コード例 #1
0
def sick(request,user_id):
    users = User.objects.all()
    selected = User.objects.get(pk=user_id)
    user_days = Day.objects.filter_user(user_id)

    year_form = YearChangeForm({'year':request.session.get('year',2013)})
    year = int(request.session.get('year',2013))

    cal = MikranCalendar(user_days,year)

    if request.method == 'POST': # If the form has been submitted...
        form = SickForm(user=request.user, data=dict(request.POST.items() + {'user_id':selected.id}.items())) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            start_date = datetime.date(int(request.POST['first_day_year']),
                                       int(request.POST['first_day_month']),
                                       int(request.POST['first_day_day']))
            
            end_date = datetime.date(int(request.POST['last_day_year']),
                                     int(request.POST['last_day_month']),
                                     int(request.POST['last_day_day']))

            start_month = int(request.POST['first_day_month'])
            end_month = int(request.POST['last_day_month'])

            status_obj = Status.objects.get(status=form.translateChoice(request.POST['status']));

            days = []
            current = Calendar()
            for month in range(start_month,end_month+1):
                for day in current.itermonthdates(int(request.POST['first_day_year']),month):
                    if day >= start_date and day <= end_date:
                        if day.isoweekday() < 6:
                            if not day in days:
                                if not day.strftime("%02d-%02m-%04Y") in cal.get_free_days(year):
                                    days.append(day)

            #build list of objects for bulk create
            Day.objects.bulk_create([Day(user_id=selected.id,status_id=status_obj.id,leave_date=day) for day in days])
            #send bulk sick days create signal
            days_planned.send(sender=User, user=selected, status=status_obj, start=start_date, end=end_date, operation="SICK".encode('utf-8'))

            #display OK message for the user
            messages.add_message(request,messages.INFO, 'Zgłosiłeś zwolnienie lekarskie od %s do %s' %(start_date,end_date))

            return HttpResponseRedirect(reverse('leave.views.show_user',args=(selected.id,)))
    else:
        form = SickForm()
        
    return render_to_response('sick_days.html',{'users': users,
                                                'selected':selected,
                                                'user_days':user_days,
                                                'cal':mark_safe(cal.formatyear(year,4)),
                                                'year_form':year_form,
                                                'days_present': user_days.filter_present().count(),
                                                'days_sick':user_days.filter_sick().count(),
                                                'days_planned':user_days.filter_planned().count(),
                                                'days_accepted':user_days.filter_accepted().count(),
                                                'form':form},
                              context_instance=RequestContext(request))
コード例 #2
0
def single_present(request,user_id,year,month,day):
    users = User.objects.all()
    selected = User.objects.get(pk=user_id)
    user_days = Day.objects.filter_user(user_id)

    url_day = datetime.date(int(year),int(month),int(day))
    present_days = Day.objects.select_related().filter(leave_date = url_day)

    year_form = YearChangeForm({'year':request.session.get('year',2013)})
    year = int(request.session.get('year',2013))

    #check if logged useed already used that day, if no form will appear, otherwise warning will be shown
    user_day = user_days.filter(leave_date = url_day)
    if user_day:
        user_day = user_day[0]

    form = SinglePresentForm(instance=Day(user_id=selected.id,status_id=Status.objects.get(status="Obecny").id,leave_date=url_day))

    cal = MikranCalendar(user_days,year,selected.id)

    if request.method == 'POST': # If the form has been submitted...
        form = SinglePresentForm(request.POST, instance=Day(user_id=selected.id,status_id=Status.objects.get(status="Obecny").id,leave_date=url_day))
        if form.is_valid(): # All validation rules pass
            #display OK message for the user
            form.save()
            messages.add_message(request,messages.INFO, 'Ten dzień (%s) jest już zarezerwowany' %(url_day))
            return HttpResponseRedirect(reverse('leave.views.show_user',args=(selected.id,)))
        

    return render_to_response('present.html',{'users': users,
                                              'selected':selected,
                                              'user_days':user_days,
                                              'user_day':user_day,
                                              'days_present': user_days.filter_present().count(),
                                              'days_sick':user_days.filter_sick().count(),
                                              'days_planned':user_days.filter_planned().count(),
                                              'days_accepted':user_days.filter_accepted().count(),
                                              'selected':selected,
                                              'cal':mark_safe(cal.formatyear(year,4)),
                                              'year_form':year_form,
                                              'form':form, 
                                              'year':year, 
                                              'month':month, 
                                              'day':day, 
                                              'statuses':cal.group_days_by_statuses(present_days)
                                              },
                              context_instance=RequestContext(request))
コード例 #3
0
def show_user(request,user_id):
    selected = User.objects.get(pk=user_id)
    user_days = Day.objects.filter_user(user_id)
    year_form = YearChangeForm({'year':request.session.get('year',2013)})
    year = int(request.session.get('year',2013))
    cal = MikranCalendar(user_days,year,selected.id)

    return render_to_response('show_user.html',{'days_present': user_days.filter_present().count(),
                                                'days_sick':user_days.filter_sick().count(),
                                                'days_planned':user_days.filter_planned().count(),
                                                'days_accepted':user_days.filter_accepted().count(),
                                                'selected':selected,
                                                'user_days':user_days,
                                                'cal':mark_safe(cal.formatyear(year,4)),
                                                'year_form':year_form,
                                                },
                              context_instance=RequestContext(request))
コード例 #4
0
def show_present(request,year,month,day):
    users = User.objects.all()
    user_days = Day.objects.select_related()

    url_day = datetime.date(int(year),int(month),int(day))
    present_days = Day.objects.select_related().filter(leave_date = url_day)

    year_form = YearChangeForm({'year':request.session.get('year',2013)})
    year = int(request.session.get('year',2013))
    cal = MikranCalendar(user_days,year)

    return render_to_response('show_present.html',{'users': users,
                                                   'cal':mark_safe(cal.formatyear(year,4)),
                                                   'year_form':year_form,
                                                   'year':year, 
                                                   'month':month, 
                                                   'day':day, 
                                                   'statuses':cal.group_days_by_statuses(present_days)
                                                   },
                              context_instance=RequestContext(request))
コード例 #5
0
def index(request):
    users = User.objects.all()
    user_days = Day.objects.select_related()
    year_form = YearChangeForm({'year':request.session.get('year',2013)})
    year = int(request.session.get('year',2013))
    cal = MikranCalendar(user_days,year)

    if request.method == 'POST': # If the form has been submitted...
        form = YearChangeForm(request.POST) # A form bound to the POST data
        if form.is_valid():
            request.session['year'] = request.POST['year']
            messages.add_message(request,messages.INFO, 'Rok został zmieniony')
            return HttpResponseRedirect(reverse('leave.views.index'))
        else:
            messages.add_message(request,messages.ERROR, 'Nie udało się zmienić roku. Co za bajzel.')

    return render_to_response('index.html',
                              {'users': users,
                               'user_days':user_days,
                               'year_form':year_form,
                               'cal':mark_safe(cal.formatyear(year,4))
                               },
                              context_instance=RequestContext(request))