Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added interface to one-off point awards

  • Loading branch information...
commit b97b83e56a48e5e0da872865dc4d4b347bb6f79d 1 parent 8ba06ff
@brosner brosner authored
View
3  MANIFEST.in
@@ -1 +1,2 @@
-include README.rst
+include README.rst
+recursive-include agon/templates *.html
View
49 agon/admin.py
@@ -1,10 +1,16 @@
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+from django.utils.functional import update_wrapper
+
from django.contrib import admin
+from django.contrib.admin import helpers
+from agon.forms import OneOffPointAwardForm
from agon.models import PointValue, AwardedPointValue
class AwardedPointValueAdmin(admin.ModelAdmin):
- list_display = ["pk", "reason", "target", "points"]
+ list_display = ["pk", "reason_display", "target", "points"]
fields = ["target_user", "value", "timestamp"]
def target(self, obj):
@@ -13,7 +19,7 @@ def target(self, obj):
else:
return obj.target_object
- def reason(self, obj):
+ def reason_display(self, obj):
if obj.value_id:
return obj.value.key
else:
@@ -21,6 +27,45 @@ def reason(self, obj):
return obj.reason
else:
return None
+ reason_display.short_description = "reason"
+
+ def get_urls(self):
+ from django.conf.urls.defaults import patterns, url
+
+ urlpatterns = super(AwardedPointValueAdmin, self).get_urls()
+
+ def wrap(view):
+ def wrapper(*args, **kwargs):
+ return self.admin_site.admin_view(view)(*args, **kwargs)
+ return update_wrapper(wrapper, view)
+
+ info = self.model._meta.app_label, self.model._meta.module_name
+
+ return patterns("",
+ url(r"^one_off_points/$",
+ wrap(self.one_off_points),
+ name="%s_%s_one_off_points" % info
+ )
+ ) + urlpatterns
+
+ def one_off_points(self, request):
+ if request.method == "POST":
+ form = OneOffPointAwardForm(request.POST)
+ if form.is_valid():
+ form.award()
+ else:
+ form = OneOffPointAwardForm()
+ form = helpers.AdminForm(
+ form=form,
+ fieldsets=[(None, {"fields": form.base_fields.keys()})],
+ prepopulated_fields={},
+ model_admin=self
+ )
+ ctx = {
+ "form": form,
+ }
+ ctx = RequestContext(request, ctx)
+ return render_to_response("agon/one_off_points.html", ctx)
admin.site.register(AwardedPointValue, AwardedPointValueAdmin)
View
13 agon/forms.py
@@ -0,0 +1,13 @@
+from django import forms
+
+from django.contrib.auth.models import User
+
+from agon.models import award_points
+
+
+class OneOffPointAwardForm(forms.Form):
+ user = forms.ModelChoiceField(User.objects.filter(is_active=True))
+ points = forms.IntegerField()
+
+ def award(self):
+ award_points(self.cleaned_data["user"], self.cleaned_data["points"])
View
22 agon/templates/agon/one_off_points.html
@@ -0,0 +1,22 @@
+{% extends "admin/base_site.html" %}
+
+{% load admin_modify adminmedia %}
+
+{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />{% endblock %}
+
+{% block content %}
+<div id="content-main">
+ <h1>Issue one-off point rewards</h1>
+
+ <form method="POST" action="">
+ {% csrf_token %}
+ {% for fieldset in form %}
+ {% include "admin/includes/fieldset.html" %}
+ {% endfor %}
+
+ <div class="submit-row">
+ <input type="submit" value="Award" class="default" />
+ </div>
+ </form>
+</div>
+{% endblock %}
Please sign in to comment.
Something went wrong with that request. Please try again.