Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

399 reduce redundancy in row based forms #664

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions events/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,8 @@ def __init__(self, event, *args, **kwargs):
if isinstance(event, Event2019):
self.fields['category'].queryset = Category.objects.filter(
pk__in=event.serviceinstance_set.values_list('service__category', flat=True))
if len(self.fields['category'].queryset) == 1:
self.fields['category'].initial = self.fields['category'].queryset.first()

def clean(self):
super(MKHoursForm, self).clean()
Expand Down Expand Up @@ -1347,6 +1349,8 @@ def __init__(self, event, *args, **kwargs):
if isinstance(event, Event2019):
self.fields['category'].queryset = Category.objects.filter(
pk__in=event.serviceinstance_set.values_list('service__category', flat=True))
if len(self.fields['category'].queryset) == 1:
self.fields['category'].initial = self.fields['category'].queryset.first()
self.fields['setup_start'].initial = self.fields['setup_start'].prepare_value(
self.event.datetime_setup_complete.replace(second=0, microsecond=0)
)
Expand Down Expand Up @@ -1825,6 +1829,8 @@ def __init__(self, *args, **kwargs):
options.append((event.pk, " %s" % event.event_name))

self.fields['event'] = forms.ChoiceField(choices=options, label="Select Event", widget=forms.RadioSelect)
if len(options) == 1:
self.fields['event'].initial = options[0][0]


class CrewCheckoutForm(forms.Form):
Expand Down Expand Up @@ -1884,6 +1890,8 @@ def __init__(self, *args, **kwargs):
min_value=0)
hour_set.fields.append(Column('hours_%s' % category.name, css_class="mx-2"))
hour_set.fields.append(Column('total', css_class="mx-2"))
if len(categories) == 1:
self.fields['hours_%s' % categories[0].name].initial = self.total_hrs

def clean(self):
cleaned_data = super(CheckoutHoursForm, self).clean()
Expand Down
13 changes: 9 additions & 4 deletions events/views/flow.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import math
from datetime import timedelta
from datetime import datetime, timedelta
from decimal import Decimal
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required, permission_required
from django.core.exceptions import PermissionDenied, ValidationError
from django.db.models import Avg, Count
from django.db.models import Avg, Count, Q
from django.forms.models import inlineformset_factory
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
Expand Down Expand Up @@ -461,8 +461,9 @@ def hours_prefill_self(request, id):
if not event.ccinstances.exists():
raise PermissionDenied
if event.hours.filter(user=request.user).exists():
messages.add_message(request, messages.ERROR, 'You already have hours for this event.')
messages.add_message(request, messages.ERROR, 'You are already checked in to this event.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you test to make sure that this does the expected? It looks like it'll error whenever a member has hours

return HttpResponseRedirect(reverse('events:detail', args=(event.id,)))
# return HttpResponseRedirect(reverse('events:crew-checkout'))
if timezone.now() < min(event.ccinstances.values_list('setup_start', flat=True)):
messages.add_message(request, messages.ERROR, 'You cannot use this feature until the event setup has started.')
return HttpResponseRedirect(reverse('events:detail', args=(event.id,)))
Expand Down Expand Up @@ -503,7 +504,7 @@ def checkin(request):

if request.user.event_records.filter(active=True).exists():
context['page'] = {"title": "You are already checked into an event",
"body": "<a href='" + reverse("events:crew-tracker") + "' class='btn btn-primary'>Back</a>"}
"body": "<a href='" + reverse("events:crew-checkout") + "' class='btn btn-primary'>Go to Crew Checkout</a>"}
return render(request, 'static_page.html', context)

if request.method == 'POST':
Expand Down Expand Up @@ -1085,6 +1086,10 @@ def viewevent(request, id):

context['apps'] = apps

context['can_selfcrew'] = request.user.is_lnl & BaseEvent.objects.filter(
Q(closed=False) & Q(cancelled=False), id=event.id, ccinstances__setup_start__lte=timezone.now(),
datetime_end__gte=(timezone.now() - timedelta(hours=3))).exists()

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


Expand Down
11 changes: 6 additions & 5 deletions site_tmpl/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
{% if selfcrew_events.exists %}
<div class="visible-xs panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Mark yourself as crew for an ongoing event</h3>
<h3 class="panel-title">Select an event to check in</h3>
</div>
<div class="panel-body">
<a class="btn btn-primary" href="{% url 'events:crew-checkin' %}">Check in</a>
<a class="btn btn-primary" href="{% url 'events:crew-checkout' %}">Check out</a>
{% comment %}
{% for event in selfcrew_events %}
<a class="btn btn-default" href="{% url 'events:selfcrew' event.id %}">{{ event.event_name }}</a>
{% endfor %}
{% endcomment %}
<a class="btn btn-warning" href="{% url 'events:crew-checkout' %}">Crew Check Out</a>
</div>
</div>
{% endif %}
Expand All @@ -48,6 +45,10 @@ <h3 class="panel-title">Quick Links</h3>
{% if request.user.is_superuser %}
<a class="btn btn-danger" href="../admin">Admin</a>
{% endif %}
{% if selfcrew_events.exists %}
<a class="hidden-xs btn btn-warning" href="{% url 'events:crew-checkin' %}">Crew Check In</a>
<a class="hidden-xs btn btn-warning" href="{% url 'events:crew-checkout' %}">Crew Check Out</a>
{% endif %}
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions site_tmpl/uglydetail.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ <h1>
<h3>Status: <b>{{ event.status }}</b></h3>

<div class="btn-group">
<!--{% if can_selfcrew %}
<a class="btn btn-warning btn-lg" href="{% url "events:crew-tracker" %}">Crew Check In/Out</a>
{% endif %}-->
{% permission request.user has 'events.view_event_reports' of event %}
<a class="btn btn-info btn-lg" href="{% url "events:pdf" event.id %}">PDF</a>
{% endpermission %}
Expand Down
Loading