Exemple #1
0
 def get(self, year, month, day):
     year, month, day = map(int, (year, month, day))
     logs = WorkLog.get(date(year, month, day))
     if logs:
         self.write(json.dumps(logs))
     else:
         self.set_status(404)
         self.write('404: not found')
Exemple #2
0
    def post(self, year, month, day):
        year, month, day = map(int, (year, month, day))
        the_date = date(year, month, day)
        request_body = json.loads(self.request.body)
        if any(x not in request_body for x in ['hours', 'description']):
            self.set_status(400)
            self.write('400: Required parameter missing')
            return
        id = request_body.get('id', None)
        hours = request_body['hours']
        description = request_body['description']

        if id:
            log = WorkLog.get(id)
            if not log:
                self.set_status(400)
                self.write('400: No log with id %s' % id)
                return
        else:
            log = WorkLog()
        log.date = the_date
        log.hours = hours
        log.description = description
        log.save()
        for time_tracker in settings.time_trackers:
            try:
                time_tracker.log_hours(the_date, hours, description)
            except Exception as e:
                print "Unable to sync with time tracking service", e
        if id:
            self.set_status(201)  # created
Exemple #3
0
def getWorkLog(contract, month, year):
    try:
        if contract.contract_begin.year > year or \
                        contract.contract_end.year < year or \
                (contract.contract_begin.year == year and contract.contract_begin.month > month) or \
                (contract.contract_end.year == year and contract.contract_end.month < month):
            raise ValidationError("Invalid workLog (shouldn't happen)")
        workL = WorkLog.objects.get(contract=contract, month=month, year=year)
    except ObjectDoesNotExist:
        workL = WorkLog()
        workL.month = month
        workL.year = year
        workL.contract = contract
        workL.save()
    return workL
Exemple #4
0
def worklog_add():
    form = WorkLogEditForm(request.form)

    if form.validate_on_submit():
        worklog = WorkLog()
        form.populate_obj(worklog)
        worklog.created_user = current_user.name
        worklog.updated_user = current_user.name
        worklog.created_time = datetime.datetime.now()
        worklog.updated_time = datetime.datetime.now()
        worklog.updated_count = 0
        db.session.add(worklog)
        db.session.commit()
        return redirect(url_for('worklog_list'))

    return render_template('worklog_edit.html', form=form)
Exemple #5
0
 def stop_counting(self):
     a = AdditionalTools.AdditionalTools()
     uid = self.uid
     total_time = self.total_duration
     # note the work finish time
     finish = datetime.datetime.now()
     finisht = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
     # count the worktime
     delta = finish - self.start
     work_time = str(datetime.timedelta(seconds=delta.seconds))
     # get work note from input
     note = request.form['worknote']
     # put total time in a human way
     time_hours = a.time_hours(delta.seconds)
     time_precise = a.time_human(delta.seconds)
     # count monies
     session_monies = self.rate * time_hours
     # save worklog entry in worklog
     new_record = WorkLog(uid, self.startt, finisht, delta.seconds,
                          time_precise, int(session_monies), note)
     db.session.add(new_record)
     db.session.commit()
     # put some variables for page rendering
     tbutton = 'start'
     tbutton_class = 'btn-primary'
     note_class = 'hidden'
     status_class = ''
     # render page
     return render_template('logger.htm',
                            rate=self.rate,
                            currency=self.currency,
                            total_duration=self.total_duration,
                            total_month_duration=self.total_month_duration,
                            workitems=self.workitems,
                            client_name=self.client[0],
                            monies=self.monies,
                            month_monies=self.month_monies,
                            company_name=self.client[2],
                            uid=self.uid,
                            tbutton=tbutton,
                            tbutton_class=tbutton_class,
                            note_class=note_class,
                            status_class=status_class,
                            start_time=self.start,
                            stop_time=finisht)
Exemple #6
0
def getWorkLog(contract, month, year):
    try:
        if contract.contract_begin.year > year or \
                        contract.contract_end.year < year or \
                (contract.contract_begin.year == year and contract.contract_begin.month > month) or \
                (contract.contract_end.year == year and contract.contract_end.month < month):
            raise ValidationError("Invalid workLog (shouldn't happen)")
        workL = WorkLog.objects.get(contract=contract, month=month, year=year)
    except ObjectDoesNotExist:
        workL = WorkLog()
        workL.month = month
        workL.year = year
        workL.contract = contract
        workL.save()
    return workL
Exemple #7
0
def worklog_add():
    form = WorkLogEditForm(request.form)

    if form.validate_on_submit():
        worklog = WorkLog()
        form.populate_obj(worklog)
        worklog.created_user = current_user.name
        worklog.updated_user = current_user.name
        worklog.created_time = datetime.datetime.now()
        worklog.updated_time = datetime.datetime.now()
        worklog.updated_count = 0
        db.session.add(worklog)
        db.session.commit()
        return redirect(url_for('worklog_list'))

    return render_template('worklog_edit.html', form=form)
Exemple #8
0
 def delete(self, year, month, day):
     year, month, day = map(int, (year, month, day))
     the_date = date(year, month, day)
     id = self.get_argument('id')
     log = WorkLog.get(id)
     log.delete()
Exemple #9
0
 def get(self):
     all_logs = WorkLog.all()
     self.write(json.dumps(all_logs))
Exemple #10
0
def serve():
    handlers = [(r'/', MainHandler)]
    if hasattr(settings, 'favicon_path'):
        handlers.append((r'/(favicon.ico)', tornado.web.StaticFileHandler,
                        {'path': settings.favicon_path}))
    handlers.append((r'/static/(.*)', tornado.web.StaticFileHandler,
                    {'path': settings.static_path}))
    handlers.extend(api.GetRegisteredResources())
    tornado_app = tornado.web.Application(handlers)
    from models import WorkLog
    from datetime import date
    log = WorkLog()
    log.date = date.today()
    log.hours = 5
    log.description = "derp"
    log.save()
    log = WorkLog()
    log.date = date.today()
    log.hours = 6
    log.description = "herp"
    log.save()
    server = tornado.httpserver.HTTPServer(tornado_app)
    server.listen(tornado.options.options.port)
    tornado.ioloop.IOLoop.instance().start()