Skip to content

Commit

Permalink
Revert "clean: remove duplicate pages under /db/my/*"
Browse files Browse the repository at this point in the history
This reverts commit 952f4b4.
  • Loading branch information
benjamin-antupit committed Jun 4, 2022
1 parent 952f4b4 commit b6af4e0
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 11 deletions.
11 changes: 10 additions & 1 deletion events/urls/my.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@

url(r'^events/', include([
url(r'^$', views.my.myevents, name="events"),
url(r'^(?P<eventid>[0-9]+)/report/$', views.my.ccreport, name="report"),

# TODO: merge these with their events equivalents.
url(r'^(?P<eventid>[0-9]+)/files/$', views.my.eventfiles, name="event-files"),
url(r'^(?P<eventid>[0-9]+)/report/$', views.my.ccreport, name="report"),
url(r'^(?P<eventid>[0-9]+)/hours/$', views.my.hours_list, name="hours-list"),
url(r'^(?P<eventid>[0-9]+)/hours/bulk/$', views.my.hours_bulk,
name="hours-bulk"),
url(r'^(?P<eventid>[0-9]+)/hours/mk/$', views.my.hours_mk,
name="hours-new"),
url(r'^(?P<eventid>[0-9]+)/hours/(?P<userid>[0-9]+)$', views.my.hours_edit,
name="hours-edit"),
url(r'^(?P<eventid>[0-9]+)/survey/$', login_required(views.my.PostEventSurveyCreate.as_view()),
name="post-event-survey"),
url(r'^survey/success/$', views.my.survey_success, name="survey-success"),
])),

]
177 changes: 169 additions & 8 deletions events/views/my.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import datetime
from itertools import chain

from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from django.db.models.aggregates import Sum
from django.forms.models import modelformset_factory
from django.forms.models import inlineformset_factory, modelformset_factory
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render, redirect
from django.urls.base import reverse
Expand All @@ -13,10 +14,12 @@
from django.template import loader

from emails.generators import generate_selfservice_notice_email
from events.forms import (SelfServiceOrgRequestForm, PostEventSurveyForm, OfficeHoursForm)
from events.models import CCReport, BaseEvent, PostEventSurvey, OfficeHour
from events.forms import (EditHoursForm, InternalReportForm, MKHoursForm,
SelfServiceOrgRequestForm, PostEventSurveyForm, OfficeHoursForm)
from events.models import CCReport, BaseEvent, Event, Hours, PostEventSurvey, CCR_DELTA, OfficeHour
from helpers.mixins import LoginRequiredMixin
from helpers.revision import set_revision_comment
from helpers.util import curry_class


@login_required
Expand Down Expand Up @@ -95,14 +98,172 @@ def myevents(request):

return render(request, 'myevents.html', context)


@login_required
def eventfiles(request, eventid):
return redirect('/db/events/view/' + eventid + '/#files')


# Views Relating to Crew Chiefs
@login_required
def ccreport(request, eventid):
if BaseEvent.objects.get(pk=eventid).closed:
return redirect('/db/events/view/' + str(eventid) + '/#reports')
elif (my_ccreports:= CCReport.objects.filter(event=eventid, crew_chief=request.user)).exists():
return redirect('/db/events/view/' + str(eventid) + '/report/update/' + str(my_ccreports.last().id) + '/')
""" Submits a crew chief report """
context = {}

user = request.user

uevent = user.ccinstances.filter(event__pk=eventid)
# check that the event in question belongs to the user
if not uevent:
return HttpResponse("This event must not have been yours, or is closed")

event = uevent[0].event
if not event.reports_editable:
return render(request, 'too_late.html', {'days': CCR_DELTA, 'event': event})

# get event
x = event.ccinstances.filter(crew_chief=user)
context['msg'] = "Crew Chief Report for '<em>%s</em>' (%s)" % (event, ",".join([str(i.category) for i in x]))

# create report
try:
report = CCReport.objects.get(event=event, crew_chief=user)
except CCReport.DoesNotExist:
report = None

# standard save flow
if request.method == 'POST':
formset = InternalReportForm(data=request.POST, event=event, request_user=user, instance=report)
if formset.is_valid():
formset.save()
return HttpResponseRedirect(reverse("my:events"))
else:
context['formset'] = formset

else:
formset = InternalReportForm(event=event, request_user=user, instance=report)

context['formset'] = formset

return render(request, 'mycrispy.html', context)


@login_required
def hours_list(request, eventid):
""" Lists a user's work hours """
context = {}
user = request.user

event = user.ccinstances.filter(event__pk=eventid)

if not event:
return HttpResponse("You must not have cc'd this event, or it's closed")
event = event[0].event
context['event'] = event

hours = event.hours.all()
context['hours'] = hours

return render(request, 'myhours.html', context)


@login_required
def hours_mk(request, eventid):
""" Hour Entry Form for CC """
context = {}

user = request.user
uevent = user.ccinstances.filter(event__pk=eventid)

if not uevent:
return HttpResponse("This event must not have been yours, or is closed")

event = uevent[0].event

if not isinstance(event, Event):
# New event - redirect to bulk update tool instead
return HttpResponseRedirect(reverse("my:hours-bulk", args=(event.id,)))

if not event.reports_editable:
return render(request, 'too_late.html', {'days': CCR_DELTA, 'event': event})

context['msg'] = "Hours for '%s'" % event.event_name
if request.method == 'POST':
formset = MKHoursForm(event, request.POST)
if formset.is_valid():
formset.save()
return HttpResponseRedirect(reverse("my:hours-list", args=(event.id,)))
else:
return redirect('/db/events/view/' + str(eventid) + '/report/mk/')
formset = MKHoursForm(event)

context['formset'] = formset

return render(request, 'mycrispy.html', context)


@login_required
def hours_edit(request, eventid, userid):
""" Hour Entry Form for CC (editing)"""
context = {}
user = request.user
uevent = user.ccinstances.filter(event__pk=eventid)

if not uevent:
return HttpResponse("You must not have cc'd this event, or it's closed")

event = uevent[0].event
if not event.reports_editable:
return render(request, 'too_late.html', {'days': CCR_DELTA, 'event': event})

hours = get_object_or_404(Hours, event=event, user_id=userid)
u = get_object_or_404(get_user_model(), pk=userid)
context['msg'] = "Hours for '%s' on '%s'" % (u, event.event_name)
if request.method == 'POST':
formset = EditHoursForm(request.POST, instance=hours)
if formset.is_valid():
formset.save()
return HttpResponseRedirect(reverse("my:hours-list", args=(event.id,)))
else:
formset = EditHoursForm(instance=hours)

context['formset'] = formset

return render(request, 'mycrispy.html', context)


@login_required
def hours_bulk(request, eventid):
""" Bulk Hours Entry Form """
context = {}
user = request.user
uevent = user.ccinstances.filter(event__pk=eventid)

if not uevent:
return HttpResponse("You must not have cc'd this event, or it's closed")

event = uevent[0].event
if not event.reports_editable:
return render(request, 'too_late.html', {'days': CCR_DELTA, 'event': event})

context['msg'] = "Bulk Hours Entry"

context['event'] = event

mk_event_formset = inlineformset_factory(Event, Hours, extra=3, exclude=[])
mk_event_formset.form = curry_class(MKHoursForm, event=event)

if request.method == 'POST':
formset = mk_event_formset(request.POST, instance=event)
if formset.is_valid():
formset.save()
return HttpResponseRedirect(reverse("my:hours-list", args=(event.id,)))
else:
formset = mk_event_formset(instance=event)

context['formset'] = formset

return render(request, 'formset_hours_bulk.html', context)


class PostEventSurveyCreate(LoginRequiredMixin, CreateView):
model = PostEventSurvey
Expand Down
43 changes: 43 additions & 0 deletions site_tmpl/my.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% extends 'base_admin.html' %}
{% load staticfiles %}


{% block content %}
<div class="container marketing" style="text-align:center;">
<div class="row">
<div class="col-md-3">
<img class="img-circle" src="{% static 'img/Account.gif' %}"/>
<h2> My Account </h2>
<a href="{% url "my-acct" %}" class="btn btn-lg btn-primary">Modify Account</a>
</div>


<div class="col-md-3">
<img class="img-circle" src="{% static 'img/WorkOrders.gif' %}"/>
<h2> WorkOrders </h2>
<div class="btn-group">
<a href="{% url 'wizard:start' %}" class="btn btn-lg btn-primary">New</a>
<a href="{% url "my:workorder" %}" class="btn btn-lg btn-primary">Previous</a>
</div>
</div>


<div class="col-md-3">
<img class="img-circle" src="{% static 'img/Org.gif' %}"/>
<h2> My Orgs </h2>
<a href="{% url "my:orgs" %}" class="btn btn-lg btn-primary">Associated Orgs</a>
</div>

{% if is_lnl %}
<div class="col-md-3">
<img class="img-circle" src="{% static 'img/MyEvents.gif' %}"/>
<h2> My Events </h2>
<a href="{% url "my:events" %}" class="btn btn-lg btn-primary">View Events</a>

</div>
{% endif %}

</div>
</div>

{% endblock %}
34 changes: 34 additions & 0 deletions site_tmpl/myeventfiles.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends 'base_admin.html' %}
{% load crispy_forms_tags %}
{% block extras %}
{% include "js_phonelimit.tmpl" %}
{% endblock %}

{% block content %}
<h2> <a href="{% url "accounts:me" %}">My</a> Files for '<em>{{event }}</em>'</h2>
<table class="table">
<tr>
<th>Service</th>
<th>Notes</th>
<th>File Name</th>
<th></th>
</tr>
{% for a in event.attachments.all %}
<tr>
<td>
{% for s in a.for_service.all %}
{{ s }}{% if not forloop.last %},{% endif %}
{% empty %}
{% endfor %}
</td>
<td>{{ a.note }}</td>
<td>{{ a.attachment.name }}</td>
<td><a class="btn btn-default" href="{{ a.attachment.url }}">Link</a></td>
</tr>


{% empty %}
<tr><td colspan="4">No files have been uploaded</td></tr>
{% endfor %}
</table>
{% endblock %}
4 changes: 2 additions & 2 deletions site_tmpl/myevents.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ <h1>Events as Crew Chief </h1>
{% if instance.event.reports_editable %}
<a class="btn btn-primary" href="{% url "my:report" instance.event.id %}">CC
Report</a>
<a class="btn btn-primary" href="{% url "events:add-bulk-crew" instance.event.id %}">Crew Hours</a>
<a class="btn btn-primary" href="{% url "my:hours-list" instance.event.id %}">Crew Hours</a>
{% endif %}
<a class="btn btn-success" target="_blank" href="https://wpi0.sharepoint.com/sites/gr-lnl/Event%20Photos/Forms/Thumbnails.aspx?view=7&q={{ instance.event.event_name|urlencode }}">Photos</a>
{% if instance.event.attachments %}
<a class="btn btn-default" href="{% url "events:detail" instance.event.id %}#files">Files</a>
<a class="btn btn-default" href="{% url "my:event-files" instance.event.id %}">Files</a>
{% endif %}

</div>
Expand Down
26 changes: 26 additions & 0 deletions site_tmpl/myhours.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends 'base_admin.html' %}

{% block content %}
<h1><a href="{% url "my:events" %}">My</a> Hours for '<em>{{event}}</em>'</h1>
<table class="table">
<thead>
<tr>
<th>Member</th>
<th>Hours</th>
<th>Service</th>
<th></th>
</tr>
</thead>
{% for hour in hours %}
<tr>
<td>{{ hour.user.get_full_name }}</td>
<td>{{ hour.hours }}</td>
<td>{{ hour.category }}</td>
<td><a href="{% url "my:hours-edit" event.id hour.user.id %}">Update</a>
</tr>
{% endfor %}
</table>
<a class="btn btn-primary btn-lg" href="{% url "my:hours-bulk" event.id %}">Bulk Add</a>
<a class="btn btn-warning btn-lg" href="{% url "my:hours-new" event.id %}">Single Add</a>
<a class="btn btn-warning btn-lg" href="{% url "my:events" %}">Done</a>
{% endblock %}

0 comments on commit b6af4e0

Please sign in to comment.