Skip to content

Commit

Permalink
style: Reformat files (use double quotes)
Browse files Browse the repository at this point in the history
  • Loading branch information
last-partizan committed Nov 25, 2023
1 parent c8e44f5 commit 8742ad3
Show file tree
Hide file tree
Showing 23 changed files with 2,073 additions and 2,069 deletions.
23 changes: 12 additions & 11 deletions docs/modeltranslation/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# fmt: off
# django-modeltranslation documentation build configuration file, created by
# sphinx-quickstart on Wed Oct 17 10:26:58 2012.
#
Expand Down Expand Up @@ -59,8 +60,8 @@
master_doc = 'index'

# General information about the project.
project = u'django-modeltranslation'
copyright = u'2009-2019, Peter Eschler, Dirk Eschler, Jacek Tomaszewski'
project = 'django-modeltranslation'
copyright = '2009-2019, Peter Eschler, Dirk Eschler, Jacek Tomaszewski'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -199,8 +200,8 @@
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-modeltranslation.tex',
u'django-modeltranslation Documentation',
u'Dirk Eschler', 'manual'),
'django-modeltranslation Documentation',
'Dirk Eschler', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -230,8 +231,8 @@
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-modeltranslation',
u'django-modeltranslation Documentation',
[u'Dirk Eschler'], 1)
'django-modeltranslation Documentation',
['Dirk Eschler'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -245,7 +246,7 @@
# dir menu entry, description, category)
texinfo_documents = [
('index', 'django-modeltranslation',
u'django-modeltranslation Documentation', u'Dirk Eschler',
'django-modeltranslation Documentation', 'Dirk Eschler',
'django-modeltranslation', 'One line description of project.',
'Miscellaneous'),
]
Expand All @@ -263,10 +264,10 @@
# -- Options for Epub output --------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = u'django-modeltranslation'
epub_author = u'Dirk Eschler'
epub_publisher = u'Dirk Eschler'
epub_copyright = u'2009-2019, Peter Eschler, Dirk Eschler, Jacek Tomaszewski'
epub_title = 'django-modeltranslation'
epub_author = 'Dirk Eschler'
epub_publisher = 'Dirk Eschler'
epub_copyright = '2009-2019, Peter Eschler, Dirk Eschler, Jacek Tomaszewski'

# The language of the text. It defaults to the language option
# or en if the language is not set.
Expand Down
6 changes: 3 additions & 3 deletions get-django-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import sys

version = sys.argv[1]
if version.startswith('http'):
if version.startswith("http"):
print(version)
else:
next_version = version[:-1] + '%d' % (int(version[-1]) + 1)
print('Django>=%s,<%s' % (version, next_version))
next_version = version[:-1] + "%d" % (int(version[-1]) + 1)
print("Django>=%s,<%s" % (version, next_version))
2 changes: 1 addition & 1 deletion modeltranslation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from django import VERSION as _django_version

if _django_version < (3, 2):
default_app_config = 'modeltranslation.apps.ModeltranslationConfig'
default_app_config = "modeltranslation.apps.ModeltranslationConfig"
except ImportError:
pass
61 changes: 31 additions & 30 deletions modeltranslation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ def __init__(self, *args, **kwargs):

def _get_declared_fieldsets(self, request, obj=None):
# Take custom modelform fields option into account
if not self.fields and hasattr(self.form, '_meta') and self.form._meta.fields:
if not self.fields and hasattr(self.form, "_meta") and self.form._meta.fields:
self.fields = self.form._meta.fields
# takes into account non-standard add_fieldsets attribute used by UserAdmin
fieldsets = (
self.add_fieldsets
if getattr(self, 'add_fieldsets', None) and obj is None
if getattr(self, "add_fieldsets", None) and obj is None
else self.fieldsets
)
if fieldsets:
return self._patch_fieldsets(fieldsets)
elif self.fields:
return [(None, {'fields': self.replace_orig_field(self.get_fields(request, obj))})]
return [(None, {"fields": self.replace_orig_field(self.get_fields(request, obj))})]
return None

def formfield_for_dbfield(self, db_field, request, **kwargs):
Expand All @@ -53,7 +53,7 @@ def patch_translation_field(self, db_field, field, request, **kwargs):
if field.required:
field.required = False
field.blank = True
self._orig_was_required['%s.%s' % (db_field.model._meta, db_field.name)] = True
self._orig_was_required["%s.%s" % (db_field.model._meta, db_field.name)] = True

# For every localized field copy the widget from the original field
# and add a css class to identify a modeltranslation widget.
Expand Down Expand Up @@ -83,24 +83,24 @@ def patch_translation_field(self, db_field, field, request, **kwargs):
b for b in form_class.__bases__ if b != NullCharField
)
field.__class__ = type(
'Nullable%s' % form_class.__name__, (NullableField, form_class), {}
"Nullable%s" % form_class.__name__, (NullableField, form_class), {}
)
if (
db_field.empty_value == 'both' or orig_field.name in self.both_empty_values_fields
db_field.empty_value == "both" or orig_field.name in self.both_empty_values_fields
) and isinstance(field.widget, (forms.TextInput, forms.Textarea)):
field.widget = ClearableWidgetWrapper(field.widget)
css_classes = self._get_widget_from_field(field).attrs.get('class', '').split(' ')
css_classes.append('mt')
css_classes = self._get_widget_from_field(field).attrs.get("class", "").split(" ")
css_classes.append("mt")
# Add localized fieldname css class
css_classes.append(build_css_class(db_field.name, 'mt-field'))
css_classes.append(build_css_class(db_field.name, "mt-field"))
# Add mt-bidi css class if language is bidirectional
if get_language_bidi(db_field.language):
css_classes.append('mt-bidi')
css_classes.append("mt-bidi")
if db_field.language == mt_settings.DEFAULT_LANGUAGE:
# Add another css class to identify a default modeltranslation widget
css_classes.append('mt-default')
css_classes.append("mt-default")
if orig_formfield.required or self._orig_was_required.get(
'%s.%s' % (orig_field.model._meta, orig_field.name)
"%s.%s" % (orig_field.model._meta, orig_field.name)
):
# In case the original form field was required, make the
# default translation field required instead.
Expand All @@ -111,7 +111,7 @@ def patch_translation_field(self, db_field, field, request, **kwargs):
# Hide clearable widget for required fields
if isinstance(field.widget, ClearableWidgetWrapper):
field.widget = field.widget.widget
self._get_widget_from_field(field).attrs['class'] = ' '.join(css_classes)
self._get_widget_from_field(field).attrs["class"] = " ".join(css_classes)

def _get_widget_from_field(self, field):
# retrieve "nested" widget in case of related field
Expand Down Expand Up @@ -171,8 +171,8 @@ def _patch_fieldsets(self, fieldsets):
if fieldsets:
fieldsets_new = list(fieldsets)
for name, dct in fieldsets:
if 'fields' in dct:
dct['fields'] = self.replace_orig_field(dct['fields'])
if "fields" in dct:
dct["fields"] = self.replace_orig_field(dct["fields"])
fieldsets = fieldsets_new
return fieldsets

Expand Down Expand Up @@ -208,15 +208,15 @@ def _get_form_or_formset(self, request, obj, **kwargs):
else:
exclude = list(exclude)
exclude.extend(self.get_readonly_fields(request, obj))
if not exclude and hasattr(self.form, '_meta') and self.form._meta.exclude:
if not exclude and hasattr(self.form, "_meta") and self.form._meta.exclude:
# Take the custom ModelForm's Meta.exclude into account only if the
# ModelAdmin doesn't define its own.
exclude.extend(self.form._meta.exclude)
# If exclude is an empty list we pass None to be consistent with the
# default on modelform_factory
exclude = self.replace_orig_field(exclude) or None
exclude = self._exclude_original_fields(exclude)
kwargs.update({'exclude': exclude})
kwargs.update({"exclude": exclude})

return kwargs

Expand All @@ -234,7 +234,7 @@ def _get_fieldsets_post_form_or_formset(self, request, form, obj=None):
"""
base_fields = self.replace_orig_field(form.base_fields.keys())
fields = list(base_fields) + list(self.get_readonly_fields(request, obj))
return [(None, {'fields': self.replace_orig_field(fields)})]
return [(None, {"fields": self.replace_orig_field(fields)})]

def get_translation_field_excludes(self, exclude_languages=None):
"""
Expand Down Expand Up @@ -296,13 +296,14 @@ def _group_fieldsets(self, fieldsets):
untranslated_fields = [
f.name
for f in fields
if (
if
(
# Exclude the primary key field
f is not self.opts.auto_field
# Exclude non-editable fields
and f.editable
# Exclude the translation fields
and not hasattr(f, 'translated_field')
and not hasattr(f, "translated_field")
# Honour field arguments. We rely on the fact that the
# passed fieldsets argument is already fully filtered
# and takes options like exclude into account.
Expand All @@ -313,8 +314,8 @@ def _group_fieldsets(self, fieldsets):
fieldsets = (
[
(
'',
{'fields': untranslated_fields},
"",
{"fields": untranslated_fields},
)
]
if untranslated_fields
Expand All @@ -331,13 +332,13 @@ def _group_fieldsets(self, fieldsets):
label = self.model._meta.get_field(orig_field).verbose_name.capitalize()
temp_fieldsets[orig_field] = (
label,
{'fields': trans_fieldnames, 'classes': ('mt-fieldset',)},
{"fields": trans_fieldnames, "classes": ("mt-fieldset",)},
)

fields_order = unique(
f.translated_field.name
for f in self.opts.fields
if hasattr(f, 'translated_field') and f.name in flattened_fieldsets
if hasattr(f, "translated_field") and f.name in flattened_fieldsets
)
for field_name in fields_order:
fieldsets.append(temp_fieldsets.pop(field_name))
Expand Down Expand Up @@ -397,13 +398,13 @@ class TabbedDjangoJqueryTranslationAdmin(TranslationAdmin):

class Media:
js = (
'admin/js/jquery.init.js',
'modeltranslation/js/force_jquery.js',
"admin/js/jquery.init.js",
"modeltranslation/js/force_jquery.js",
mt_settings.JQUERY_UI_URL,
'modeltranslation/js/tabbed_translation_fields.js',
"modeltranslation/js/tabbed_translation_fields.js",
)
css = {
'all': ('modeltranslation/css/tabbed_translation_fields.css',),
"all": ("modeltranslation/css/tabbed_translation_fields.css",),
}


Expand All @@ -417,10 +418,10 @@ class Media:
js = (
mt_settings.JQUERY_URL,
mt_settings.JQUERY_UI_URL,
'modeltranslation/js/tabbed_translation_fields.js',
"modeltranslation/js/tabbed_translation_fields.js",
)
css = {
'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
"screen": ("modeltranslation/css/tabbed_translation_fields.css",),
}


Expand Down
4 changes: 2 additions & 2 deletions modeltranslation/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class ModeltranslationConfig(AppConfig):
name = 'modeltranslation'
verbose_name = 'Modeltranslation'
name = "modeltranslation"
verbose_name = "Modeltranslation"

def ready(self):
from modeltranslation.models import handle_translation_registrations
Expand Down
Loading

0 comments on commit 8742ad3

Please sign in to comment.