login_required prettify_error render_to projects overtime_report html

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@login_required
@prettify_error
@render_to('projects/overtime_report.html')
def project_overtime(request, company, slug):
"""
Create new project estimate message.
User need to have ``PERMISSION_PROJECT_OVERTIME`` on processed project to
have access to this view.
"""
project = Project(company, slug)
_check_owner(project)
# Check permissions
if not project.has_permission(request.user, PERMISSION_PROJECT_OVERTIME):
return HttpResponseForbidden()
try:
project_estimate = project.last_estimate_values['project_time_per_cp']
except TypeError:
project_estimate = 2
hh = abs(int(project_estimate))
mm = abs(int((project_estimate - int(project_estimate))*60))
hrc_cp = '%d:%d' % (hh, mm)
initial = {'sender': request.user.pk, 'project': project, 'hrs_cp': hrc_cp}
redirect_to = reverse('company-timesheets_list', args=[slug])
if request.method == 'POST':
form = OvertimeAddReportForm(request.POST, initial=initial)
if form.is_valid():
# Generate time report
message, report_interval = form.generate_message()
message_uid = uuid.uuid4().hex
url = reverse('message_add', args=[project.company.slug, project.slug])
url += u'?draft=1&message_uid=%s' % message_uid
# Remove old messages' data from session
for key in request.session.keys():
if key.startswith('message'):
request.session.pop(key)
if request.session.modified:
request.session.save()
# And store it to session
request.session['message_draft'] = True
request.session['message_report_interval'] = True
request.session['message_draft_' + message_uid] = message
request.session['message_report_interval_' + message_uid] = (report_interval)
return redirect(url)
else:
form = OvertimeAddReportForm(initial=initial)
return {'company': company,
'form': form,
'redirect_to': redirect_to}