Changeset c297267


Ignore:
Timestamp:
Oct 11, 2011, 7:41:37 PM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage, test-hooks
Children:
1ed7e51
Parents:
00d201c
git-author:
Alex Dehnert <adehnert@…> (10/11/11 17:08:00)
git-committer:
Alex Dehnert <adehnert@…> (10/11/11 19:41:37)
Message:

Cycle-based system for people's confirmation

Location:
asadb
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • asadb/forms/admin.py

    r00d201c rc297267  
    2323admin.site.register(forms.models.FYSMCategory, FYSMCategoryAdmin)
    2424
     25class Admin_GroupConfirmationCycle(admin.ModelAdmin):
     26    list_display = (
     27        'pk',
     28        'name',
     29        'slug',
     30        'create_date',
     31    )
     32    list_display_links = ('pk', 'name', 'slug', )
     33    prepopulated_fields = {"slug": ("name",)}
     34admin.site.register(forms.models.GroupConfirmationCycle, Admin_GroupConfirmationCycle)
     35
    2536class Admin_GroupMembershipUpdate(admin.ModelAdmin):
    2637    list_display = (
     
    4354        'pk',
    4455        'username',
     56        'cycle',
    4557        'update_time',
     58        'deleted',
     59        'valid',
    4660    )
    47     list_filter = ('groups', )
    48     list_display_links = ('pk', 'username', )
     61    list_filter = ('valid', 'groups', )
     62    list_display_links = ('pk', 'username', 'cycle', )
    4963admin.site.register(forms.models.PersonMembershipUpdate, Admin_PersonMembershipUpdate)
  • asadb/forms/models.py

    r6d986af rc297267  
    137137
    138138
     139class GroupConfirmationCycle(models.Model):
     140    name = models.CharField(max_length=30)
     141    slug = models.SlugField()
     142    create_date = models.DateTimeField(default=datetime.datetime.now)
     143
     144    def __unicode__(self, ):
     145        return u"GroupConfirmationCycle %d: %s" % (self.id, self.name, )
     146
     147    @classmethod
     148    def latest(cls, ):
     149        return cls.objects.order_by('-create_date')[0]
     150
     151
    139152class GroupMembershipUpdate(models.Model):
    140153    update_time = models.DateTimeField(default=datetime.datetime.utcfromtimestamp(0))
     
    167180
    168181
     182VALID_UNSET         = 0
     183VALID_AUTOVALIDATED = 10
     184VALID_OVERRIDDEN    = 20    # confirmed by an admin
     185VALID_AUTOREJECTED      = -10
     186VALID_HANDREJECTED      = -20
     187VALID_CHOICES = (
     188    (VALID_UNSET,           "unvalidated"),
     189    (VALID_AUTOVALIDATED,   "autovalidated"),
     190    (VALID_OVERRIDDEN,      "hand-validated"),
     191    (VALID_AUTOREJECTED,    "autorejected"),
     192    (VALID_HANDREJECTED,    "hand-rejected"),
     193)
     194
    169195class PersonMembershipUpdate(models.Model):
    170196    update_time = models.DateTimeField(default=datetime.datetime.utcfromtimestamp(0))
    171197    username = models.CharField(max_length=30)
     198    cycle = models.ForeignKey(GroupConfirmationCycle)
     199    deleted = models.DateTimeField(default=None, null=True, blank=True, )
     200    valid = models.IntegerField(choices=VALID_CHOICES, default=VALID_UNSET)
    172201    groups = models.ManyToManyField(groups.models.Group, help_text="By selecting a group here, you indicate that you are an active member of the group in question.<br>If your group does not appear in the list above, then please email asa-exec@mit.edu.<br>")
    173202
  • asadb/forms/views.py

    r0e6090f rc297267  
    339339    initial = {
    340340    }
    341     update_obj = forms.models.PersonMembershipUpdate()
    342     update_obj.update_time  = datetime.datetime.now()
    343     update_obj.username = request.user.username
    344 
     341    cycle = forms.models.GroupConfirmationCycle.latest()
     342    try:
     343        update_obj = forms.models.PersonMembershipUpdate.objects.get(
     344            username=request.user.username,
     345            deleted__isnull=True,
     346            cycle=cycle,
     347        )
     348        selected_groups = update_obj.groups.all()
     349        print "Got update"
     350    except forms.models.PersonMembershipUpdate.DoesNotExist:
     351        update_obj = forms.models.PersonMembershipUpdate()
     352        update_obj.update_time  = datetime.datetime.now()
     353        update_obj.username = request.user.username
     354        update_obj.cycle = cycle
     355        selected_groups = []
     356
     357    accounts = groups.models.AthenaMoiraAccount
     358    try:
     359        person = accounts.active_accounts.get(username=request.user.username)
     360        if person.is_student():
     361            update_obj.valid = forms.models.VALID_AUTOVALIDATED
     362        else:
     363            update_obj.valid = forms.models.VALID_AUTOREJECTED
     364    except accounts.DoesNotExist:
     365        pass
     366        update_obj.valid = forms.models.VALID_AUTOREJECTED
     367
     368    message = ""
    345369    if request.method == 'POST': # If the form has been submitted...
    346370        form = Form_PersonMembershipUpdate(request.POST, request.FILES, instance=update_obj) # A form bound to the POST data
     
    348372        if form.is_valid(): # All validation rules pass
    349373            request_obj = form.save()
    350             return HttpResponseRedirect(reverse('membership-thanks', )) # Redirect after POST
     374            message = "Update saved"
    351375
    352376    else:
    353         form = Form_PersonMembershipUpdate(initial=initial, ) # An unbound form
     377        form = Form_PersonMembershipUpdate(initial=initial, instance=update_obj, ) # An unbound form
    354378
    355379    context = {
    356380        'form':form,
     381        'groups':selected_groups,
     382        'message': message,
    357383        'pagename':'groups',
    358384    }
  • asadb/template/membership/confirm.html

    r3087933 rc297267  
    66<h2>Membership update</h2>
    77
     8{% if message %}
     9<div class='messagebox infobox'>
     10<p>{{message}}</p>
     11</div>
     12{% endif %}
     13
    814<p>
    915The ASA is attempting to verify that all currently recognized groups are active
     
    1218
    1319<p>
    14 Please select below the groups that you consider yourself a member of. (If you
    15 prefer, you can submit this form whenever one of your groups' leaders asks you
    16 to. Submitting again will not erase previous submissions.)
     20Please select below the groups that you consider yourself a member of. If you
     21come back to this form again, you'll be able to see all the groups you
     22previously submitted, and add new groups. However, you should be careful not to
     23deselect any groups.
    1724</p>
    1825
     
    2532</form>
    2633
     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
    2743{% endblock %}
Note: See TracChangeset for help on using the changeset viewer.