]> git.parisson.com Git - teleforma.git/commitdiff
add jqchat mess move script
authorGuillaume Pellerin <yomguy@parisson.com>
Sat, 13 Jul 2013 19:26:09 +0000 (21:26 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Sat, 13 Jul 2013 19:26:09 +0000 (21:26 +0200)
teleforma/management/commands/teleforma-move-jqchat-messages.py [new file with mode: 0644]

diff --git a/teleforma/management/commands/teleforma-move-jqchat-messages.py b/teleforma/management/commands/teleforma-move-jqchat-messages.py
new file mode 100644 (file)
index 0000000..4821539
--- /dev/null
@@ -0,0 +1,28 @@
+from optparse import make_option
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from jqchat.models import *
+import datetime
+
+
+class Command(BaseCommand):
+    help = "Move some jqchat messages from one room to another past to a given date"
+    args = "from_room to_room year month day"
+
+    def handle(self, *args, **options):
+        day = args[-1]
+        month = args[-2]
+        year = args[-3]
+        to_room_name = args[-4]
+        from_room_name = args[-5]
+
+        date = datetime.datetime(int(year), int(month), int(day))
+        to_room = Room.objects.get(name=to_room_name)
+        from_room = Room.objects.get(name=from_room_name)
+
+        messages = Message.objects.filter(room=from_room, created__gte=date)
+        for message in messages:
+            message.room = to_room
+            message.save()
+