Commits

Artur Barseghyan committed 17a15bc Draft

cleanup

Comments (0)

Files changed (2)

example/example/local_settings.py

 PROJECT_DIR = lambda base : os.path.abspath(os.path.join(os.path.dirname(__file__), base).replace('\\','/'))
 
 DEBUG = True
-DEBUG_TOOLBAR = True
+DEBUG_TOOLBAR = False
 TEMPLATE_DEBUG = DEBUG
 
 DATABASES = {

src/slim/models/fields.py

 from django.core import exceptions
 from django.utils.translation import ugettext_lazy as _
 
-from slim import get_languages, default_language, get_languages_keys
-from slim.monkey_patches import monkeypatch_method, monkeypatch_property
-from slim.translations import is_primary_language
+from slim import get_languages, default_language
 
 
 class LanguageField(models.CharField):
             translated_object = None
         if not model_instance.pk:
             if translated_object and translated_object.pk:
-                raise exceptions.ValidationError("Translation in language %s for this object already exists." % value )
+                raise exceptions.ValidationError("Translation in language %s for this object already exists." % value)
         else:
             if translated_object and translated_object.pk and model_instance != translated_object:
-                raise exceptions.ValidationError("Translation in language %s for this object already exists." % value )
+                raise exceptions.ValidationError("Translation in language %s for this object already exists." % value)
         super(LanguageField, self).validate(value, model_instance)
 
-        '''
-        @monkeypatch_property(cls)
-        def is_multilingual(self):
-            """
-            Simple flat to use on objects to find our wheither they are multilinugal
-            or not
-
-            :return bool: Always returns boolean True
-            """
-            return True
-
-        @monkeypatch_method(cls)
-        def get_redirect_to_target(self, request):
-            """
-            Find an acceptable redirect target. If this is a local link, then try
-            to find the page this redirect references and translate it according
-            to the user's language. This way, one can easily implement a localized
-            "/"-url to welcome page redirection.
-            """
-            target = self.redirect_to
-            if target and target.find('//') == -1: # Not an offsite link http://bla/blubb
-                try:
-                    page = cls.objects.page_for_path(target)
-                    page = page.get_translation(getattr(request, 'LANGUAGE_CODE', None))
-                    target = page.get_absolute_url()
-                except cls.DoesNotExist:
-                    pass
-            return target
-
-        @monkeypatch_method(cls)
-        def available_translations(self):
-            """
-            Returns available translations.
-
-            :return interable: At this moment a list of objects.
-            """
-            if not self.id: # New, unsaved pages have no translations
-                return []
-            if is_primary_language(self.language):
-                return self.translations.all()
-            elif self.translation_of:
-                return [self.translation_of] + list(self.translation_of.translations.exclude(
-                    language=self.language))
-            else:
-                return []
-
-        @monkeypatch_method(cls)
-        def get_original_translation(self, *args, **kwargs):
-            """
-            Gets original translation of current object.
-
-            :return obj: Object of the same class as the one queried.
-            """
-            if is_primary_language(self.language):
-                return self
-            return self.translation_of
-
-        @monkeypatch_method(cls)
-        def translation_admin(self, *args, **kwargs):
-            """
-            Gets a HTML with URL to the original translation of available. For admin use.
-
-            :return str:
-            """
-            if self.translation_of:
-                url = u'/admin/' + self._meta.app_label + '/' + self._meta.module_name + '/' + \
-                      str(self.translation_of.id) + '/'
-                name = unicode(self.translation_of)
-
-                return u'<a href="%(url)s">%(name)s</a>' % {'url': url, 'name': name}
-            return ''
-        translation_admin.allow_tags = True
-        translation_admin.short_description = _('Translation of')
-
-        @monkeypatch_method(cls)
-        def _available_translations_admin(self, include_self=True):
-            """
-            Gets a HTML with all available translation URLs for current object if available. For admin use.
-
-            :return str:
-            """
-            try:
-                original_translation = self.original_translation
-                available_translations = list(self.available_translations())
-                languages_keys = get_languages_keys()
-                languages = dict(get_languages())
-
-                if include_self:
-                    available_translations.append(self)
-
-                output = []
-                # Processing all available translations. Adding edit links.
-                if available_translations:
-                    for translation in available_translations:
-                        url = u'/admin/' + translation._meta.app_label + '/' + translation._meta.module_name + \
-                              '/' + str(translation.id) + '/'
-                        name = unicode(languages[translation.language])
-                        output.append(u'<a href="%(url)s">%(name)s</a>' % {'url': url, 'name': name})
-                        languages_keys.remove(translation.language)
-
-                if self.pk and self.language in languages_keys:
-                    languages_keys.remove(self.language)
-
-                # For all languages that are still available (original object has no translations for)
-                for language in languages_keys:
-                    url = u'/admin/' + self._meta.app_label + '/' + self._meta.module_name + \
-                          '/add/?translation_of=' + str(original_translation.id) + '&amp;language=' + language
-                    name = unicode(languages[language])
-                    output.append(u'<a href="%(url)s" style="color:#baa">%(name)s</a>' % {'url': url, 'name': name})
-                return u' | '.join(output)
-            except Exception, e:
-                return u''
-
-        @monkeypatch_method(cls)
-        def available_translations_admin(self, *args, **kwargs):
-            """
-            Gets a HTML with all available translation URLs for current object if available. For admin use.
-
-            :return str:
-            """
-            return self._available_translations_admin(include_self=True, *args, **kwargs)
-        available_translations_admin.allow_tags = True
-        available_translations_admin.short_description = _('Translations')
-
-        @monkeypatch_method(cls)
-        def available_translations_exclude_current_admin(self, *args, **kwargs):
-            """
-            Same as `available_translations_admin` but does not include itself to the list.
-
-            :return str:
-            """
-            return self._available_translations_admin(include_self=False, *args, **kwargs)
-        available_translations_exclude_current_admin.allow_tags = True
-        available_translations_exclude_current_admin.short_description = _('Translations')
-
-        @monkeypatch_property(cls)
-        def original_translation(self):
-            """
-            Property for ``get_original_translation`` method.
-
-            :return obj: Object of the same class as the one queried.
-            """
-            return self.get_original_translation()
-
-        @monkeypatch_method(cls)
-        def get_translation_for(self, language):
-            """
-            Get translation article in given language.
-
-            :param str language: Which shall be one of the languages specified in ``LANGUAGES``
-                in `settings.py`.
-            :return obj: Either object of the same class as or None if no translations are
-                available for the given ``language``.
-            """
-            if not language in get_languages_keys():
-                return None
-            if str(self.language) == str(language):
-                return self
-            if str(self.original_translation.language) == str(language):
-                return self.original_translation
-            try:
-                return self.original_translation.translations.get(language=language)
-            except Exception, e:
-                return None
-        '''
 
 class SimpleLanguageField(models.CharField):
     """