Skip to content

Commit fe94325

Browse files
authored
Fix code style (#1262)
* fix code style according to Django’s style guide * fix code style according to Django’s style guide * remove empty line Co-authored-by: Jacob Rief <[email protected]>
1 parent 3bbacb0 commit fe94325

File tree

6 files changed

+215
-92
lines changed

6 files changed

+215
-92
lines changed

filer/models/abstract.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,51 @@ class BaseImage(File):
2929
file_type = 'Image'
3030
_icon = "image"
3131

32-
_height = models.FloatField(null=True, blank=True)
33-
_width = models.FloatField(null=True, blank=True)
32+
_height = models.FloatField(
33+
null=True,
34+
blank=True,
35+
)
3436

35-
default_alt_text = models.CharField(_('default alt text'), max_length=255, blank=True, null=True)
36-
default_caption = models.CharField(_('default caption'), max_length=255, blank=True, null=True)
37+
_width = models.FloatField(
38+
null=True,
39+
blank=True,
40+
)
41+
42+
default_alt_text = models.CharField(
43+
_("default alt text"),
44+
max_length=255,
45+
blank=True,
46+
null=True,
47+
)
48+
49+
default_caption = models.CharField(
50+
_("default caption"),
51+
max_length=255,
52+
blank=True,
53+
null=True,
54+
)
55+
56+
subject_location = models.CharField(
57+
_("subject location"),
58+
max_length=64,
59+
blank=True,
60+
default='',
61+
)
3762

38-
subject_location = models.CharField(_('subject location'), max_length=64, blank=True,
39-
default='')
4063
file_ptr = models.OneToOneField(
41-
to='filer.File', parent_link=True,
64+
to='filer.File',
65+
parent_link=True,
4266
related_name='%(app_label)s_%(class)s_file',
4367
on_delete=models.CASCADE,
4468
)
4569

70+
class Meta:
71+
app_label = 'filer'
72+
verbose_name = _("image")
73+
verbose_name_plural = _("images")
74+
abstract = True
75+
default_manager_name = 'objects'
76+
4677
@classmethod
4778
def matches_file_type(cls, iname, ifile, mime_type):
4879
# source: https://www.freeformatter.com/mime-types-list.html
@@ -173,10 +204,3 @@ def easy_thumbnails_thumbnailer(self):
173204
thumbnail_storage=self.file.thumbnail_storage,
174205
thumbnail_basedir=self.file.thumbnail_basedir)
175206
return tn
176-
177-
class Meta:
178-
app_label = 'filer'
179-
verbose_name = _('image')
180-
verbose_name_plural = _('images')
181-
abstract = True
182-
default_manager_name = 'objects'

filer/models/clipboardmodels.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ class Clipboard(models.Model):
1111
verbose_name=_('user'), related_name="filer_clipboards",
1212
on_delete=models.CASCADE,
1313
)
14+
1415
files = models.ManyToManyField(
1516
'File',
1617
verbose_name=_('files'),
1718
related_name="in_clipboards",
1819
through='ClipboardItem',
1920
)
2021

22+
class Meta:
23+
app_label = 'filer'
24+
verbose_name = _("clipboard")
25+
verbose_name_plural = _("clipboards")
26+
2127
def append_file(self, file_obj):
2228
try:
2329
# We have to check if file is already in the clipboard as otherwise polymorphic complains
@@ -31,25 +37,21 @@ def append_file(self, file_obj):
3137
def __str__(self):
3238
return "Clipboard %s of %s" % (self.id, self.user)
3339

34-
class Meta:
35-
app_label = 'filer'
36-
verbose_name = _('clipboard')
37-
verbose_name_plural = _('clipboards')
38-
3940

4041
class ClipboardItem(models.Model):
4142
file = models.ForeignKey(
4243
'File',
43-
verbose_name=_('file'),
44+
verbose_name=_("file"),
4445
on_delete=models.CASCADE,
4546
)
47+
4648
clipboard = models.ForeignKey(
4749
Clipboard,
48-
verbose_name=_('clipboard'),
50+
verbose_name=_("clipboard"),
4951
on_delete=models.CASCADE,
5052
)
5153

5254
class Meta:
5355
app_label = 'filer'
54-
verbose_name = _('clipboard item')
55-
verbose_name_plural = _('clipboard items')
56+
verbose_name = _("clipboard item")
57+
verbose_name_plural = _("clipboard items")

filer/models/filemodels.py

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,56 +49,111 @@ def mimetype_validator(value):
4949

5050
class File(PolymorphicModel, mixins.IconsMixin):
5151
file_type = 'File'
52-
_icon = "file"
52+
_icon = 'file'
5353
_file_data_changed_hint = None
5454

5555
folder = models.ForeignKey(
5656
Folder,
57-
verbose_name=_('folder'),
57+
verbose_name=_("folder"),
5858
related_name='all_files',
5959
null=True,
6060
blank=True,
6161
on_delete=models.CASCADE,
6262
)
63-
file = MultiStorageFileField(_('file'), null=True, blank=True, max_length=255)
64-
_file_size = models.BigIntegerField(_('file size'), null=True, blank=True)
6563

66-
sha1 = models.CharField(_('sha1'), max_length=40, blank=True, default='')
64+
file = MultiStorageFileField(
65+
_("file"),
66+
null=True,
67+
blank=True,
68+
max_length=255,
69+
)
70+
71+
_file_size = models.BigIntegerField(
72+
_("file size"),
73+
null=True,
74+
blank=True,
75+
)
76+
77+
sha1 = models.CharField(
78+
_("sha1"),
79+
max_length=40,
80+
blank=True,
81+
default='',
82+
)
83+
84+
has_all_mandatory_data = models.BooleanField(
85+
_("has all mandatory data"),
86+
default=False,
87+
editable=False,
88+
)
89+
90+
original_filename = models.CharField(
91+
_("original filename"),
92+
max_length=255,
93+
blank=True,
94+
null=True,
95+
)
6796

68-
has_all_mandatory_data = models.BooleanField(_('has all mandatory data'), default=False, editable=False)
97+
name = models.CharField(
98+
max_length=255,
99+
default="",
100+
blank=True,
101+
verbose_name=_("name"),
102+
)
69103

70-
original_filename = models.CharField(_('original filename'), max_length=255, blank=True, null=True)
71-
name = models.CharField(max_length=255, default="", blank=True, verbose_name=_('name'))
72-
description = models.TextField(null=True, blank=True, verbose_name=_('description'))
104+
description = models.TextField(
105+
null=True,
106+
blank=True,
107+
verbose_name=_("description"),
108+
)
73109

74110
owner = models.ForeignKey(
75111
getattr(settings, 'AUTH_USER_MODEL', 'auth.User'),
76112
related_name='owned_%(class)ss',
77113
on_delete=models.SET_NULL,
78114
null=True,
79115
blank=True,
80-
verbose_name=_('owner'),
116+
verbose_name=_("owner"),
81117
)
82118

83-
uploaded_at = models.DateTimeField(_('uploaded at'), auto_now_add=True)
84-
modified_at = models.DateTimeField(_('modified at'), auto_now=True)
119+
uploaded_at = models.DateTimeField(
120+
_("uploaded at"),
121+
auto_now_add=True,
122+
)
123+
124+
modified_at = models.DateTimeField(
125+
_("modified at"),
126+
auto_now=True,
127+
)
85128

86129
is_public = models.BooleanField(
87130
default=is_public_default,
88-
verbose_name=_('Permissions disabled'),
89-
help_text=_('Disable any permission checking for this '
90-
'file. File will be publicly accessible '
91-
'to anyone.'))
131+
verbose_name=_("Permissions disabled"),
132+
help_text=_("Disable any permission checking for this "
133+
"file. File will be publicly accessible "
134+
"to anyone."))
92135

93136
mime_type = models.CharField(
94137
max_length=255,
95-
help_text='MIME type of uploaded content',
138+
help_text="MIME type of uploaded content",
96139
validators=[mimetype_validator],
97140
default='application/octet-stream',
98141
)
99142

100143
objects = FileManager()
101144

145+
class Meta:
146+
app_label = 'filer'
147+
verbose_name = _("file")
148+
verbose_name_plural = _("files")
149+
150+
def __str__(self):
151+
if self.name in ('', None):
152+
text = "%s" % (self.original_filename,)
153+
else:
154+
text = "%s" % (self.name,)
155+
return text
156+
102157
@classmethod
103158
def matches_file_type(cls, iname, ifile, mime_type):
104159
return True # I match all files...
@@ -270,13 +325,6 @@ def has_generic_permission(self, request, permission_type):
270325
else:
271326
return False
272327

273-
def __str__(self):
274-
if self.name in ('', None):
275-
text = "%s" % (self.original_filename,)
276-
else:
277-
text = "%s" % (self.name,)
278-
return text
279-
280328
def get_admin_change_url(self):
281329
return reverse(
282330
'admin:{0}_{1}_change'.format(
@@ -287,14 +335,8 @@ def get_admin_change_url(self):
287335
)
288336

289337
def get_admin_delete_url(self):
290-
try:
291-
# Django <=1.6
292-
model_name = self._meta.module_name
293-
except AttributeError:
294-
# Django >1.6
295-
model_name = self._meta.model_name
296338
return reverse(
297-
'admin:{0}_{1}_delete'.format(self._meta.app_label, model_name,),
339+
'admin:{0}_{1}_delete'.format(self._meta.app_label, self._meta.model_name),
298340
args=(self.pk,))
299341

300342
@property
@@ -373,8 +415,3 @@ def logical_path(self):
373415
@property
374416
def duplicates(self):
375417
return File.objects.find_duplicates(self)
376-
377-
class Meta:
378-
app_label = 'filer'
379-
verbose_name = _('file')
380-
verbose_name_plural = _('files')

filer/models/foldermodels.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ class Folder(models.Model, mixins.IconsMixin):
104104
related_name='children',
105105
on_delete=models.CASCADE,
106106
)
107-
name = models.CharField(_('name'), max_length=255)
107+
108+
name = models.CharField(
109+
_('name'),
110+
max_length=255,
111+
)
108112

109113
owner = models.ForeignKey(
110114
getattr(settings, 'AUTH_USER_MODEL', 'auth.User'),
@@ -115,10 +119,31 @@ class Folder(models.Model, mixins.IconsMixin):
115119
blank=True,
116120
)
117121

118-
uploaded_at = models.DateTimeField(_('uploaded at'), auto_now_add=True)
122+
uploaded_at = models.DateTimeField(
123+
_('uploaded at'),
124+
auto_now_add=True,
125+
)
126+
127+
created_at = models.DateTimeField(
128+
_('created at'),
129+
auto_now_add=True,
130+
)
131+
132+
modified_at = models.DateTimeField(
133+
_('modified at'),
134+
auto_now=True,
135+
)
119136

120-
created_at = models.DateTimeField(_('created at'), auto_now_add=True)
121-
modified_at = models.DateTimeField(_('modified at'), auto_now=True)
137+
class Meta:
138+
# see: https://github.com/django-mptt/django-mptt/pull/577
139+
index_together = (('tree_id', 'lft'),)
140+
unique_together = (('parent', 'name'),)
141+
ordering = ('name',)
142+
permissions = (("can_use_directory_listing",
143+
"Can use directory listing"),)
144+
app_label = 'filer'
145+
verbose_name = _("Folder")
146+
verbose_name_plural = _("Folders")
122147

123148
@property
124149
def file_count(self):
@@ -230,17 +255,6 @@ def contains_folder(self, folder_name):
230255
except Folder.DoesNotExist:
231256
return False
232257

233-
class Meta:
234-
# see: https://github.com/django-mptt/django-mptt/pull/577
235-
index_together = (('tree_id', 'lft'),)
236-
unique_together = (('parent', 'name'),)
237-
ordering = ('name',)
238-
permissions = (("can_use_directory_listing",
239-
"Can use directory listing"),)
240-
app_label = 'filer'
241-
verbose_name = _("Folder")
242-
verbose_name_plural = _("Folders")
243-
244258

245259
# MPTT registration
246260
try:
@@ -300,7 +314,11 @@ class FolderPermission(models.Model):
300314
null=True,
301315
on_delete=models.CASCADE,
302316
)
303-
everybody = models.BooleanField(_("everybody"), default=False)
317+
318+
everybody = models.BooleanField(
319+
_("everybody"),
320+
default=False,
321+
)
304322

305323
can_read = models.SmallIntegerField(
306324
_("can read"),
@@ -326,6 +344,11 @@ class FolderPermission(models.Model):
326344
default=None,
327345
)
328346

347+
class Meta:
348+
verbose_name = _('folder permission')
349+
verbose_name_plural = _('folder permissions')
350+
app_label = 'filer'
351+
329352
objects = FolderPermissionManager()
330353

331354
def __str__(self):
@@ -364,8 +387,3 @@ def clean(self):
364387
raise ValidationError('User or group cannot be selected together with "everybody".')
365388
if not self.user and not self.group and not self.everybody:
366389
raise ValidationError('At least one of user, group, or "everybody" has to be selected.')
367-
368-
class Meta:
369-
verbose_name = _('folder permission')
370-
verbose_name_plural = _('folder permissions')
371-
app_label = 'filer'

0 commit comments

Comments
 (0)