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 post(self):
        form = LateApplicationForm(self.request.POST, user=self.request.user)
        if form.validate():
            date = form.popup_date.data
            explanation = form.popup_explanation.data
            late = Late(
                user_id=self.request.user.id,
                date=date,
                explanation=explanation,
                justified=True,
            )
            self.session.add(late)
            topic = self._(u'${email} - Late ${date}',
                           email=self.request.user.email,
                           date=date.strftime('%d.%m.%Y'))
            deferred = EmailSender.send(
                config['COMPANY_MAILING_LIST'],
                topic,
                form.popup_explanation.data,
                sender_name=self.request.user.name,
                replay_to=self.request.user.email,
            )
            datehour9 = datetime.datetime.combine(date, hour9)

            calendar = cal.Calendar(self.request.user)
            event = cal.Event(
                datehour9,
                datehour9 + cal.onehour,
                self._(u'Late'),
                explanation,
            )
            event_id = calendar.addEvent(event)

            if deferred:
                LOG(u"Late added")
                if event_id:
                    return Response(
                        self._(u'Request added. Calendar entry added'))
                else:
                    return Response(
                        self.
                        _(u'Request added. Calendar entry has <b class="red">NOT</b> beed added'
                          ))

            else:
                return Response(
                    self.
                    _(u'There was problem with sending email - request has not been added, please conntact administrator'
                      ))

        return dict(form=form)
Exemplo n.º 5
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
            late = Late(
                user_id=self.request.user.id,
                date=date,
                explanation=explanation,
                justified=True,
            )
            self.session.add(late)
            topic = self._(u'${email} - Late ${date}',
                email=self.request.user.email,
                date=date.strftime('%d.%m.%Y')
            )
            deferred = EmailSender.send(
                config['COMPANY_MAILING_LIST'],
                topic,
                form.popup_explanation.data,
                sender_name=self.request.user.name,
                replay_to=self.request.user.email,
            )
            datehour9 = datetime.datetime.combine(date, hour9)

            calendar = cal.Calendar(self.request.user)
            event = cal.Event(
                datehour9,
                datehour9+cal.onehour,
                self._(u'Late'),
                explanation,
            )
            event_id = calendar.addEvent(event)

            if deferred:
                LOG(u"Late added")
                if event_id:
                    return Response(self._(u'Request added. Calendar entry added'))
                else:
                    return Response(self._(u'Request added. Calendar entry has <b class="red">NOT</b> beed added'))

            else:
                return Response(self._(u'There was problem with sending email - request has not been added, please conntact administrator'))

        return dict(form=form)
Exemplo n.º 6
0
 def get(self):
     form = LateApplicationForm(user=self.request.user)
     return dict(form=form)