예제 #1
0
    def dispatch(self):
        form = AbsenceCreateForm(self.request.POST, request=self.request)
        days, mandated, used, left = 0, 0, 0, 0
        if form.popup_date_start.data:
            mandated, used, left = user_leave(self.request,
                                              form.popup_date_start.data.year)
            if form.popup_date_end.data:
                days = h.get_working_days(form.popup_date_start.data,
                                          form.popup_date_end.data)
                left -= days
        if self.request.method == 'POST' and form.validate():
            date_start = form.popup_date_start.data
            date_end = form.popup_date_end.data
            type = form.popup_type.data
            remarks = form.popup_remarks.data
            user_id = form.popup_user_id.data
            absence = Absence(
                user_id=user_id,
                date_start=date_start,
                date_end=date_end,
                days=days,
                type=type,
                remarks=remarks,
            )
            DBSession.add(absence)
            return Response(self._('Done') + RELOAD_PAGE)

        return dict(form=form,
                    days=days,
                    mandated=mandated,
                    used=used,
                    left=left)
예제 #2
0
 def validate_popup_type(self, field):
     if self.popup_date_start.data and self.popup_date_end.data and field.data not in (u'inne', u'okolicznosciowe', u'l4'):
         mandated, used, left = user_leave(self.request, self.popup_date_start.data.year)
         days = h.get_working_days(self.popup_date_start.data, self.popup_date_end.data)
         left -= days
         if left < 0:
             raise ValidationError(_(u'There is no leave to use, please choose Absence or conntact with Assistant'))
예제 #3
0
    def get(self):
        date_start = self.request.GET.get('date_start')
        date_end = self.request.GET.get('date_end')

        if date_start:
            date_start = datetime.datetime.strptime(date_start,
                                                    '%d/%m/%Y').date()
            mandated, used, left = user_leave(self.request, date_start.year)
            days = 0

            if date_end:
                type = self.request.GET.get('type')
                date_end = datetime.datetime.strptime(date_end,
                                                      '%d/%m/%Y').date()

                days = h.get_working_days(date_start, date_end)
                if days is None:
                    days = 0
                if type in ('planowany', 'zadanie'):
                    left -= days

            return dict(days=days, left=left, mandated=mandated)

        self.request.response.status = 400
        return dict(date_start='This field is required.')
예제 #4
0
파일: form.py 프로젝트: avalanchy/intranet
    def dispatch(self):
        form = AbsenceCreateForm(self.request.POST, request=self.request)
        days, mandated, used, left = 0, 0, 0, 0
        if form.popup_date_start.data:
            mandated, used, left = user_leave(self.request, form.popup_date_start.data.year)
            if form.popup_date_end.data:
                days = h.get_working_days(form.popup_date_start.data, form.popup_date_end.data)
                left -= days
        if self.request.method == 'POST' and form.validate():
            date_start = form.popup_date_start.data
            date_end = form.popup_date_end.data
            type = form.popup_type.data
            remarks = form.popup_remarks.data
            user_id = form.popup_user_id.data
            absence = Absence(
                user_id=user_id,
                date_start=date_start,
                date_end=date_end,
                days=days,
                type=type,
                remarks=remarks,
            )
            self.session.add(absence)
            return Response(self._('Done') + RELOAD_PAGE)

        return dict(
            form=form,
            days=days,
            mandated=mandated,
            used=used,
            left=left
        )
예제 #5
0
    def get(self):
        date_start = self.request.GET.get('date_start')
        date_end = self.request.GET.get('date_end')

        if date_start:
            date_start = datetime.datetime.strptime(date_start, '%d/%m/%Y').date()
            mandated, used, left = user_leave(self.request, date_start.year)
            days = 0

            if date_end:
                type = self.request.GET.get('type')
                date_end = datetime.datetime.strptime(date_end, '%d/%m/%Y').date()

                days = h.get_working_days(date_start, date_end)
                if days is None:
                    days = 0
                if type in ('planowany', 'zadanie'):
                    left -= days

            return dict(
                days=days,
                left=left,
                mandated=mandated
            )

        self.request.response.status = 400
        return dict(
            date_start='This field is required.'
        )
예제 #6
0
    def get(self):
        date_start = self.request.GET.get('date_start')
        date_end = self.request.GET.get('date_end')
        type = self.request.GET.get('type')
        days = 0
        if date_start:
            date_start = datetime.datetime.strptime(date_start, '%d/%m/%Y').date()
            mandated, used, left = user_leave(self.request, date_start.year)
            if date_end:
                date_end = datetime.datetime.strptime(date_end, '%d/%m/%Y').date()
                days = h.get_working_days(date_start, date_end)
                if days is None:
                    days = 0
                if type in ('planowany', 'zadanie'):
                    left -= days

            return dict(
                status='ok',
                days=days,
                left=left,
                mandated=mandated,
            )
        return dict(
            status='nok',
        )
예제 #7
0
 def validate_popup_type(self, field):
     if field.data == u'l4' and not self.request.user.employment_contract:
         raise ValidationError(_(u"Only user on employment contract can submit L4 absence."))
     if self.popup_date_start.data and self.popup_date_end.data and field.data not in (u'inne', u'okolicznosciowe', u'l4'):
         mandated, used, left = user_leave(self.request, self.popup_date_start.data.year)
         days = h.get_working_days(self.popup_date_start.data, self.popup_date_end.data)
         left -= days
         if left < 0:
             raise ValidationError(_(u'There is no leave to use, please choose Absence or conntact with Assistant'))
예제 #8
0
 def validate_popup_type(self, field):
     if self.popup_date_start.data and self.popup_date_end.data and field.data not in (
             u'inne', u'okolicznosciowe', u'l4'):
         mandated, used, left = user_leave(self.request,
                                           self.popup_date_start.data.year)
         days = h.get_working_days(self.popup_date_start.data,
                                   self.popup_date_end.data)
         left -= days
         if left < 0:
             raise ValidationError(
                 _(u'There is no leave to use, please choose Absence or conntact with Assistant'
                   ))
예제 #9
0
    def dispatch(self):
        form = AbsentApplicationForm(self.request.POST, request=self.request)
        days, mandated, used, left = 0, 0, 0, 0
        if form.popup_date_start.data:
            mandated, used, left = user_leave(self.request, form.popup_date_start.data.year)
            if form.popup_date_end.data:
                days = h.get_working_days(form.popup_date_start.data, form.popup_date_end.data)
                left -= days
        if self.request.method == 'POST' and form.validate():
            memcache.clear()
            response = u''
            date_start = form.popup_date_start.data
            date_end = form.popup_date_end.data
            type = form.popup_type.data
            remarks = form.popup_remarks.data
            absence = Absence(
                user_id=self.request.user.id,
                date_start=date_start,
                date_end=date_end,
                days=days,
                type=type,
                remarks=remarks,
            )
            memcache.delete(MEMCACHED_NOTIFY_KEY % date_start)
            self.session.add(absence)

            if absence.type != 'inne':
                # let's add timeentries for this leave
                holidays = Holiday.all()
                date = date_start
                oneday = datetime.timedelta(days=1)
                description = self._(u'Auto Leave: ${type} - ${remarks}',
                    type=dict(ABSENCE_TYPES)[type],
                    remarks=remarks
                )
                project_id = L4_PROJECT_ID if type == u'l4' else LEAVE_PROJECT_ID

                while date <= date_end:
                    if not Holiday.is_holiday(date, holidays=holidays):
                        timeentry = TimeEntry(
                            user_id=self.request.user.id,
                            date=date,
                            time=8,
                            description=description,
                            project_id=project_id,
                        )
                        self.session.add(timeentry)
                    date += oneday

                ## let's send email
                deferred = self._send_mail(
                    absence.type,
                    date_start.strftime('%Y-%m-%d'),
                    date_end.strftime('%Y-%m-%d'),
                    days,
                    remarks,
                )
                response += self._(u'Request added<br>Hours added<br>')

            ## and add event to calendar:
            calendar = cal.Calendar(self.request.user)
            event = cal.Event(
                date_start,
                date_end+cal.oneday,
                u'NIEOB-[%s]' % self.request.user.name,
                remarks,
            )
            event_id = calendar.addEvent(event)

            if event_id:
                response += self._(u'Calendar entry has been added')
            else:
                response += u'Calendar entry has <b class="red">NOT</b> beed added'

            return Response(response)

        return dict(
            form=form,
            days=days,
            mandated=mandated,
            used=used,
            left=left
        )