Implemented public and unpublished features in Django shift tables Added background color control for desired shifts

When I saw the shift table function, I found out that it took a considerable amount of time since the administrator contacted everyone's requests via lines. So, I didn't want to publish the shift in the middle of creation, so I implemented the public and unpublished functions.

image.png

If the administrator is editing, the status is private and the publish button is displayed.

If you don't have administrator privileges image.png

Not displayed.

The control may be better off using the User group, but it's deciding if it's superuser.

We decide to have a flag on the model and decide whether it is ON or OFF. I thought about having a moon table, but I think I'll think about it when I rethink the deadline and so on.

First of all, I think that making people happy to use it will accelerate the acquisition of technology, so I will do my best to implement it (⌒∇⌒)

python.suchedule.modell.py


class Schedule(models.Model):
    id = models.AutoField(verbose_name='Schedule ID',primary_key=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Employee name')
    date = models.DateField(verbose_name='date')
    year = models.PositiveIntegerField(validators=[MinValueValidator(1),])
    month = models.PositiveIntegerField(validators=[MaxValueValidator(12),MinValueValidator(1),])
    shift_name_1 = models.ForeignKey(Shift, verbose_name='1 shift name', related_name='shift_name1',on_delete=models.SET_NULL,null= True)
    shisetsu_name_1 = models.ForeignKey(Shisetsu, verbose_name='1 facility', related_name='shisetsu_name1',on_delete=models.SET_NULL,blank=True, null=True)
    shift_name_2 = models.ForeignKey(Shift, verbose_name='2 shift name', related_name='shift_name2',on_delete=models.SET_NULL,blank=True, null=True)
    shisetsu_name_2 = models.ForeignKey(Shisetsu, verbose_name='2 facilities', related_name='shisetsu_name2',on_delete=models.SET_NULL,blank=True, null=True)
    shift_name_3 = models.ForeignKey(Shift, verbose_name='3 shift name', related_name='shift_name3',on_delete=models.SET_NULL,blank=True, null=True)
    shisetsu_name_3 = models.ForeignKey(Shisetsu, verbose_name='3 facilities', related_name='shisetsu_name3',on_delete=models.SET_NULL,blank=True, null=True)
    shift_name_4 = models.ForeignKey(Shift, verbose_name='4 shift name', related_name='shift_name4',on_delete=models.SET_NULL,blank=True, null=True)
    shisetsu_name_4 = models.ForeignKey(Shisetsu, verbose_name='4 facilities', related_name='shisetsu_name4',on_delete=models.SET_NULL,blank=True, null=True)
    day_total_worktime = models.IntegerField(verbose_name='Daily working hours', default=0)
    kibou_shift = models.BooleanField(verbose_name='Hope shift',default=False)
    open_flag = models.BooleanField(verbose_name='Public flag',default=False)

    class Meta:
        unique_together = ('user', 'date')

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 %}
  </div>
        <!--Button link to open modal-->
        {% if perms.schedule.add_schedule %}<!--Authority-->
            <button type="button" class="btn-info btn active" data-toggle="modal" data-target="#createModal">Shift creation</button>
        {% endif %}
        <!--Creation confirmation-->
        <div class="modal fade" id="createModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4><class="modal-title" id="myModalLabel">confirmation screen</h4></h4>
                    </div>
                    <div class="modal-body">
                        <label>When I create a shift, the data is overwritten. Do you want to execute it?</label>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">close</button>

                            <a href="{% url 'schedule:schedulecreate' year month %}" class="btn-info btn active">Shift creation</a>
                       
                    </div>
                </div>
            </div>
        </div>

            <!--Button link to open modal-->
            {% if perms.schedule.add_schedule %}<!--Authority-->
                {% if open_flag.open_flag == False %}
                    <button type="button" class="btn-info btn active" data-toggle="modal" data-target="#openModal">Release</button>
                {% elif open_flag.open_flag == True %}
                    <button type="button" class="btn-info btn active" data-toggle="modal" data-target="#closeModal">private</button>
                {% endif %}
            {% endif %}

            <!--Public confirmation-->
            <div class="modal fade" id="openModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4><class="modal-title" id="myModalLabel">confirmation screen</h4></h4>
                        </div>
                        <div class="modal-body">
                            <label>Do you want to publish the shift?</label>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">close</button>
                            {% ifnotequal month 12 %}
                                <a href="{% url 'schedule:scheduleopen' year month %}" class="btn-info btn active">Release</a>
                            {% else %}
                            
                                <a href="{% url 'schedule:scheduleopen' year|add:'1' month %}" class="btn-info btn active">Release</a>
                            {% endifnotequal %}
                            
                        </div>
                    </div>
                </div>
            </div>

            <!--Private confirmation-->
            <div class="modal fade" id="closeModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4><class="modal-title" id="myModalLabel">confirmation screen</h4></h4>
                        </div>
                        <div class="modal-body">
                            <label>Do you want to keep the shift private?</label>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">close</button>
                            {% ifnotequal month 12 %}
                                <a href="{% url 'schedule:scheduleclose' year month %}" class="btn-info btn active">private</a>
                            {% else %}
                            
                                <a href="{% url 'schedule:scheduleclose' year|add:'1' month %}" class="btn-info btn active">private</a>
                            {% endifnotequal %}
                            
                        </div>
                    </div>
                </div>
            </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 %}
                {% for UserShozoku in UserShozoku_list %}
                    {% if shisetsu.name|stringformat:"s" == UserShozoku.shisetsu_name|stringformat:"s" %}
                        <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>
                    {% endif %}
                {% endfor %}
            {% 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>
    {% if perms.schedule.add_schedule or open_flag.open_flag == True %}<!--Authority-->
        {% for profile in profile_list %}
            {% for staff in user_list %}
                {% if profile.user_id == staff.id %}
                    <tr align="center">
                    <th class ="fixed03" ><a href="{% url 'schedule:monthschedulekojin' year month staff.id %}">{{ staff.last_name }} {{ staff.first_name }}</a></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-->
                            
                            {% if item.kibou_shift == True %}
                                <td class="meisai03">
                            {% elif item.shift_name_1|stringformat:"s" == "Closed"  %}
                                <td class="meisai01"> 
                            {% elif item.shift_name_1|stringformat:"s" == "Not"  %} 
                                <td class="meisai04">
                            {% else %}
                                <td class="meisai01"> 
                            {% endif %}
                            {% if item.shift_name_1 != None %}
                                {% if item.shift_name_1|stringformat:"s" == "Yes" %}
                                    {{ item.shift_name_1 }}
                                {% elif item.shift_name_1|stringformat:"s" == "Closed" %}
                                
                                {% elif item.shift_name_1|stringformat:"s" == "Not" %}
                                    {{ item.shift_name_1 }}
                                {% else %}                   
                                    <span style="background-color:{{ item.shisetsu_name_1.color }}">{{ item.shift_name_1 }}</span>
                                {% 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 %}                  
                            <span style="background-color:{{ item.shisetsu_name_2.color }}">{{ item.shift_name_2 }}</span>
                        {% 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 %}                        
                            <span style="background-color:{{ item.shisetsu_name_3.color }}">{{ item.shift_name_3 }}</span>
                        {% 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 %}                         
                            <span style="background-color:{{ item.shisetsu_name_4.color }}">{{ item.shift_name_4 }}</span>
                        {% endif %}    
                    {% endif %}                   
                {% endif %}            
            {% endfor %}
            </td>

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



I keenly realized that it is important to communicate with the people who actually use it and use their imagination (delusional power) to consider it.

Recommended Posts

Implemented public and unpublished features in Django shift tables Added background color control for desired shifts
Added a function to register desired shifts in the Django shift table