|
@@ -3,6 +3,25 @@ from . import available_themes, default_theme
|
3
|
3
|
from PIL import Image
|
4
|
4
|
|
5
|
5
|
|
|
6
|
+def GetSettings():
|
|
7
|
+ s = Setting.objects.filter(id=1).first()
|
|
8
|
+ if s is None:
|
|
9
|
+ s = Setting(id=1)
|
|
10
|
+ s.save()
|
|
11
|
+ return s
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+def SettingExist(data):
|
|
15
|
+ s = GetSettings()
|
|
16
|
+ if data['page_theme'] == s.page_theme and data['page_title'] == s.page_title and data['page_image'] == s.page_image.name:
|
|
17
|
+ if s.page_image.name:
|
|
18
|
+ return data['page_image_data'] == s.page_image.open().read().hex()
|
|
19
|
+ else:
|
|
20
|
+ return True
|
|
21
|
+ else:
|
|
22
|
+ return False
|
|
23
|
+
|
|
24
|
+
|
6
|
25
|
class Setting(models.Model):
|
7
|
26
|
page_image = models.ImageField(
|
8
|
27
|
upload_to='theme',
|
|
@@ -24,6 +43,36 @@ class Setting(models.Model):
|
24
|
43
|
img.thumbnail(output_size)
|
25
|
44
|
img.save(self.page_image.path)
|
26
|
45
|
|
|
46
|
+ def export_data(self):
|
|
47
|
+ rv = {}
|
|
48
|
+ rv['page_image'] = self.page_image.name
|
|
49
|
+ rv['page_image_data'] = self.page_image.open().read().hex()
|
|
50
|
+ rv['page_theme'] = self.page_theme
|
|
51
|
+ rv['page_title'] = self.page_title
|
|
52
|
+ return rv
|
|
53
|
+
|
|
54
|
+ def import_data(self, data):
|
|
55
|
+ self.page_title = data['page_title']
|
|
56
|
+ self.page_theme = data['page_theme']
|
|
57
|
+ self.page_image.name = data['page_image']
|
|
58
|
+ if self.page_image.name:
|
|
59
|
+ with self.page_image.open('wb') as pi:
|
|
60
|
+ pi.write(bytes.fromhex(data['page_image_data']))
|
|
61
|
+ self.save()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+def BottomBarExist(data):
|
|
65
|
+ name = data.get('name', '')
|
|
66
|
+ icon_name = data.get('icon_name', '')
|
|
67
|
+ icon_data = data.get('icon_data')
|
|
68
|
+ url = data.get('url', '')
|
|
69
|
+ left = data.get('left')
|
|
70
|
+ sequence_number = data.get('sequence_number')
|
|
71
|
+ for bb_entry in BottomBar.objects.filter(name=name, icon=icon_name, url=url, left=left, sequence_number=sequence_number):
|
|
72
|
+ if icon_name == '' or icon_data == bb_entry.icon.open().read().hex():
|
|
73
|
+ return True
|
|
74
|
+ return False
|
|
75
|
+
|
27
|
76
|
|
28
|
77
|
class BottomBar(models.Model):
|
29
|
78
|
name = models.CharField(max_length=64, blank=True)
|
|
@@ -40,3 +89,27 @@ class BottomBar(models.Model):
|
40
|
89
|
output_size = (int(img.width * 40 / img.height), 40)
|
41
|
90
|
img.thumbnail(output_size)
|
42
|
91
|
img.save(self.icon.path)
|
|
92
|
+
|
|
93
|
+ def export_data(self):
|
|
94
|
+ rv = {}
|
|
95
|
+ rv['name'] = self.name
|
|
96
|
+ rv['icon_name'] = self.icon.name
|
|
97
|
+ if self.icon.name != '':
|
|
98
|
+ rv['icon_data'] = self.icon.open().read().hex()
|
|
99
|
+ else:
|
|
100
|
+ rv['icon_data'] = None
|
|
101
|
+ rv['url'] = self.url
|
|
102
|
+ rv['left'] = self.left
|
|
103
|
+ rv['sequence_number'] = self.sequence_number
|
|
104
|
+ return rv
|
|
105
|
+
|
|
106
|
+ def import_data(self, data):
|
|
107
|
+ self.name = data['name']
|
|
108
|
+ self.icon.name = data['icon_name']
|
|
109
|
+ if self.icon.name:
|
|
110
|
+ with self.icon.open('wb') as ih:
|
|
111
|
+ ih.write(bytes.fromhex(data['icon_data']))
|
|
112
|
+ self.url = data['url']
|
|
113
|
+ self.left = data['left']
|
|
114
|
+ self.sequence_number = data['sequence_number']
|
|
115
|
+ self.save()
|