1. Branko Vukelic
  2. django-i18n-model

Commits

egasimus  committed cbd616b

Apply a slightly more concise coding style to models.py

  • Participants
  • Parent commits 0b03989
  • Branches master

Comments (0)

Files changed (1)

File i18n_model/models.py

View file
     def __new__(cls, *args, **kwargs):
         for language in settings.LANGUAGES:
             language_code = language[0]
-            setattr(
-                cls,
-                language_code.replace('-', '_'),
-                create_language_method(language_code)
-            )
+            setattr(cls,
+                    language_code.replace('-', '_'),
+                    create_language_method(language_code))
         return models.Manager.__new__(cls)
 
 
             if '.' in source:
                 # There's a dot in the name, so this is a model name in
                 # ``app.Model`` format, most likely.
-                source = get_model(
-                    source.split('.')[0],
-                    source.split('.')[1]
-                )
+                source = get_model(source.split('.')[0],
+                                   source.split('.')[1])
 
             else:
                 # Otherwise, let's assume that developer meant just class name.
                 # Let's try to get it as a class.
-                source = get_class(
-                    source,
-                    attrs['__module__'],
-                )
+                source = get_class(source,
+                                   attrs['__module__'],)
 
         if source is None and name.endswith('I18N'):
             # There wasn't a ``source_model`` attribute among the Meta options,
         if not fields:
             # No fields were found, so let's grab all CharField, SlugField,
             # and TextField from the source model.
-            fields = [
-                f.name for f in source._meta.fields
-                if type(f) in [
-                    models.TextField,
-                    models.CharField,
-                    models.SlugField
-                ]
-            ]
+            fields = [f.name for f in source._meta.fields
+                      if type(f) in [models.TextField,
+                                     models.CharField,
+                                     models.SlugField]]
 
         unique_fields = []
 
             if type(attrs['Meta'].unique_together[0]) in (str, unicode):
                 attrs['Meta'].unique_together = (
                     attrs['Meta'].unique_together,
-                    ('i18n_source', 'i18n_language')
-                )
+                    ('i18n_source', 'i18n_language'))
             else:
-                attrs['Meta'].unique_together += (
-                    'i18n_source',
-                    'i18n_language'
-                )
+                attrs['Meta'].unique_together += ('i18n_source',
+                                                  'i18n_language')
         else:
             attrs['Meta'].unique_together = (('i18n_source', 'i18n_language'),)
 
                 attrs['Meta'].unique_together += (('i18n_language', field),)
 
         # Let's also add a reference to the original model
-        attrs['i18n_source'] = models.ForeignKey(
-            source,
-            related_name='translations',
-            editable=False,
-            verbose_name=_('source')
-        )
+        attrs['i18n_source'] = models.ForeignKey(source,
+                                                 related_name='translations',
+                                                 editable=False,
+                                                 verbose_name=_('source'))
 
         return ModelBase.__new__(mcs, name, bases, attrs)
 
         _('language'),
         max_length=10,
         choices=[l for l in settings.LANGUAGES
-                 if l[0] != settings.LANGUAGE_CODE],
-    )
+                 if l[0] != settings.LANGUAGE_CODE])
 
     @classmethod
     def translate(cls, source, language, **kwargs):
         if not kwargs:
-            return cls.objects.get(
-                i18n_source=source,
-                i18n_language=language
-            )
+            return cls.objects.get(i18n_source=source,
+                                   i18n_language=language)
 
         try:
-            translation = cls.objects.get(
-                i18n_source=source,
-                i18n_language=language
-            )
+            translation = cls.objects.get(i18n_source=source,
+                                          i18n_language=language)
             for key, value in kwargs.items():
                 setattr(translation, key, value)
             translation.save()
             return translation
         except cls.DoesNotExist:
-            return cls.objects.create(
-                i18n_source=source,
-                i18n_language=language,
-                **kwargs
-            )
+            return cls.objects.create(i18n_source=source,
+                                      i18n_language=language,
+                                      **kwargs)
 
     def __unicode__(self):
-        return _('%s translation for %s') % (
-            self.get_i18n_language_display(),
-            self.i18n_source,
-        )
+        return _('%s translation for %s') % (self.get_i18n_language_display(),
+                                             self.i18n_source)
 
     objects = I18nManager()