annotate contests/admin.py @ 693:ad69236e8501

For issue #52, update many 3rd party Javascript libraries. Updated to jquery 1.10.2, jquery ui 1.10.3. This broke a lot of stuff. - Found a newer version of the jquery cycle all plugin (3.0.3). - Updated JPlayer to 2.4.0. - Updated to MarkItUp 1.1.14. This also required me to add multiline attributes set to true on various buttons in the markdown set. - As per a stackoverflow post, added some code to get multiline titles in a jQuery UI dialog. They removed that functionality but allow you to put it back. Tweaked the MarkItUp preview CSS to show blockquotes in italic. Did not update TinyMCE at this time. I'm not using the JQuery version and this version appears to work ok for now. What I should do is make a repo for MarkItUp and do a vendor branch thing so I don't have to futz around diffing directories to figure out if I'll lose changes when I update.
author Brian Neal <bgneal@gmail.com>
date Wed, 04 Sep 2013 19:55:20 -0500
parents ee87ea74d46b
children 5977b43499f7
rev   line source
bgneal@540 1 """
bgneal@540 2 Admin definitions for the contest application.
bgneal@540 3
bgneal@540 4 """
bgneal@540 5 from django.contrib import admin
bgneal@540 6 from django.conf import settings
bgneal@540 7
bgneal@540 8 from contests.models import Contest
bgneal@540 9
bgneal@540 10
bgneal@540 11 class ContestAdmin(admin.ModelAdmin):
bgneal@540 12 list_display = ['title', 'is_public', 'creation_date', 'end_date',
bgneal@540 13 'contestant_count', 'winner']
bgneal@540 14 list_editable = ['is_public']
bgneal@540 15 date_hierarchy = 'creation_date'
bgneal@540 16 search_fields = ['title', 'description']
bgneal@540 17 prepopulated_fields = {'slug': ['title']}
bgneal@540 18 raw_id_fields = ['winner', 'contestants']
bgneal@540 19 actions = ['pick_winner']
bgneal@540 20
bgneal@540 21 class Media:
bgneal@540 22 js = (['js/contests/contests_admin.js'] +
bgneal@540 23 settings.GPP_THIRD_PARTY_JS['tiny_mce'])
bgneal@540 24
bgneal@540 25 def contestant_count(self, obj):
bgneal@540 26 return obj.contestants.count()
bgneal@540 27 contestant_count.short_description = '# Entries'
bgneal@540 28
bgneal@540 29 def pick_winner(self, request, qs):
bgneal@540 30 """
bgneal@540 31 Picks a winner on the contests selected by the admin. Note that for
bgneal@540 32 safety reasons, we only update those contests that don't have winners
bgneal@540 33 already.
bgneal@540 34
bgneal@540 35 """
bgneal@540 36 count = 0
bgneal@540 37 for contest in qs:
bgneal@540 38 if not contest.winner:
bgneal@540 39 contest.pick_winner()
bgneal@540 40 contest.save()
bgneal@540 41 count += 1
bgneal@540 42
bgneal@540 43 self.message_user(request, "%d of %d winners picked" % (count,
bgneal@540 44 qs.count()))
bgneal@540 45
bgneal@540 46 pick_winner.short_description = "Pick winners for selected contests"
bgneal@540 47
bgneal@540 48
bgneal@540 49
bgneal@540 50 admin.site.register(Contest, ContestAdmin)