Changeset 7d7801f


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

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    r7ef7143 r7d7801f  
    77asadb/media/fysm/slides/
    88asadb/media/page-previews/fysm/
     9asadb/media/midway/maps/
    910asadb/util/saved-data/
    1011asadb/util/static-data/
  • 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    }
  • asadb/template/midway/upload.html

    rd848b98 r7d7801f  
    33{% block title %}ASA: {{midway.name}}: upload assignments{% endblock %}
    44{% block content %}
    5 <h2>{{midway.name}}: upload assignments</h2>
     5<h1>{{midway.name}}: upload assignments</h1>
     6
     7{% if uploaded %}
     8<h2>Results</h2>
     9
     10<h3>New entries added ({{found|length}})</h3>
     11
     12<table class='pretty-table'>
     13<tr>
     14    <th>Group</th>
     15    <th>Table</th>
     16</tr>
     17{% for assignment in found %}
     18<tr>
     19    <th>{{assignment.group}}</th>
     20    <td>{{assignment.location}}</td>
     21</tr>
     22{% endfor %}
     23</table>
     24
     25{% for issue, cases in issues.items %}
     26<h3>Issue: {{issue}} ({{cases|length}})</h3>
     27<table class='pretty-table'>
     28<tr>
     29    <th>Name</th>
     30    <th>Email</th>
     31    <th>Table</th>
     32</tr>
     33{% for name, email, table in cases %}
     34<tr>
     35    <th>{{name}}</th>
     36    <td>{{email}}</td>
     37    <td>{{table}}</td>
     38</tr>
     39{% endfor %}
     40</table>
     41{% endfor %}
     42
     43<!-- end of results -->
     44{% endif %}
     45
     46<h2>Input</h2>
    647
    748<form enctype="multipart/form-data" method="post" action="">
Note: See TracChangeset for help on using the changeset viewer.