f867189ff6b55944d418681bc331d9ef06cf2022
[redakcja.git] / apps / explorer / models.py
1 import os
2
3 from django.db import models
4 from django.contrib.auth.models import User
5 from django.conf import settings
6 from django.utils.translation import gettext_lazy as _
7
8
9 class PanelSettings(models.Model):
10     user = models.ForeignKey(User)
11     left_panel = models.CharField(blank=True,  max_length=80)
12     right_panel = models.CharField(blank=True,  max_length=80)
13
14     class Meta:
15         ordering = ['user__name']
16         verbose_name, verbose_name_plural = _("panel settings"), _("panel settings")
17
18     def __unicode__(self):
19         return u"Panel settings for %s" % self.user.name
20
21
22 def get_image_folders():
23     return sorted(fn for fn in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR)) if not fn.startswith('.'))
24
25
26 def get_images_from_folder(folder):
27     return sorted(settings.MEDIA_URL + settings.IMAGE_DIR + '/' + folder + '/' + fn for fn 
28             in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, folder))
29             if not fn.startswith('.'))
30
31 def user_branch(user):
32     return 'personal_'+user.username