Exemplo n.º 1
0
    def post(self):
        lateness = self.request.json.get('lateness')
        form = LateApplicationForm(MultiDict(**lateness), user=self.request.user)
        if form.validate():
            date = form.popup_date.data
            explanation = form.popup_explanation.data
            in_future = date > datetime.date.today()
            late = Late(
                user_id=self.request.user.id,
                date=date,
                explanation=explanation,
                justified=in_future or None,
                late_start=form.late_start.data,
                late_end=form.late_end.data,
                work_from_home=form.work_from_home.data,
            )

            DBSession.add(late)
            memcache.delete(MEMCACHED_NOTIFY_KEY % date)

            if in_future and is_production:
                event_id = self._add_event(date, explanation)

            return dict(
                entry=True
            )

        self.request.response.status = 400
        return form.errors
Exemplo n.º 2
0
    def post(self):
        form = LateApplicationForm(self.request.POST, user=self.request.user)
        if form.validate():
            date = form.popup_date.data
            explanation = form.popup_explanation.data
            in_future = date > datetime.date.today()
            late = Late(
                user_id=self.request.user.id,
                date=date,
                explanation=explanation,
                justified=in_future or None, #justifed only when date is in future
                late_start=form.late_start.data,
                late_end=form.late_end.data,
                work_from_home=form.work_from_home.data
            )

            self.session.add(late)
            memcache.delete(MEMCACHED_NOTIFY_KEY % date)

            debug = self.request.registry.settings['DEBUG'] == 'True'
            if in_future and not debug:
                event_id = self._add_event(date, explanation)

            return Response(self._(u'Entry added'))

        return dict(form=form)
Exemplo n.º 3
0
    def post(self):
        lateness = self.request.json.get('lateness')
        form = LateApplicationForm(MultiDict(**lateness),
                                   user=self.request.user)
        if form.validate():
            date = form.popup_date.data
            explanation = form.popup_explanation.data
            in_future = date > datetime.date.today()
            late = Late(
                user_id=self.request.user.id,
                date=date,
                explanation=explanation,
                justified=in_future or None,
                late_start=form.late_start.data,
                late_end=form.late_end.data,
                work_from_home=form.work_from_home.data,
            )

            DBSession.add(late)
            memcache.delete(MEMCACHED_NOTIFY_KEY % date)

            if in_future and is_production:
                event_id = self._add_event(date, explanation)

            return dict(entry=True)

        self.request.response.status = 400
        return form.errors
Exemplo n.º 4
0
 def invalidate_for(tracker_id):
     memcache.delete(SELECTOR_CACHE_KEY % tracker_id)
     DEBUG(u'Invalidated selector mapping cache for tracker %s' % (tracker_id, ))
Exemplo n.º 5
0
 def invalidate_office_ip(self):
     """ invalidates the cached value of office IP """
     memcache.delete(OFFICE_IP_MEMCACHE_KEY)
     DEBUG(u"Office IP invalidated")
Exemplo n.º 6
0
    def post(self):
        absence = self.request.json.get('absence')
        form = AbsentApplicationForm(MultiDict(**absence),
                                     request=self.request)
        if form.validate():
            response = {
                u'request': False,
                u'hours': False,
                u'calendar_entry': False,
            }

            memcache.clear()

            date_start = form.popup_date_start.data
            date_end = form.popup_date_end.data
            days = 0
            if date_start and date_end:
                days = h.get_working_days(date_start, date_end)
            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,
            )

            DBSession.add(absence)
            memcache.delete(MEMCACHED_NOTIFY_KEY % date_start)

            if absence.type != 'inne':
                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,
                        )
                        DBSession.add(timeentry)
                    date += oneday

                self._send_email(
                    absence.type,
                    date_start.strftime('%Y-%m-%d'),
                    date_end.strftime('%Y-%m-%d'),
                    days,
                    remarks,
                )

                response[u'request'] = True
                response[u'hours'] = True

            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)

            response[u'calendar_entry'] = bool(event_id)

            return response

        self.request.response.status = 400
        return form.errors
Exemplo n.º 7
0
 def invalidate_office_ip(self):
     """ invalidates the cached value of office IP """
     memcache.delete(OFFICE_IP_MEMCACHE_KEY)
     DEBUG(u"Office IP invalidated")
Exemplo n.º 8
0
    def post(self):
        absence = self.request.json.get('absence')
        form = AbsentApplicationForm(MultiDict(**absence), request=self.request)
        if form.validate():
            response = {
                u'request': False,
                u'hours': False,
                u'calendar_entry': False,
            }

            memcache.clear()

            date_start = form.popup_date_start.data
            date_end = form.popup_date_end.data
            days = 0
            if date_start and date_end:
                days = h.get_working_days(date_start, date_end)
            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,
            )

            DBSession.add(absence)
            memcache.delete(MEMCACHED_NOTIFY_KEY % date_start)

            if absence.type != 'inne':
                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,
                        )
                        DBSession.add(timeentry)
                    date += oneday

                self._send_email(
                    absence.type,
                    date_start.strftime('%Y-%m-%d'),
                    date_end.strftime('%Y-%m-%d'),
                    days,
                    remarks,
                )

                response[u'request'] = True
                response[u'hours'] = True

            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)

            response[u'calendar_entry'] = bool(event_id)

            return response

        self.request.response.status = 400
        return form.errors
Exemplo n.º 9
0
 def invalidate_for(tracker_id):
     memcache.delete(SELECTOR_CACHE_KEY % tracker_id)
     DEBUG(u'Invalidated selector mapping cache for tracker %s' %
           (tracker_id, ))
Exemplo n.º 10
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
        )