Exemple #1
0
    def log(self, date, hours, task, description):
        '''
        log <date> <hours> <task> <description>

        date is "today" for current date, or any date in dd/MM/yyyy format
        hours is in decimal unit (example: 1:15 hours would be 1.25)
        task is a known task name (see: dp task)
        '''
        try:
            if date.strip() == 'today':
                date = datetime.now()
            else:
                date = datetime.strptime(date, DATE_FORMAT)
        except ValueError:
            return 'wrong formated date "%s", see: dp help log' % date
        if task not in self.data.tasks:
            return 'unknown task "%s", see: dp task' % task
        if any(not bool(self.data[s]) for s in SETTINGS):
            return 'not all settings configured, see: dp config'
        bot = DotProjectBot(self.data.server)
        bot.login(self.data.user, self.data.password)
        bot.log_task(self.data.tasks[task],
                     date,
                     hours,
                     description)
        return 'Log created'
Exemple #2
0
def log_hours():
    logging.basicConfig(level=logging.INFO)
    
    categories = settings.HAMSTER_TO_DP.keys()
    tag_logged = Tag.get_or_create(name = '_logged_in_dp_')
    

    already_tagged = [ft.fact.id for ft in FactTag.filter(tag=tag_logged).distinct()]
    

    #get all facts that belong to exportable categories, finished, and
    # not previously posted
    facts = Fact.filter(
                Q(activity__category__name__in=categories) & 
                ~Q(end_time__is=None) &
              # ~Q(fact_tags_set__tag=tag_logged)     # * see note
                ~Q(id__in=already_tagged)
            )

    # NOTE
    # I want to exclude Facts tagged with ``tag_logged``, . but that ~Q() condition
    # only exclude the facts that are ONLY tagged with ``tag_logged``.
    
    # the last Q is a workaround but imply a nested select.
    # How I should write this query?

    if not facts.exists():
        logging.info("You're up to date! There is no unsynced tasks")
        return
        

    br = DotProjectBot(settings.DP_BASE_URL)
    br.login(settings.DP_USERNAME, settings.DP_PASSWORD)


    for f in facts:
        #process data
        tags = ', '.join([ft.tag.name for ft in f.fact_tags_set])

        if tags and f.description:
            description = '%s %s: %s' % (f.activity.name, tags, f.description)
        elif tags:
            description = '%s %s' % (f.activity.name, tags)
        elif f.description:
            description = '%s %s' % (f.activity.name, f.description)
        else:
            description = f.activity.name

        dp_task_id = settings.HAMSTER_TO_DP[f.category.name]

        #and post the fact into dotproject!
        br.log_task(dp_task_id, f.start_time, f.duration, description)

        #then mark the fact as logged.
        ft = FactTag(fact=f, tag=tag_logged)
        ft.save()