Parcourir la source

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

master
Dirk Alders il y a 4 ans
Parent
révision
9da7e60a13
4 fichiers modifiés avec 36 ajouts et 33 suppressions
  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 Voir le fichier

@@ -25,34 +25,28 @@ DATA_TYPE_ITEM = 'item'
25 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 28
 def suspend_public():
39
-    return __get_settings__().suspend_puplic
29
+    return settings.SUSPEND_PUBLIC
40 30
 
41 31
 
42 32
 def show_image():
43
-    return __get_settings__().show_image
33
+    return settings.SHOW_IMAGE
44 34
 
45 35
 
46 36
 def show_video():
47
-    return __get_settings__().show_video
37
+    return settings.SHOW_VIDEO
48 38
 
49 39
 
50 40
 def show_audio():
51
-    return __get_settings__().show_audio
41
+    return settings.SHOW_AUDIO
52 42
 
53 43
 
54 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 52
 def dict2args(d):

+ 1
- 2
admin.py Voir le fichier

@@ -1,5 +1,5 @@
1 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 5
 class ItemAdmin(admin.ModelAdmin):
@@ -106,4 +106,3 @@ class TagAdmin(admin.ModelAdmin):
106 106
 
107 107
 admin.site.register(Item, ItemAdmin)
108 108
 admin.site.register(Tag, TagAdmin)
109
-admin.site.register(Setting)

+ 16
- 0
migrations/0004_delete_setting.py Voir le fichier

@@ -0,0 +1,16 @@
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 Voir le fichier

@@ -9,7 +9,6 @@ import logging
9 9
 import media
10 10
 import os
11 11
 import pygal
12
-import subprocess
13 12
 import time
14 13
 
15 14
 DEBUG = False
@@ -306,11 +305,14 @@ class Item(models.Model):
306 305
             return user in parent.modify_access.all()
307 306
 
308 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 317
     def sorted_itemlist(self):
316 318
         if self.type == TYPE_FOLDER:
@@ -357,7 +359,7 @@ class Item(models.Model):
357 359
 
358 360
     def current_settings(self):
359 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 363
         return self.__current_settings__
362 364
 
363 365
     def __cache_update_needed__(self):
@@ -413,7 +415,7 @@ class Item(models.Model):
413 415
                         self.num_videos_c += 1
414 416
         # sorted item list
415 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 419
         self.sil_c = json.dumps([i.rel_path for i in sil], indent=4)
418 420
         # datetime
419 421
         if len(sil) > 0:
@@ -466,11 +468,3 @@ class Tag(models.Model):
466 468
         """the url to the Django admin interface for the model instance"""
467 469
         info = (self._meta.app_label, self._meta.model_name)
468 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)

Chargement…
Annuler
Enregistrer