コード例 #1
0
ファイル: toggl.py プロジェクト: blesson3/TrackLater
    def update_entry(self, entry_id: str, new_entry: Entry,
                     issue: Optional[Issue]) -> Entry:
        updated_entry = self.push_session(session={
            'start_time': new_entry.start_time,
            'end_time': new_entry.end_time,
        },
                                          entry_id=entry_id,
                                          name=new_entry.title,
                                          project_id=new_entry.project)

        return Entry(
            id=_str(updated_entry['id']),
            start_time=parse_time(updated_entry['start']),
            end_time=parse_time(updated_entry['stop']),
            title=updated_entry['description'],
            project=_str(updated_entry.get('pid', None)),
        )
コード例 #2
0
def updateentry() -> Any:
    if request.method == 'POST':
        data = request.get_json()
        module = data.get('module')
        entry_id = _str(data.get('entry_id', None))
        project = data.get('project_id', None)
        if project == "null":
            project = None
        project_to_group = {
            project.pid: project.group
            for project in Project.query.all()
        }
        new_entry = Entry(start_time=parseTimestamp(data['start_time']),
                          end_time=parseTimestamp(data.get('end_time', None)),
                          id=entry_id,
                          issue=data.get('issue_id', None),
                          project=project,
                          title=data.get('title', ''),
                          text=data.get('text', ""),
                          extra_data=data.get('extra_data', {}),
                          group=project_to_group.get(str(project), None))
        issue = None
        if new_entry.issue:
            issue = Issue.query.filter(Issue.uuid == new_entry.issue).first()

        parser = Parser(None, None)

        if not entry_id:
            # Check that create is allowed
            assert isinstance(parser.modules[module], AddEntryMixin)
            new_entry = parser.modules[module].create_entry(  # type: ignore
                new_entry=new_entry, issue=issue)
        else:
            # Check that update is allowed
            assert isinstance(parser.modules[module], UpdateEntryMixin)
            new_entry = parser.modules[module].update_entry(  # type: ignore
                entry_id=new_entry.id,
                new_entry=new_entry,
                issue=issue)
        data = "error"

        if new_entry:
            Entry.query.filter(Entry.id == new_entry.id).delete()
            new_entry.module = module
            db.session.merge(new_entry)
            db.session.commit()
            data = new_entry.to_dict()

        return json.dumps(data, default=json_serial)
    return None
コード例 #3
0
ファイル: toggl.py プロジェクト: Eerovil/TrackLater
 def create_entry(self, new_entry: Entry, issue: Optional[Issue]) -> Entry:
     entry = self.push_session(
         session={
             'start_time': new_entry.start_time,
             'end_time': new_entry.end_time,
         },
         name=new_entry.title,
         project_id=new_entry.project
     )
     return Entry(
         id=_str(entry['id']),
         start_time=parse_time(entry['start']),
         end_time=parse_time(entry['stop']),
         title=entry['description'],
         project=entry.get('pid', None),
         group=new_entry.group,
     )
コード例 #4
0
ファイル: clockify.py プロジェクト: Eerovil/TrackLater
 def create_entry(self, new_entry: Entry, issue: Optional[Issue]) -> Entry:
     if not new_entry.project or new_entry.project == '0':
         new_entry.project = None
     if new_entry.end_time is None:
         raise ValueError("No end_time")
     entry = self.provider.workspace_request(
         'time-entries',
         data=json.dumps({
             'start': new_entry.start_time.isoformat() + 'Z',
             'end': new_entry.end_time.isoformat() + 'Z',
             'description': new_entry.title,
             'projectId': new_entry.project,
         }),
         method='POST'
     )
     return Entry(
         id=_str(entry['id']),
         start_time=parse_time(entry['timeInterval']['start']),
         end_time=parse_time(entry['timeInterval']['end']),
         title=entry['description'],
         project=entry['projectId'],
     )