Permalink
Browse files

Added batteries-included user riff correction. Fixes #8.

  • Loading branch information...
1 parent a3d596a commit 5e9e7fc6e3d27b4695db4e16b401eedda4c8e436 @melinath melinath committed Apr 5, 2013
Showing with 73 additions and 1 deletion.
  1. +52 −0 djam/batteries.py
  2. +5 −1 djam/riffs/admin.py
  3. +16 −0 djam/templates/djam/models/auth/user/password-change.html
View
@@ -0,0 +1,52 @@
+from django.contrib.auth.forms import AdminPasswordChangeForm
+from django.contrib.auth.models import User
+from django.conf.urls import patterns, url
+from django.views.generic import UpdateView
+
+from djam.riffs.models import ModelRiff
+from djam.views.models import ModelRiffMixin
+
+
+class UserPasswordView(ModelRiffMixin, UpdateView):
+ form_class = AdminPasswordChangeForm
+ template_name = 'djam/models/auth/user/password-change.html'
+
+ def get_success_url(self):
+ return self.riff.reverse('update', pk=self.object.pk)
+
+ def has_permission(self, request):
+ return self.riff.has_change_permission(request)
+
+ def get_form_kwargs(self):
+ kwargs = super(UserPasswordView, self).get_form_kwargs()
+ kwargs['user'] = kwargs.pop('instance')
+ return kwargs
+
+ def get_crumbs(self):
+ crumbs = super(UserPasswordView, self).get_crumbs()
+ crumbs += [
+ (self.riff.reverse('update', pk=self.object.pk),
+ unicode(self.object)),
+ (None, 'Change password'),
+ ]
+ return crumbs
+
+
+class UserRiff(ModelRiff):
+ model = User
+
+ def get_password_change_kwargs(self):
+ return self.get_view_kwargs()
+
+ def get_extra_urls(self):
+ urlpatterns = super(UserRiff, self).get_extra_urls()
+ urlpatterns += patterns('',
+ url(r'^(?P<pk>\w+)/password/',
+ UserPasswordView.as_view(**self.get_password_change_kwargs()),
+ name='password-change'),
+ )
+ return urlpatterns
+
+
+def register_batteries(riff):
+ riff.register(UserRiff)
View
@@ -36,11 +36,15 @@ def register_model(self, model):
riff_class = type(class_name, (ModelRiff,), {'model': model})
self.register(riff_class)
- def autodiscover(self):
+ def autodiscover(self, with_batteries=True):
if not self._autodiscovered:
from django.contrib.admin import autodiscover, site
autodiscover()
+ if with_batteries:
+ from djam.batteries import register_batteries
+ register_batteries(self)
+
for model in site._registry:
try:
self.register_model(model)
@@ -0,0 +1,16 @@
+{% extends "djam/__base.html" %}
+{% load i18n floppyforms %}
+
+{% block body_classes %}{{ block.super }} password-change{% endblock %}
+
+{% block main %}
+ <div class="row">
+ <form method='post' action='{{ request.path }}' class="form-horizontal">
+ {% csrf_token %}
+ {% form form using "floppyforms/layouts/bootstrap-horizontal.html" %}
+ <div class="form-actions">
+ <button type="submit" class="btn btn-success">{% trans "Change Password" %}</button>
+ </div>
+ </form>
+ </div>
+{% endblock %}

0 comments on commit 5e9e7fc

Please sign in to comment.