def crons_violations(request): logger.info('function_call crons_violations(request) ->') for user in User.objects.all(): Query().analysis_violation(user) c = {} c.update(csrf(request)) return render_to_response('cron.html', c, context_instance=RequestContext(request))
def overview_week(request): logger.info('function_call overview_week(request) ->') days = Query().overview_week(request.user, datetime.datetime.today()) c = { 'user': request.user, 'days': days, 'SITENAME': settings.SITENAME, 'management': request.user.has_perm('auth.management') } c.update(csrf(request)) return render_to_response('overview_week.html', c, context_instance=RequestContext(request))
def analysis_violations(request): logger.info('function_call analysis_violations(request) ->') if request.method == 'POST': logger.info('Executing Query().analysis_violation') for user in User.objects.all(): Query().analysis_violation(user) violations = Violation.objects.all() c = { 'user': request.user, 'violations': violations, 'SITENAME': settings.SITENAME, 'management': request.user.has_perm('auth.management') } c.update(csrf(request)) return render_to_response('analysis_violation.html', c, context_instance=RequestContext(request))
def overview_year(request): logger.info('function_call overview_year(request) ->') year = datetime.datetime.today().year if request.POST.get('year'): year = int(request.POST.get('year')) months = Query().overview_year(request.user, year) c = { 'user': request.user, 'months': months, 'year': year, 'year_left': year - 1, 'year_right': year + 1, 'SITENAME': settings.SITENAME, 'management': request.user.has_perm('auth.management') } c.update(csrf(request)) return render_to_response('overview_year.html', c, context_instance=RequestContext(request))
def overview_month(request): logger.info('function_call overview_month(request) ->') date = datetime.datetime.today() if request.POST.get('date'): date = datetime.datetime.strptime(request.POST.get('date'), '%m.%Y') days = Query().overview_month(request.user, date.month, date.year) c = { 'user': request.user, 'days': days, 'date': date, 'date_left': date - relativedelta(months=+1), 'date_right': date + relativedelta(months=+1), 'SITENAME': settings.SITENAME, 'management': request.user.has_perm('auth.management') } c.update(csrf(request)) return render_to_response('overview_month.html', c, context_instance=RequestContext(request))
def overview_day(request): logger.info('function_call overview_day(request) ->') today = datetime.datetime(datetime.datetime.today().year, datetime.datetime.today().month, datetime.datetime.today().day) if request.POST.get('action'): if request.POST.get('action') == "delete": entry = Acquisition.objects.get(id=request.POST.get('id_entry')) entry.delete() if request.POST.get('action') == "choosedate": try: today = datetime.datetime.strptime(request.POST.get('date'), '%d.%m.%Y') except Exception: 1 + 1 queryresult = Query().overview_day(request.user, today) c = { 'user': request.user, 'form': DateForm(), 'today': today, 'start': queryresult['start'], 'end': queryresult['end'], 'break': queryresult['breakstring'], 'entire': queryresult['entirestring'], 'entries': queryresult['allAcquisitions'], 'projects': queryresult['projects'], 'SITENAME': settings.SITENAME, 'management': request.user.has_perm('auth.management') } c.update(csrf(request)) return render_to_response('overview_day.html', c, context_instance=RequestContext(request))
def personal_budget(request): logger.info('function_call personal_budget(request) ->') year = datetime.datetime.today().year form = YearForm(initial={'year': year}) if request.method == 'POST': form = YearForm(request.POST) if form.is_valid(): year = int(form.cleaned_data['year']) percent_yellow = 0 percent_red = 0 projects = UserProfile.objects.get(user=request.user).all_projects() worked = 0 allAcquisitions = Acquisition.objects.all().filter(user=request.user) userProfile = UserProfile.objects.get(user=request.user) expected = '-' if year == datetime.datetime.today().year: average = Query().average_hours(request.user, year) if average > 0: expected = average * (250 - userProfile.vacation_days) / 60 for project in projects: project.consumed = 0 project.consumed_all = 0 project.my_hours = Membership.objects.get(user=request.user, project=project).hours for ac in allAcquisitions: if ac.project == project: project.consumed_all = project.consumed_all + ( ac.end - ac.start).seconds if ac.start.date().year == year: project.consumed = project.consumed + (ac.end - ac.start).seconds worked = worked + (ac.end - ac.start).seconds project.consumed_all = float("%.2f" % project.consumed_all) / 3600 project.consumed_all = float("%.2f" % project.consumed_all) project.consumed = float("%.2f" % project.consumed) / 3600 project.consumed = float("%.2f" % project.consumed) worked = float("%.2f" % worked) / 3600 if worked < userProfile.min_hours: percent_green = worked * 100 / userProfile.max_hours + 1 elif worked < userProfile.max_hours: percent_green = userProfile.min_hours * 100 / userProfile.max_hours + 1 percent_yellow = worked * 100 / userProfile.max_hours - percent_green else: percent_red = int(100 - (userProfile.max_hours * 100 / worked)) percent_green = userProfile.min_hours * ( 100 - percent_red) / userProfile.max_hours + 1 percent_yellow = (userProfile.max_hours - userProfile.min_hours) * ( 100 - percent_red) / userProfile.max_hours c = { 'user': request.user, 'worked': float("%.2f" % worked), 'userProfile': userProfile, 'projects': projects, 'SITENAME': settings.SITENAME, 'management': request.user.has_perm('auth.management'), 'percent_green': int(percent_green), 'percent_yellow': int(percent_yellow), 'percent_red': int(percent_red), 'expected': expected, 'form': form } c.update(csrf(request)) return render_to_response('personal_budget.html', c, context_instance=RequestContext(request))