Ignore:
Timestamp:
Mar 17, 2013, 6:58:58 AM (13 years ago)
Author:
Alex Dehnert <adehnert@…>
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)
Message:

WIP: midway page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/forms/views.py

    rd848b98 r7d7801f  
    2323from django.db.models import Q, Count
    2424
     25import collections
    2526import csv
    2627import datetime
     
    576577        assignments = forms.models.MidwayAssignment.objects.filter(midway=midway)
    577578        context['assignments'] = assignments
     579        context['pagename'] = 'midway'
    578580
    579581        return context
     
    587589    midway = get_object_or_404(forms.models.Midway, slug=slug, )
    588590
     591    uploaded = False
     592    found = []
     593    issues = collections.defaultdict(list)
     594
    589595    if request.method == 'POST': # If the form has been submitted...
    590596        form = MidwayAssignmentsUploadForm(request.POST, request.FILES, ) # A form bound to the POST data
    591597
    592598        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
    594625    else:
    595626        form = MidwayAssignmentsUploadForm() # An unbound form
     
    598629        'midway':midway,
    599630        'form':form,
     631        'uploaded': uploaded,
     632        'found': found,
     633        'issues': dict(issues),
     634        #'issues': issues,
    600635        'pagename':'midway',
    601636    }
Note: See TracChangeset for help on using the changeset viewer.