Browse Source

Add pop/update module settings methods

Denis K 9 years ago
parent
commit
9d6809e4c9
1 changed files with 20 additions and 0 deletions
  1. 20 0
      jet/models.py

+ 20 - 0
jet/models.py

@@ -1,8 +1,10 @@
 from importlib import import_module
+import json
 from django.db import models
 from django.utils import timezone
 from django.utils.encoding import python_2_unicode_compatible
 from django.utils.translation import ugettext_lazy as _
+from jet.utils import DateTimeEncoder
 
 
 @python_2_unicode_compatible
@@ -66,4 +68,22 @@ class UserDashboardModule(models.Model):
         except AttributeError:
             return None
 
+    def pop_settings(self, pop_settings):
+        settings = json.loads(self.settings)
+
+        for setting in pop_settings:
+            if setting in settings:
+                settings.pop(setting)
+
+        self.settings = json.dumps(settings, cls=DateTimeEncoder)
+        self.save()
+
+    def update_settings(self, update_settings):
+        settings = json.loads(self.settings)
+
+        settings.update(update_settings)
+
+        self.settings = json.dumps(settings, cls=DateTimeEncoder)
+        self.save()
+