Browse files

Add actions to disable/enable snippets in bulk; hide preview-only che…

…ckbox, since it's mostly misunderstood and not used; tweaks to import management command
  • Loading branch information...
1 parent 60b1de5 commit 6ca451ab1fd6cb34aff153a451532b484fe8327a @lmorchard lmorchard committed May 12, 2011
Showing with 35 additions and 5 deletions.
  1. +30 −4 apps/homesnippets/admin.py
  2. +3 −1 apps/homesnippets/management/commands/importfrombug.py
  3. +2 −0 requirements/compiled.txt
View
34 apps/homesnippets/admin.py
@@ -1,13 +1,14 @@
import os
from datetime import datetime
-from django.contrib import admin
+from django.contrib import admin, messages
from django import forms
from django.db import models
from django.db.models import get_app, get_apps, get_model, get_models
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
+
from smuggler.settings import SMUGGLER_FORMAT, SMUGGLER_FIXTURE_DIR
from smuggler.utils import (get_excluded_models_set, get_file_list,
save_uploaded_file_on_disk, serialize_to_response,
@@ -49,6 +50,27 @@ def dump_selected_snippets(modeladmin, request, queryset):
dump_selected_snippets.short_description = "Dump selected snippets (and client match rules) as JSON data"
+def disable_selected_snippets(modeladmin, request, queryset):
+ cnt = 0
+ for snippet in queryset.all():
+ snippet.disabled = True
+ snippet.save()
+ cnt += 1
+ messages.add_message(request, messages.INFO,
+ ('%(cnt)d snippet(s) disabled') % dict(cnt=cnt))
+
+disable_selected_snippets.short_description = "Disable selected snippets"
+
+def enable_selected_snippets(modeladmin, request, queryset):
+ cnt = 0
+ for snippet in queryset.all():
+ snippet.disabled = False
+ snippet.save()
+ cnt += 1
+ messages.add_message(request, messages.INFO,
+ ('%(cnt)d snippet(s) enabled') % dict(cnt=cnt))
+
+enable_selected_snippets.short_description = "Enable selected snippets"
class ClientMatchRuleAdmin(admin.ModelAdmin):
change_list_template = 'smuggler/change_list.html'
@@ -83,7 +105,11 @@ class ClientMatchRuleAdmin(admin.ModelAdmin):
class SnippetAdmin(admin.ModelAdmin):
change_list_template = 'smuggler/change_list.html'
- actions = [ dump_selected_snippets ]
+ actions = [
+ dump_selected_snippets,
+ disable_selected_snippets,
+ enable_selected_snippets,
+ ]
dump_name = 'snippets'
save_on_top = True
@@ -111,7 +137,7 @@ class SnippetAdmin(admin.ModelAdmin):
list_display = (
'name',
- 'preview', 'disabled',
+ 'disabled',
'priority', 'pub_start', 'pub_end',
'modified'
)
@@ -121,7 +147,7 @@ class SnippetAdmin(admin.ModelAdmin):
)
list_editable = (
- 'preview', 'disabled', 'priority',
+ 'disabled', 'priority',
'pub_start', 'pub_end',
)
View
4 apps/homesnippets/management/commands/importfrombug.py
@@ -164,7 +164,7 @@ def update_snippets(self):
idx += 1
if english not in self.import_manifest['snippets_content']:
- print "\t%s BAD ENGLISH: %s" % (idx, english)
+ print "\t%s UNEXPECTED ENGLISH: %s" % (idx, english)
continue
meta = self.import_manifest['snippets_content'][english]
@@ -174,6 +174,8 @@ def update_snippets(self):
meta.update(dict(
bug_id = self.bug_id,
attachment_description = attachment['description'],
+ locale_code = locale['code'],
+ locale_name = locale['name'],
english = english,
translated = translated % cgi.escape(meta['placeholder']),
))
View
2 requirements/compiled.txt
@@ -0,0 +1,2 @@
+# Compiled packages, sometimes better installed as OS packages
+mysql-python

0 comments on commit 6ca451a

Please sign in to comment.