Преглед на файлове

Configuration moved to config.py, Sort option by name added

master
Dirk Alders преди 4 години
родител
ревизия
9da7e60a13
променени са 4 файла, в които са добавени 36 реда и са изтрити 33 реда
  1. 9
    15
      __init__.py
  2. 1
    2
      admin.py
  3. 16
    0
      migrations/0004_delete_setting.py
  4. 10
    16
      models.py

+ 9
- 15
__init__.py Целия файл

25
 DATA_TYPE_SEARCH = 'search'
25
 DATA_TYPE_SEARCH = 'search'
26
 
26
 
27
 
27
 
28
-def __get_settings__():
29
-    from .models import Setting
30
-    try:
31
-        s = Setting.objects.get(id=1)
32
-    except Setting.DoesNotExist:
33
-        s = Setting(id=1)
34
-        s.save()
35
-    return s
36
-
37
-
38
 def suspend_public():
28
 def suspend_public():
39
-    return __get_settings__().suspend_puplic
29
+    return settings.SUSPEND_PUBLIC
40
 
30
 
41
 
31
 
42
 def show_image():
32
 def show_image():
43
-    return __get_settings__().show_image
33
+    return settings.SHOW_IMAGE
44
 
34
 
45
 
35
 
46
 def show_video():
36
 def show_video():
47
-    return __get_settings__().show_video
37
+    return settings.SHOW_VIDEO
48
 
38
 
49
 
39
 
50
 def show_audio():
40
 def show_audio():
51
-    return __get_settings__().show_audio
41
+    return settings.SHOW_AUDIO
52
 
42
 
53
 
43
 
54
 def show_other():
44
 def show_other():
55
-    return __get_settings__().show_other
45
+    return settings.SHOW_OTHER
46
+
47
+
48
+def sort_by_date():
49
+    return settings.SORT_BY_DATE
56
 
50
 
57
 
51
 
58
 def dict2args(d):
52
 def dict2args(d):

+ 1
- 2
admin.py Целия файл

1
 from django.contrib import admin
1
 from django.contrib import admin
2
-from .models import Item, Tag, Setting, TYPE_AUDIO, TYPE_FOLDER, TYPE_IMAGE, TYPE_VIDEO
2
+from .models import Item, Tag, TYPE_AUDIO, TYPE_FOLDER, TYPE_IMAGE, TYPE_VIDEO
3
 
3
 
4
 
4
 
5
 class ItemAdmin(admin.ModelAdmin):
5
 class ItemAdmin(admin.ModelAdmin):
106
 
106
 
107
 admin.site.register(Item, ItemAdmin)
107
 admin.site.register(Item, ItemAdmin)
108
 admin.site.register(Tag, TagAdmin)
108
 admin.site.register(Tag, TagAdmin)
109
-admin.site.register(Setting)

+ 16
- 0
migrations/0004_delete_setting.py Целия файл

1
+# Generated by Django 2.2.9 on 2020-01-31 09:37
2
+
3
+from django.db import migrations
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('pygal', '0003_auto_20200130_2203'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.DeleteModel(
14
+            name='Setting',
15
+        ),
16
+    ]

+ 10
- 16
models.py Целия файл

9
 import media
9
 import media
10
 import os
10
 import os
11
 import pygal
11
 import pygal
12
-import subprocess
13
 import time
12
 import time
14
 
13
 
15
 DEBUG = False
14
 DEBUG = False
306
             return user in parent.modify_access.all()
305
             return user in parent.modify_access.all()
307
 
306
 
308
     def sort_string(self):
307
     def sort_string(self):
309
-        try:
310
-            tm = int(self.item_data.datetime.strftime('%s'))
311
-        except AttributeError:
312
-            raise AttributeError('Unable to create a sortstring for %s. Used datetime was: %s' % (str(self), repr(self.item_data.datetime)))
313
-        return '%012d_%s' % (tm, os.path.basename(self.rel_path))
308
+        if pygal.sort_by_date():
309
+            try:
310
+                tm = int(self.item_data.datetime.strftime('%s'))
311
+            except AttributeError:
312
+                raise AttributeError('Unable to create a sortstring for %s. Used datetime was: %s' % (str(self), repr(self.item_data.datetime)))
313
+            return '%012d_%s' % (tm, os.path.basename(self.rel_path))
314
+        else:
315
+            return self.rel_path
314
 
316
 
315
     def sorted_itemlist(self):
317
     def sorted_itemlist(self):
316
         if self.type == TYPE_FOLDER:
318
         if self.type == TYPE_FOLDER:
357
 
359
 
358
     def current_settings(self):
360
     def current_settings(self):
359
         if self.__current_settings__ is None:
361
         if self.__current_settings__ is None:
360
-            self.__current_settings__ = pygal.show_audio() * 1 + pygal.show_image() * 2 + pygal.show_other() * 3 + pygal.show_video() * 4
362
+            self.__current_settings__ = pygal.show_audio() * 1 + pygal.show_image() * 2 + pygal.show_other() * 4 + pygal.show_video() * 8 + pygal.sort_by_date() * 16
361
         return self.__current_settings__
363
         return self.__current_settings__
362
 
364
 
363
     def __cache_update_needed__(self):
365
     def __cache_update_needed__(self):
413
                         self.num_videos_c += 1
415
                         self.num_videos_c += 1
414
         # sorted item list
416
         # sorted item list
415
                     sil.append(sub_item)
417
                     sil.append(sub_item)
416
-        sil.sort(key=lambda entry: entry.sort_string(), reverse=True)
418
+        sil.sort(key=lambda entry: entry.sort_string(), reverse=pygal.sort_by_date())
417
         self.sil_c = json.dumps([i.rel_path for i in sil], indent=4)
419
         self.sil_c = json.dumps([i.rel_path for i in sil], indent=4)
418
         # datetime
420
         # datetime
419
         if len(sil) > 0:
421
         if len(sil) > 0:
466
         """the url to the Django admin interface for the model instance"""
468
         """the url to the Django admin interface for the model instance"""
467
         info = (self._meta.app_label, self._meta.model_name)
469
         info = (self._meta.app_label, self._meta.model_name)
468
         return reverse('admin:%s_%s_change' % info, args=(self.pk,))
470
         return reverse('admin:%s_%s_change' % info, args=(self.pk,))
469
-
470
-
471
-class Setting(models.Model):
472
-    suspend_puplic = models.BooleanField(default=True)
473
-    show_image = models.BooleanField(default=True)
474
-    show_video = models.BooleanField(default=True)
475
-    show_audio = models.BooleanField(default=False)
476
-    show_other = models.BooleanField(default=False)

Loading…
Отказ
Запис