Changeset 56e8cb8


Ignore:
Timestamp:
Oct 12, 2011, 10:54:21 PM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage, test-hooks
Children:
8dfd3db
Parents:
ce7fd92
git-author:
Alex Dehnert <adehnert@…> (10/12/11 22:54:21)
git-committer:
Alex Dehnert <adehnert@…> (10/12/11 22:54:21)
Message:

Better participant membership UI (Trac: #26)

Location:
asadb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • asadb/forms/views.py

    r4260e2c r56e8cb8  
    11import forms.models
    22import groups.models
     3import groups.views
    34import settings
    45
     
    367368        update_obj.valid = forms.models.VALID_AUTOREJECTED
    368369
     370    qs = groups.models.Group.active_groups
     371    filterset = groups.views.GroupFilter(request.GET, qs)
     372    filtered_groups = filterset.qs.all()
     373    show_filtered_groups = ('search' in request.GET)
     374
    369375    message = ""
    370     if request.method == 'POST': # If the form has been submitted...
     376    message_type = "info"
     377
     378    if request.method == 'POST' and 'add-remove' in request.POST:
     379        group = groups.models.Group.objects.get(id=request.POST['group'])
     380        if request.POST['action'] == 'remove':
     381            if group in update_obj.groups.all():
     382                update_obj.groups.remove(group)
     383                message = "You have been successfully removed from %s." % (group, )
     384            else:
     385                message = "Sorry, but you're not in %s." % (group, )
     386                message_type = "warn"
     387        elif request.POST['action'] == 'add':
     388            if group in update_obj.groups.all():
     389                message = "Sorry, but you're already in %s." % (group, )
     390                message_type = "warn"
     391            else:
     392                update_obj.groups.add(group)
     393                message = "You have been successfully added to %s." % (group, )
     394        else:
     395            message = "Uh, somehow you tried to do something besides adding and removing..."
     396            message_type = "alert"
     397
     398    if request.method == 'POST' and 'list' in request.POST: # If the form has been submitted...
    371399        form = Form_PersonMembershipUpdate(request.POST, request.FILES, instance=update_obj) # A form bound to the POST data
    372400
     
    380408    context = {
    381409        'form':form,
    382         'groups':selected_groups,
     410        'filter':filterset,
     411        'show_filtered_groups':show_filtered_groups,
     412        'filtered_groups':filtered_groups,
     413        'member_groups':selected_groups,
    383414        'message': message,
     415        'message_type': message_type,
    384416        'pagename':'groups',
    385417    }
  • asadb/template/membership/confirm.html

    rc297267 r56e8cb8  
    77
    88{% if message %}
    9 <div class='messagebox infobox'>
     9<div class='messagebox {{message_type}}box'>
    1010<p>{{message}}</p>
    1111</div>
     
    1717</p>
    1818
    19 <p>
    20 Please select below the groups that you consider yourself a member of. If you
    21 come back to this form again, you'll be able to see all the groups you
    22 previously submitted, and add new groups. However, you should be careful not to
    23 deselect any groups.
    24 </p>
     19<p>We ask you to help with that process by indicating what groups you consider yourself a member of.</p>
     20
     21<h3>Groups you currently say you're a member of:</h3>
     22{% if member_groups %}
     23<ul>
     24{% for group in member_groups %}
     25    <li>{{group}}</li>
     26{% endfor %}
     27</ul>
     28{% else %}
     29<p>You are not currently indicating membership in any groups.</p>
     30{% endif %}
     31
     32<h3>Option 1: Add or remove groups one at a time</h3>
     33
     34<form action="" method="get">
     35    <table class='pretty-table'>
     36    {{ filter.form.as_table }}
     37    </table>
     38    <input type="submit" name='search' value="Search" />
     39    <input type="submit" name='stop-search' value="Stop searching" />
     40</form>
     41
     42{% if show_filtered_groups %}
     43<table class='pretty-table'>
     44<thead>
     45    <tr>
     46        <th>Name</th>
     47        <th>Website</th>
     48        <th>ASA DB</th>
     49        <th>Description</th>
     50        <th>Add/Remove</th>
     51    </tr>
     52</thead>
     53<tbody>
     54{% for group in filtered_groups %}
     55    <tr>
     56        <th>{{group.name}}</th>
     57        <td>{% if group.website_url %}<a href='{{group.website_url}}'>Website</a>{%endif%}</td>
     58        <td><a href='{% url groups:group-detail group.pk %}'>DB Entry</a></td>
     59        <td>{{group.description}}</td>
     60        <td>
     61            <form action="" method="post">
     62            {% csrf_token %}
     63            <input type="hidden" name="group" value="{{group.pk}}">
     64            {% if group in member_groups %}
     65            <input type="hidden" name="action" value="remove">
     66            <input type="submit" name="add-remove" value="Remove">
     67            {% else %}
     68            <input type="hidden" name="action" value="add">
     69            <input type="submit" name="add-remove" value="Add">
     70            {% endif %}
     71            </form>
     72        </td>
     73    </tr>
     74{% endfor %}
     75</tbody>
     76</table>
     77{% else %}
     78<p>Hit "search" to see matching groups.</p>
     79{% endif %}
     80
     81
     82<h3>Option 2: Select all your groups at once</h3>
     83
     84<p>Below is a list of all recognized groups. You can go through picking out the groups you are a member of. However, you should be careful not to deselect any groups (unless you aren't a member of them, of course).</p>
    2585
    2686<form enctype="multipart/form-data" method="post" action="">
     
    2888<table class='pretty-table'>
    2989{{ form.as_table }}
    30 <tr><th colspan='2'><input type='submit' value='Confirm membership' /></th></tr>
     90<tr><th colspan='2'><input type='submit' name='list' value='Update list of groups' /></th></tr>
    3191</table>
    3292</form>
    3393
    34 {% if groups %}
    35 <h3>Groups saved</h3>
    36 <ul>
    37 {% for group in groups %}
    38     <li>{{group}}</li>
    39 {% endfor %}
    40 </ul>
    41 {% endif %}
    42 
    4394{% endblock %}
Note: See TracChangeset for help on using the changeset viewer.