Permalink
Browse files

Add new action + view for editing start and end dates in bulk

  • Loading branch information...
Osmose committed Jun 17, 2011
1 parent 7ba7981 commit 2fa4807b4d93eae5f9af819cf66c9010778ac69c
View
@@ -3,7 +3,7 @@
from django import forms
from django.contrib import admin, messages
from django.db import models
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseRedirect
from django.template.loader import render_to_string
from django.utils.encoding import smart_unicode
from django.utils.safestring import mark_safe
@@ -74,6 +74,15 @@ def enable_selected_snippets(modeladmin, request, queryset):
enable_selected_snippets.short_description = "Enable selected snippets"
+def bulk_edit_dates(modeladmin, request, queryset):
+ selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
+ return HttpResponseRedirect('/admin/bulkDateChange?ids=%s' %
+ ','.join(selected))
+
+bulk_edit_dates.short_description = "Edit start and end dates of selected " \
+ "snippets"
+
+
class ClientMatchRuleAdmin(admin.ModelAdmin):
change_list_template = 'smuggler/change_list.html'
@@ -127,6 +136,7 @@ class SnippetAdmin(admin.ModelAdmin):
dump_selected_snippets,
disable_selected_snippets,
enable_selected_snippets,
+ bulk_edit_dates,
]
dump_name = 'snippets'
View
@@ -0,0 +1,11 @@
+from django.forms import *
+
+class BulkDateForm(Form):
+ start_date = DateTimeField(label='Start Date',
+ widget=DateInput(attrs={'class':'datetime'}),
+ required=False)
+ end_date = DateTimeField(label='End Date',
+ widget=DateInput(attrs={'class':'datetime'}),
+ required=False)
+ ids = CharField(required=True,
+ widget=widgets.HiddenInput())
@@ -0,0 +1,22 @@
+{% extends 'admin/base_site.html' %}
+
+{% block extrahead %}
+<link rel="stylesheet" type="text/css" href="/media/css/forms.css" />
+<link rel="stylesheet" type="text/css" href="/site_media/jquery-ui-1.8.13.custom.css" />
+<link rel="stylesheet" type="text/css" href="/site_media/jquery-ui-timepicker-addon.css" />
+<script type="text/javascript" src="/site_media/jquery-1.6.1.min.js"></script>
+<script type="text/javascript" src="/site_media/jquery-ui-1.8.13.custom.min.js"></script>
+<script type="text/javascript" src="/site_media/jquery-ui-timepicker-addon.js"></script>
+<script type="text/javascript" src="/site_media/adminBulkDateChange.js"></script>
+{% endblock %}
+
+{% block content %}
+<form action="{% url homesnippets.views.admin_bulk_date_change %}" method="post">{% csrf_token %}
+ <fieldset class="module aligned">
+ {{ form.as_p }}
+ </fieldset>
+ <div class="submit-row">
+ <input type="submit" value="Change" class="default" />
+ </div>
+</form>
+{% endblock %}
View
@@ -1,18 +1,20 @@
"""
Home snippets URL patterns
"""
-from django.conf.urls.defaults import *
-from django.views.generic.simple import direct_to_template
+from django.conf.urls.defaults import patterns, url
urlpatterns = patterns("homesnippets.views",
# browser/components/nsBrowserContentHandler.js:911: const SNIPPETS_URL = "http://snippets.mozilla.com/" + STARTPAGE_VERSION + "/%NAME%/%VERSION%/%APPBUILDID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/";
- url(r'^(?P<startpage_version>[^/]+)/(?P<name>[^/]+)/(?P<version>[^/]+)/(?P<appbuildid>[^/]+)/(?P<build_target>[^/]+)/(?P<locale>[^/]+)/(?P<channel>[^/]+)/(?P<os_version>[^/]+)/(?P<distribution>[^/]+)/(?P<distribution_version>[^/]+)/$',
- 'view_snippets', name='view_snippets', kwargs={'preview':False}),
+ url(r'^(?P<startpage_version>[^/]+)/(?P<name>[^/]+)/(?P<version>[^/]+)/(?P<appbuildid>[^/]+)/(?P<build_target>[^/]+)/(?P<locale>[^/]+)/(?P<channel>[^/]+)/(?P<os_version>[^/]+)/(?P<distribution>[^/]+)/(?P<distribution_version>[^/]+)/$',
+ 'view_snippets', name='view_snippets', kwargs={'preview': False}),
- url(r'^preview/(?P<startpage_version>[^/]+)/(?P<name>[^/]+)/(?P<version>[^/]+)/(?P<appbuildid>[^/]+)/(?P<build_target>[^/]+)/(?P<locale>[^/]+)/(?P<channel>[^/]+)/(?P<os_version>[^/]+)/(?P<distribution>[^/]+)/(?P<distribution_version>[^/]+)/$',
- 'view_snippets', name='preview_snippets', kwargs={'preview':True}),
+ url(r'^preview/(?P<startpage_version>[^/]+)/(?P<name>[^/]+)/(?P<version>[^/]+)/(?P<appbuildid>[^/]+)/(?P<build_target>[^/]+)/(?P<locale>[^/]+)/(?P<channel>[^/]+)/(?P<os_version>[^/]+)/(?P<distribution>[^/]+)/(?P<distribution_version>[^/]+)/$',
+ 'view_snippets', name='preview_snippets', kwargs={'preview': True}),
url(r"^base64encode/(?P<url>.+)$", "base64_encode", name="base64_encode"),
+ url(r"^admin/bulkDateChange$",
+ "admin_bulk_date_change",
+ name="admin_bulk_date_change"),
url(r"^$", "index", name="index"),
)
View
@@ -8,12 +8,13 @@
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
-from django.http import HttpResponse, Http404
+from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.views.decorators.cache import cache_control
from homesnippets.models import Snippet
+from homesnippets.forms import BulkDateForm
HTTP_MAX_AGE = getattr(settings, 'SNIPPET_HTTP_MAX_AGE', 1)
@@ -90,3 +91,26 @@ def base64_encode(request, **kwargs):
return HttpResponse(json.dumps({'img': base64_str}),
mimetype='applications/json')
+
+
+@staff_member_required
+def admin_bulk_date_change(request, **kwargs):
+ """Show a custom form to bulk-change snippet start and end dates"""
+
+ if request.method == 'POST':
+ form = BulkDateForm(request.POST)
+ if form.is_valid():
+ start_date = form.cleaned_data['start_date']
+ end_date = form.cleaned_data['end_date']
+
+ snippet_ids = form.cleaned_data['ids'].split(',')
+ snippets = Snippet.objects.filter(id__in=snippet_ids)
+ snippets.update(pub_start=start_date, pub_end=end_date)
+
+ return HttpResponseRedirect('/admin/homesnippets/snippet/')
+ else:
+ form = BulkDateForm(initial=request.GET)
+
+ return render_to_response('adminBulkDateChange.html',
+ {'form': form},
+ context_instance=RequestContext(request))
@@ -0,0 +1,3 @@
+jQuery(function($) {
+ $("input.datetime").datetimepicker();
+});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 2fa4807

Please sign in to comment.