[PYTHON] Change what is displayed by Dango authorized person

I asked a friend to use the shift table once. There were some requests.

① Shift table: Only the administrator can edit the time. ② Shift table I want you to copy the shift creation by day of the week ③ Desired shift: By the 5th of every month, we ask for a shift request and create and distribute it by the 10th, so input restrictions are required to enter by 5. ④ Bulletin board: Notify each facility ⑤ Task It is best if you can take over what you have to do

Until now, I have created moving objects as goals for the time being. From here, I will learn about input restrictions and authority control so that you can really use it.

First, clicking on the working hours in the shift table will take you to the screen for registering shifts, but this will be changed so that only superusers can do it and other users cannot.

In html,

{% if perms.schedule.add_schedule %}

Conditional statement was added.

perms. refers to the authority setting itself, and determines whether the schedule table in it has additional authority.

It was just one line, but it took almost two hours. There is likely to be something to learn about permission settings.

html looks like this

python:schedule.month.html



{% extends 'accounts/base.html' %}
{% load static %}
{% block customcss %}
<link rel="stylesheet" href="{% static 'schedule/month.css' %}">
{% endblock customcss %}

{% block header %}
    <div class="header">
        <div class="cole-md-1">
                <a href="{% url 'schedule:KibouList' %}" class="btn-secondary btn active">List of desired shifts</a></p>
                {% ifnotequal month 1 %}
                    <a href="{% url 'schedule:monthschedule' year month|add:'-1' %}" class="btn-info btn active">last month</a>
                {% else %}
                    <a href="{% url 'schedule:monthschedule' year|add:'-1' 12 %}" class="btn-info btn active">last month</a>
                {% endifnotequal %}
       
                {% ifnotequal month 12 %}
                    <a href="{% url 'schedule:monthschedule' year month|add:'1' %}" class="btn-info btn active">Next month</a>
                {% else %}
                     <a href="{% url 'schedule:monthschedule' year|add:'1' 1 %}" class="btn-info btn active">Next month</a>
                {% endifnotequal %}
                {% if perms.schedule.add_schedule %}<!--Authority-->
                    <a href="{% url 'schedule:schedulecreate' year month %}" class="btn-info btn active">Shift creation</a>
                {% endif %}
        </div>
        <div class="cole-md-2">
            {% for shift in shift_object %}
                {% if shift.name != "Closed" and shift.name != "Yes" %}
                    {{ shift.name }} : {{ shift.start_time | date:"G"}}~{{ shift.end_time | date:"G"}} 
                {% endif %}
            {% endfor %}    
        </div>
        <p>
            <a href="{% url 'schedule:monthschedule' year month %}" button type="button" class="btn btn-outline-dark">all</a>
            {% for shisetsu in shisetsu_object %}
                <a href="{% url 'schedule:monthschedulefilter' year month shisetsu.pk %}" button type="button" class="btn btn-outline-dark" span style="background-color:{{ shisetsu.color }}">{{ shisetsu.name }}</span></a>
            {% endfor %}
        </p>
    </div> 

{% endblock header %}

{% block content %}
<table class="table">
    <thead>
        <tr>    <!--date-->
            <th class ="fixed00" rowspan="2">{{ kikan }}</th>
            {% for item in calender_object %}
            <th class ="fixed01">{{ item.date | date:"d" }}</th>
            {% endfor %}
        <tr>   <!--Day of the week-->
            {% for item in youbi_object %}
                <th class ="fixed02">{{ item }}</th>
            {% endfor %}
        </tr>
    </thead>
    <tbody>
    {% for profile in profile_list %}
        {% for staff in user_list %}
            {% if profile.user_id == staff.id %}
                <tr align="center">
                <th class ="fixed03" >{{ staff.last_name }} {{ staff.first_name }}</th>  <!--staff_id element used in js-->
                {% for item in object_list %} 
                    {% if item.user|stringformat:"s" == staff.username|stringformat:"s" %}<!--If the username is the same-->
                        <td class="meisai"> 
                        {% if item.shift_name_1 != None %}
                            {% if item.shift_name_1|stringformat:"s" == "Yes" or item.shift_name_1|stringformat:"s" == "Closed" %}
                                {{ item.shift_name_1 }}
                            {% else %}
                                {% for shisetsu in shisetsu_object %}
                                    {% if item.shisetsu_name_1|stringformat:"s" == shisetsu.name|stringformat:"s" %}                          
                                        <span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_1 }}</span>
                                    {% endif %}
                                {% endfor %} 
                            {% endif %}    
                        {% endif %}
                {% if item.shift_name_2 != None %}
                    {% if item.shift_name_2|stringformat:"s" == "Yes" or item.shift_name_2|stringformat:"s" == "Closed" %}
                        {{ item.shift_name_2 }}
                    {% else %}
                        {% for shisetsu in shisetsu_object %}
                            {% if item.shisetsu_name_2|stringformat:"s" == shisetsu.name|stringformat:"s" %}                          
                                    <span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_2 }}</span>
                            {% endif %}
                        {% endfor %} 
                    {% endif %}    
                {% endif %}
                {% if item.shift_name_3 != None %}
                    {% if item.shift_name_3|stringformat:"s" == "Yes" or item.shift_name_3|stringformat:"s" == "Closed" %}
                        {{ item.shift_name_3 }}
                    {% else %}
                        {% for shisetsu in shisetsu_object %}
                            {% if item.shisetsu_name_3|stringformat:"s" == shisetsu.name|stringformat:"s" %}                          
                                <span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_3 }}</span>
                            {% endif %}
                        {% endfor %} 
                    {% endif %}    
                {% endif %}
                {% if item.shift_name_4 != None %}
                    {% if item.shift_name_4|stringformat:"s" == "Yes" or item.shift_name_4|stringformat:"s" == "Closed" %}
                        {{ item.shift_name_4 }}
                    {% else %}
                        {% for shisetsu in shisetsu_object %}
                            {% if item.shisetsu_name_4|stringformat:"s" == shisetsu.name|stringformat:"s" %}                          
                                <span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_4 }}</span>
                            {% endif %}
                        {% endfor %} 
                    {% endif %}    
                {% endif %}                   
            {% endif %}            
        {% endfor %}
        </td>

        <tr align="center">
            {% for month in month_total %} 
                {% if month.user ==  staff.id %}<!--If the username is the same-->
                    <td class="fixed04"><b>{{ month.month_total_worktime }}</b></td>
                {% endif %}
            {% endfor %}
            {% for item in object_list %} 
                {% if item.user|stringformat:"s" == staff.username|stringformat:"s" %}<!--If the username is the same-->
                    {% if perms.schedule.add_schedule %}<!--Authority-->
                        <td  class="meisai" id="s{{ staff.id }}d{{ item.date }}">
                            <a href="{% url 'schedule:update' item.pk %}">{{ item.day_total_worktime }} </a>
                        </td>
                    {% else %}
                        <td  class="meisai" id="s{{ staff.id }}d{{ item.date }}">
                            {{ item.day_total_worktime }}
                        </td>
                    {% endif %}
                {% endif %}            
            {% endfor %}
        </tr>
        {% endif %}
        {% endfor %}
        {% endfor %}
        </tbody>
    </table>
</div>
</div>
{% endblock content %}

image.png

The shift creation button is no longer displayed without permission. And the time is also non-clickable.

① Shift table: Only the administrator can edit the time. This solved the problem.

② Shift table I want you to copy the shift creation by day of the week ⇒ Think about what to do with copying on the day of the week. I think it's easier to have it in your profile and copy from there.

③ Desired shift: By the 5th of every month, we ask for a shift request and create and distribute it by the 10th, so input restrictions are required to enter by 5. ⇒I've been doing this for about 2 hours now, but I haven't been able to solve it. The current code is here

schedule.views



class KibouUpdate(UpdateView):
    template_name = 'schedule/kiboushift/update.html'
    model = KibouShift
    fields = ('user', 'date', 'shift_name_1', 'shisetsu_name_1', 'shift_name_2', 'shisetsu_name_2', 'shift_name_3', 'shisetsu_name_3', 'shift_name_4', 'shisetsu_name_4')
    def date(self):
        date = self.cleaned_date.get('date')
        now = datetime.now()
        print(now.date)
        #Enter only after 20th when 5th
        if now.day > 5:
            startdate = datetime.date(now.year,now.month,20)
            if date < startdate:
                raise ValidationError(
                "It is a date that cannot be entered",
                params={'value': value},
                )
        else:
            startdate = datetime.date(now.year,now.month,20)
            startdate = enddate + relativedelta(months=1)
            if date < startdate:
                raise ValidationError(
                "It is a date that cannot be entered",
                params={'value': value},
                )
        return date

    success_url = reverse_lazy('schedule:KibouList')

With this, if it exceeds 5 days, it can only be updated after the 20th of the following month. I can do it at all (laugh)

This may not be resolved immediately

④ Bulletin board: Notify each facility ⇒ This seems to be possible to implement, so I will do it (⌒∇⌒)

⑤ Task It is best if you can take over what you have to do ⇒I will study the usability of redmine or todoist and consider various ways to create regular tasks. I think this will be one app, so I plan to postpone it.

Recommended Posts

Change what is displayed by Dango authorized person
[Python] What is inherited by multiple inheritance?
What is namespace
What is copy.copy ()
What is Django? .. ..
What is dotenv?
What is POSIX?
What is klass?
What is SALOME?
What is Linux?
What is python
What is hyperopt?
What is Linux
What is pyvenv
What is __call__
What is Linux
What is Python
[Statistics] Understand what an ROC curve is by animation.