Parcourir la source

Import and Export for Models added

master
Dirk Alders il y a 4 ans
Parent
révision
8cf64464ba
1 fichiers modifiés avec 22 ajouts et 0 suppressions
  1. 22
    0
      models.py

+ 22
- 0
models.py Voir le fichier

@@ -15,9 +15,31 @@ def get_userprofile(user):
15 15
     return profile
16 16
 
17 17
 
18
+def UserprofilerExist(username, data):
19
+    try:
20
+        profile = UserProfile.objects.get(user__username=username)
21
+    except UserProfile.DoesNotExist:
22
+        return False
23
+    return profile.timezone == data['timezone'] and profile.language_code == data['language_code']
24
+
25
+
18 26
 # USERPROFILE Model
19 27
 #
20 28
 class UserProfile(models.Model):
21 29
     user = models.OneToOneField(User, unique=True, on_delete=models.CASCADE)
22 30
     timezone = models.CharField(max_length=150, default='UTC', choices=[(t, t) for t in pytz.common_timezones])
23 31
     language_code = models.CharField(max_length=150, default='en', choices=settings.LANGUAGES)
32
+
33
+    def export_key(self):
34
+        return self.user.username
35
+
36
+    def export_data(self):
37
+        rv = {}
38
+        rv['timezone'] = self.timezone
39
+        rv['language_code'] = self.language_code
40
+        return rv
41
+
42
+    def import_data(self, data):
43
+        self.timezone = data['timezone']
44
+        self.language_code = data['language_code']
45
+        self.save()

Chargement…
Annuler
Enregistrer