Пример #1
0
def add_time(user_id, date, bug_id, project_id, hours, subject):
    # try finding existing entry for this bug
    session = DBSession()
    bug_id = str(bug_id)
    entry = TimeEntry.query.filter(TimeEntry.user_id==user_id) \
                           .filter(TimeEntry.date==date.date()) \
                           .filter(TimeEntry.ticket_id==bug_id) \
                           .filter(TimeEntry.project_id==project_id).first()
    if not entry:
        # create new entry
        entry = TimeEntry(
            user_id=user_id,
            date=date.date(),
            time=hours,
            description=subject,
            ticket_id=bug_id,
            project_id = project_id,
            modified_ts=date
        )
        session.add(entry)
        LOG(u'Adding new entry')
    else:
        # update existing entry
        if not entry.frozen:
            entry.time += hours
            entry.modified_ts = date # TODO: this might remove an already existing lateness
            session.add(entry)
            LOG(u'Updating existing entry')
        else:
            LOG(u'Omission of an existing entry because it is frozen')
Пример #2
0
def add_time(user_id, date, bug_id, project_id, hours, subject):
    # try finding existing entry for this bug
    session = DBSession()
    bug_id = str(bug_id)
    entry = TimeEntry.query.filter(TimeEntry.user_id==user_id) \
                           .filter(TimeEntry.date==date.date()) \
                           .filter(TimeEntry.ticket_id==bug_id) \
                           .filter(TimeEntry.project_id==project_id).first()
    if not entry:
        # create new entry
        entry = TimeEntry(user_id=user_id,
                          date=date.date(),
                          time=hours,
                          description=subject,
                          ticket_id=bug_id,
                          project_id=project_id,
                          modified_ts=date)
        session.add(entry)
        LOG(u'Adding new entry')
    else:
        # update existing entry
        if not entry.frozen:
            entry.time += hours
            entry.modified_ts = date  # TODO: this might remove an already existing lateness
            session.add(entry)
            LOG(u'Updating existing entry')
        else:
            LOG(u'Omission of an existing entry because it is frozen')
Пример #3
0
    def on_retrieve(self, lines):
        """ When single message was retrieved """
        msg = email.message_from_string('\n'.join(lines))
        sender = decode(msg['From'])
        tracker = self.match_tracker(msg)
        if tracker is None:
            DEBUG(u'Email from %s ignored, no tracker matched' % (sender, ))
            return

        # find appopriate handler
        handler = getattr(self, 'handle_%s_email' % tracker.type)
        # handler should parse the response and return essential info or None
        data = handler(msg, tracker)
        if data is None: # email should be ignored
            return
        user_id, date, bug_id, project_id, hours, subject = data

        # try finding existing entry for this bug
        session = DBSession()
        bug_id = str(bug_id)
        entry = TimeEntry.query.filter(TimeEntry.user_id==user_id)\
                               .filter(TimeEntry.date==date.date())\
                               .filter(TimeEntry.ticket_id==bug_id)\
                               .filter(TimeEntry.project_id==project_id)\
                               .first()
        if not entry:
            # create new entry
            entry = TimeEntry(
                user_id=user_id,
                date=date.date(),
                time=hours,
                description=subject,
                ticket_id=bug_id,
                project_id = project_id,
                modified_ts=date
            )
            session.add(entry)
            LOG(u'Adding new entry')
        else:
            # update existing entry
            if not entry.frozen:
                entry.time += hours
                entry.modified_ts = date # TODO: this might remove an already existing lateness
                session.add(entry)
                LOG(u'Updating existing entry')
            else:
                LOG(u'Omission of an existing entry because it is frozen')
        transaction.commit()