Changeset 7d7801f for asadb/forms/views.py
- Timestamp:
- Mar 17, 2013, 6:58:58 AM (13 years ago)
- Branches:
- master, space-access, stable, stage
- Children:
- cf509c0
- Parents:
- d848b98
- git-author:
- Alex Dehnert <adehnert@…> (03/17/13 06:58:58)
- git-committer:
- Alex Dehnert <adehnert@…> (03/17/13 06:58:58)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asadb/forms/views.py
rd848b98 r7d7801f 23 23 from django.db.models import Q, Count 24 24 25 import collections 25 26 import csv 26 27 import datetime … … 576 577 assignments = forms.models.MidwayAssignment.objects.filter(midway=midway) 577 578 context['assignments'] = assignments 579 context['pagename'] = 'midway' 578 580 579 581 return context … … 587 589 midway = get_object_or_404(forms.models.Midway, slug=slug, ) 588 590 591 uploaded = False 592 found = [] 593 issues = collections.defaultdict(list) 594 589 595 if request.method == 'POST': # If the form has been submitted... 590 596 form = MidwayAssignmentsUploadForm(request.POST, request.FILES, ) # A form bound to the POST data 591 597 592 598 if form.is_valid(): # All validation rules pass 593 pass 599 uploaded = True 600 reader = csv.DictReader(request.FILES['assignments']) 601 for row in reader: 602 group_name = row['Group'] 603 group_officers = row['officers'] 604 table = row['Table'] 605 issue = False 606 try: 607 group = groups.models.Group.objects.get(name=group_name) 608 assignment = forms.models.MidwayAssignment( 609 midway=midway, 610 location=table, 611 group=group, 612 ) 613 assignment.save() 614 found.append(assignment) 615 status = group.group_status.slug 616 if status != 'active': 617 issue = 'status=%s (added anyway)' % (status, ) 618 except groups.models.Group.DoesNotExist: 619 issue = 'unknown group (ignored)' 620 if issue: 621 issues[issue].append((group_name, group_officers, table)) 622 for issue in issues: 623 issues[issue] = sorted(issues[issue], key=lambda x: x[0]) 624 594 625 else: 595 626 form = MidwayAssignmentsUploadForm() # An unbound form … … 598 629 'midway':midway, 599 630 'form':form, 631 'uploaded': uploaded, 632 'found': found, 633 'issues': dict(issues), 634 #'issues': issues, 600 635 'pagename':'midway', 601 636 }
Note: See TracChangeset
for help on using the changeset viewer.