Example #1
0
def check_in(current_time=datetime.now()):

    res = session.query(Timesheet).order_by(Timesheet.id.desc()).first()
    if res is not None:
        entry = session.query(Entry).filter(
                Entry.date == date.today())\
                .order_by(Entry.id.desc()).first()

        #if checked in but havent checked out
        if entry and not entry.checkout_time:
            print 'You havent checked out from the last session. ' \
                    'I think this is a repeated action'

        #create a new entry when there is already check in and check out made
        elif entry and entry.checkout_time:
            res.entries.append(Entry(current_time))

        #create an entry if havned checked in
        else:
            res.entries.append(Entry(current_time))
    else:
        sheet = Timesheet()
        archive.timesheets.append(sheet)
        sheet.entries.append(Entry(current_time))

    session.commit()
Example #2
0
def create_new_sheet():

    #filter: sheet created less than a day to current time.
    if session.query(Timesheet).filter(Timesheet.created_date==date.today()).count():
        print 'You just created a timesheet today...'
    else:
        new = Timesheet()
        archive.timesheets.append(new)
        session.commit()
Example #3
0
def delete(sheet_id, entry_id):
    if sheet_id is not None:
        res = session.query(Timesheet).get(sheet_id)

    elif entry_id is not None:
        res = session.query(Entry).get(entry_id)

    else:
        print 'You didnt provide any option. usage: ts rm {-s} or {-e} {id}'
        sys.exit(0)

    if not res:
        click.echo('The ' + ('entry' if entry_id else 'timesheet') +\
            ' you want to delete does not exist. Maybe you entered a wrong id number.')
    else:
        session.delete(res)
    session.commit()
Example #4
0
def sendmail(to, subject, text, attach):

    user = session.query(User).first()
    if user is None:
        email = click.prompt('Please enter your email address', type=str)
        pwd = getpass.getpass('Password:'******'From'] = user.email
    msg['To'] = to
    msg['Subject'] = subject

    msg.attach(MIMEText(text))

    part = MIMEBase('application', 'octet-stream')
    if attach is not None:
        try:
            with open(attach, 'rb') as fh:
                data = fh.read()
            part.set_payload(data)
            Encoders.encode_base64(part)
            part.add_header(
                'Content-Disposition',
                'attachment; filename="%s"' % os.path.basename(attach))
            msg.attach(part)
        except IOError:
            click.echo(
                click.style('Error opening attachment file %s' % attach,
                            fg='red'))
    try:
        mailServer = smtplib.SMTP("smtp.gmail.com", 587)
        mailServer.ehlo()
        mailServer.starttls()
        mailServer.ehlo()
        mailServer.login(user.email, user.password)
        mailServer.sendmail(user.email, to, msg.as_string())
        click.echo(click.style('email sent!', fg='yellow'))
    except SMTPException:
        click.echo(click.style('Failed sending the email.', fg='red'))

    mailServer.close()
Example #5
0
def check_out(task, current_time=datetime.now()):

    sheet = session.query(Timesheet).order_by(Timesheet.id.desc()).first()

    if sheet is not None:
        entry = session.query(Entry).filter(Entry.date == date.today())\
                .order_by(Entry.id.desc()).first()

        if entry is not None:
            if entry.checkout_time is None:
                entry.checkout_time = current_time
                entry.hours = entry.get_hour()
                sheet.total_hours += entry.hours

            if task is not None:
                entry.task = task

            print sheet.total_hours
        else:
            print 'You havent checked in yet son!'

    else:
        print 'You havent created any timesheet.'
    session.commit()
Example #6
0
def update_name(target, args, kwargs):
    session.add(target)
    session.commit()
    target.name = 'sheet#' + str(target.id)