Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed old migration command

git-svn-id: http://django-notification.googlecode.com/svn/trunk@108 590c3fc9-4838-0410-bb95-17a0c9b37ca9
  • Loading branch information...
commit 010a269f22c3450075ae76aec60ea9ebb3e7606d 1 parent b3d68f2
@jtauber jtauber authored
Showing with 0 additions and 78 deletions.
  1. +0 −78 notification/management/commands/upgrade_notices.py
View
78 notification/management/commands/upgrade_notices.py
@@ -1,78 +0,0 @@
-from django.core.management.base import NoArgsCommand
-from django.db.models import get_model
-from django.utils.translation import ugettext
-
-from notification.models import Notice
-
-# converts pre r70 notices to new approach
-
-def decode_object(ref):
- decoded = ref.split(".")
- if len(decoded) == 4:
- app, name, pk, msgid = decoded
- return get_model(app, name).objects.get(pk=pk), msgid
- app, name, pk = decoded
- return get_model(app, name).objects.get(pk=pk), None
-
-class FormatException(Exception):
- pass
-
-def decode_message(message, decoder):
- out = []
- objects = []
- mapping = {}
- in_field = False
- prev = 0
- for index, ch in enumerate(message):
- if not in_field:
- if ch == '{':
- in_field = True
- if prev != index:
- out.append(message[prev:index])
- prev = index
- elif ch == '}':
- raise FormatException("unmatched }")
- elif in_field:
- if ch == '{':
- raise FormatException("{ inside {}")
- elif ch == '}':
- in_field = False
- obj, msgid = decoder(message[prev+1:index])
- if msgid is None:
- objects.append(obj)
- out.append("%s")
- else:
- mapping[msgid] = obj
- out.append("%("+msgid+")s")
- prev = index + 1
- if in_field:
- raise FormatException("unmatched {")
- if prev <= index:
- out.append(message[prev:index+1])
- result = "".join(out)
- if mapping:
- args = mapping
- else:
- args = tuple(objects)
- return ugettext(result) % args
-
-def message_to_html(message):
- def decoder(ref):
- obj, msgid = decode_object(ref)
- if hasattr(obj, "get_absolute_url"):
- return u"""<a href="%s">%s</a>""" % (obj.get_absolute_url(), unicode(obj)), msgid
- else:
- return unicode(obj), msgid
- return decode_message(message, decoder)
-
-
-class Command(NoArgsCommand):
- help = 'Upgrade notices from old style approach.'
-
- def handle_noargs(self, **options):
- # wrapping in list() is required for sqlite, see http://code.djangoproject.com/ticket/7411
- for notice in list(Notice.objects.all()):
- message = notice.message
- notice.message = message_to_html(message)
- notice.save()
-

0 comments on commit 010a269

Please sign in to comment.
Something went wrong with that request. Please try again.