Exemplo n.º 1
0
    def post(self):
        if not self.request.is_xhr:
            return HTTPBadRequest()

        date = self.v['date']
        form = TimeEntryForm(self.request.POST)

        if form.validate():
            project_id = form.project_id.data
            time = TimeEntry(
                date = date,
                user_id = self.request.user.id,
                time = form.time.data,
                description = form.description.data,
                ticket_id = form.ticket_id.data,
                project_id = project_id if project_id else None
            )
            DBSession.add(time)
            LOG(u'Ajax - Time entry added')

            entries = self._get_time_entries(date)
            total_sum = sum(entry.time for (tracker, entry) in entries if not entry.deleted)
            template = render(
                '/times/_list.html',
                dict(entries=entries, total_sum=total_sum),
                request=self.request
            )

            return dict(status='success', html=template)

        errors = u'<br />'.join((u"%s - %s" % (field, u', '.join(errors)) for field, errors in form.errors.iteritems()))
        return dict(status='error', errors=errors)
Exemplo n.º 2
0
    def post(self):
        if not self.request.is_xhr:
            return HTTPBadRequest()

        date = self.v['date']
        form = TimeEntryForm(self.request.POST)

        if form.validate():
            project_id = form.project_id.data
            time = TimeEntry(date=date,
                             user_id=self.request.user.id,
                             time=form.time.data,
                             description=form.description.data,
                             ticket_id=form.ticket_id.data,
                             project_id=project_id if project_id else None)
            DBSession.add(time)
            LOG(u'Ajax - Time entry added')

            entries = self._get_time_entries(date)
            total_sum = sum(entry.time for (tracker, entry) in entries
                            if not entry.deleted)
            template = render('/times/_list.html',
                              dict(entries=entries, total_sum=total_sum),
                              request=self.request)

            return dict(status='success', html=template)

        errors = u'<br />'.join((u"%s - %s" % (field, u', '.join(errors))
                                 for field, errors in form.errors.iteritems()))
        return dict(status='error', errors=errors)
Exemplo n.º 3
0
    def post(self):
        timeentry = self.v['timeentry']

        next_ = self.request.GET.get('next')
        if not next_:
            next_ = self.request.url_for(
                '/times/list',
                date=timeentry.date.strftime('%d.%m.%Y'),
            )

        form = TimeEntryForm(self.request.POST, obj=timeentry)
        date = timeentry.date
        today = datetime.date.today()

        if form.validate():
            if timeentry.project_id != int(
                    form.project_id.data) and today > date:
                timeentry.deleted = True
                timeentry.modified_ts = datetime.datetime.now()
                time = TimeEntry(date=date,
                                 user_id=timeentry.user_id,
                                 time=form.time.data,
                                 description=form.description.data,
                                 ticket_id=form.ticket_id.data,
                                 project_id=form.project_id.data
                                 if form.project_id.data else None,
                                 timer_ts=datetime.datetime.now()
                                 if form.timer.data else None)
                DBSession.add(time)
            else:
                ticket_id = form.ticket_id.data

                if timeentry.time != form.time.data or\
                   timeentry.project_id != form.project_id.data:
                    timeentry.modified_ts = datetime.datetime.now()

                timeentry.time = form.time.data
                timeentry.description = form.description.data
                timeentry.ticket_id = ticket_id
                timeentry.project_id = form.project_id.data if form.project_id.data else None

            self.flash(self._(u'Time entry saved'))
            LOG(u'Time entry saved')
            return HTTPFound(next_)

        return dict(
            timeentry_id=timeentry.id,
            form=form,
            date=date,
            next=next_,
        )
Exemplo n.º 4
0
    def post(self):
        timeentry = self.v['timeentry']

        next_ = self.request.GET.get('next')
        if not next_:
            next_ = self.request.url_for(
                '/times/list',
                date=timeentry.date.strftime('%d.%m.%Y'),
            )

        form = TimeEntryForm(self.request.POST, obj=timeentry)
        date = timeentry.date
        today = datetime.date.today()

        if form.validate():
            if timeentry.project_id != int(form.project_id.data) and today > date:
                timeentry.deleted = True
                timeentry.modified_ts = datetime.datetime.now()
                time = TimeEntry(
                    date=date,
                    user_id = timeentry.user_id,
                    time = form.time.data,
                    description = form.description.data,
                    ticket_id = form.ticket_id.data,
                    project_id = form.project_id.data if form.project_id.data else None,
                    timer_ts = datetime.datetime.now() if form.timer.data else None
                )
                DBSession.add(time)
            else:
                ticket_id = form.ticket_id.data

                if timeentry.time != form.time.data or\
                   timeentry.project_id != form.project_id.data:
                    timeentry.modified_ts = datetime.datetime.now()

                timeentry.time = form.time.data
                timeentry.description = form.description.data
                timeentry.ticket_id = ticket_id
                timeentry.project_id = form.project_id.data if form.project_id.data else None

            self.flash(self._(u'Time entry saved'))
            LOG(u'Time entry saved')
            return HTTPFound(next_)

        return dict(
            timeentry_id=timeentry.id,
            form=form,
            date=date,
            next=next_,
        )
Exemplo n.º 5
0
    def get(self):
        date_str = self.request.GET.get('date')
        date = datetime.datetime.strptime(date_str, '%d.%m.%Y')
        user_id = self.request.GET.get('user_id')
        if self.request.user.id == int(user_id):
            return HTTPFound(self.request.url_for('/times/list',
                                                  date=date_str))

        user = User.query.get(user_id)
        if user is None:
            return HTTPNotFound()

        entries = self._get_time_entries(date, user_id)
        form = TimeEntryForm()

        total_sum = sum(entry.time for (tracker, entry) in entries
                        if not entry.deleted)

        return dict(
            date=date,
            form=form,
            entries=entries,
            user=user,
            prev_date=previous_day(date),
            next_date=next_day(date),
            total_sum=total_sum,
            can_modify=self.request.has_perm('can_edit_users_timeentry'),
        )
Exemplo n.º 6
0
    def get(self):
        date_str = self.request.GET.get('date')
        date = datetime.datetime.strptime(date_str, '%d.%m.%Y')

        entries = self._get_time_entries(date)

        total_sum = sum(entry.time for (tracker, entry) in entries
                        if not entry.deleted)
        form = TimeEntryForm()

        needs_justification = False
        for tracker, timeentry in entries:
            if timeentry.modified_ts.date() > timeentry.date:
                needs_justification = True

        return dict(
            date=date,
            entries=entries,
            form=form,
            user=self.request.user,
            prev_date=previous_day(date),
            next_date=next_day(date),
            total_sum=total_sum,
            needs_justification=needs_justification,
            justification_status=excuses.wrongtime_status(
                date, self.request.user.id),
            can_modify=user_can_modify_timeentry(self.request.user, date),
        )
Exemplo n.º 7
0
 def get(self):
     date = datetime.datetime.strptime(self.request.GET.get('date'),
                                       '%d.%m.%Y')
     bugs = Bugs(self.request).get_user()
     form = TimeEntryForm()
     return dict(
         date=date,
         form=form,
         bugs=(bug for bug in bugs if bug.project),
         user=self.request.user,
     )
Exemplo n.º 8
0
    def get(self):
        timeentry = self.v['timeentry']

        next_ = self.request.GET.get('next')
        if not next_:
            next_ = self.request.url_for(
                '/times/list',
                date=timeentry.date.strftime('%d.%m.%Y'),
            )
        form = TimeEntryForm(obj=timeentry)
        date = timeentry.date

        return dict(
            timeentry_id=timeentry.id,
            form=form,
            date=date,
            next=next_,
        )