Beispiel #1
0
 def clock_in_when(cls, when: datetime, verbose=False):
     if verbose:
         print(f"Clocking you in at {when:%Y-%m-%d %H:%M:%S}")
     c = cls(
         time_in=when,
         date_key=get_date_key(when),
         month_key=get_month(when),
         week_key=get_week(when),
     )
     c.save()
     State.set_clok(c)
     return c
Beispiel #2
0
 def get_by_week_key(cls, key: Union[int, str] = None, all_jobs=False):
     if key is None:
         key = get_week()
     if all_jobs:
         return [
             i for i in (cls.query().filter(cls.week_key == int(key)).all())
         ]
     else:
         return [
             i
             for i in (cls.query().filter(cls.week_key == int(key)).filter(
                 cls.job_id == State.get().job.id).all())
         ]
Beispiel #3
0
 def get_by_week_key(self,
                     key: Union[datetime, int, str] = None,
                     all_jobs=False):
     key = get_week() if key is None else key
     if all_jobs:
         return [
             i
             for i in (Clok.query().filter(Clok.user_id == self.id).filter(
                 Clok.week_key == int(key)).all())
         ]
     else:
         return [
             i
             for i in (self.query().filter(Clok.user_id == self.id).filter(
                 Clok.week_key == int(key)).filter(
                     Clok.job_id == self.job_id).all())
         ]
Beispiel #4
0
    def clock_in_when(self, when: datetime = None, out: datetime = None):
        when = when if when is not None else datetime.now()
        c = Clok(
            user_id=self.id,
            job_id=self.job_id,
            time_in=when,
            date_key=get_date_key(when),
            month_key=get_month(when),
            week_key=get_week(when),
        )
        if out is not None:
            c.time_out = out
            c.update_span()

        c.save()
        self.set_clok(c)
        return c
Beispiel #5
0
def in_(
        when: str = Argument(None, help="Set a specific time to clock in"),
        out: str = Option(None, help="Set time to clock out"),
        m: str = Option(None, help="Journal Message to add to record"),
):
    """Clock into a job, or add a job day"""
    if when is not None and len(when.split("-")) > 3:
        when, out = parse_date_time_junction(when)
    else:
        if out is not None:
            out = parse_date_and_time(out)
        if when is not None:
            when = parse_date_and_time(when)

    if when is not None and out is not None:
        print(
            f"Creating entry for {when:%Y-%m-%d}: {when:%H:%M:%S} to {out:%H:%M:%S}"
        )
        c = Clok(
            time_in=when,
            time_out=out,
            date_key=get_date_key(when),
            month_key=get_month(when),
            week_key=get_week(when),
        )
        c.update_span()
        c.save()
        if m is not None:
            c.add_journal(m)
    elif when is not None and out is None:
        Clok.clock_in_when(when, verbose=True)
        if m is not None:
            Clok.get_last_record().add_journal(m)
        State.set_clok(Clok.get_last_record())
    else:
        Clok.clock_in(verbose=True)
        if m is not None:
            Clok.get_last_record().add_journal(m)
        State.set_clok(Clok.get_last_record())