def get_meta_description(self, language=None): language = language or get_current_language() meta_tag = "" meta_description = getattr(self, "meta_description_%s" % language) if meta_description: meta_tag = u"""<meta name="description" lang="%s" content="%s" />\n""" % (language, escape(meta_description)) return mark_safe(meta_tag)
def get_meta_keywords(self, language=None): language = language or get_current_language() meta_tag = "" meta_keywords = getattr(self, "meta_keywords_%s" % language) if meta_keywords: meta_tag = u"""<meta name="keywords" lang="%s" content="%s" />\n""" % (language, escape(meta_keywords)) return mark_safe(meta_tag)
def __get__(self, obj, type=None): if obj is None: raise AttributeError('MultilingualProxy.__get__ can only be accessed via an instance.') language = get_current_language() or settings.LANGUAGE_CODE val = obj.__dict__[_language_field_name(self._field.attname, language)] if not val: val = obj.__dict__[_language_field_name(self._field.attname, settings.LANGUAGE_CODE)] if not val and not self._field.blank: # No value set for mandatory field for the current language! Has the default language been changed recently? return "" return val
def get_fees(self, language=None): language = language or get_current_language() fees = [] for i in range(_fees_count): label = getattr(self, "fee%d_label_%s" % (i, language), "") or getattr(self, "fee%d_label" % i, "") amount = getattr(self, "fee%d_amount" % i) if label and amount is not None: fees.append({ "label": label, "amount": format_currency(amount, "EUR", locale=language) }) return fees
def __set__(self, obj, value): """ sets a multi language value programmatically. The value must be provided either by a value or by a dictionary with the language code as key and a string value as value """ # setting multilingual values via dict!!! if isinstance(value, dict): for key in value.keys(): obj.__dict__[_language_field_name(self._field.attname, key)] = value[key] # normal setter else: language = get_current_language() or settings.LANGUAGE_CODE obj.__dict__[_language_field_name(self._field.attname, language)] = value
def get_rendered(self): language = get_current_language() or settings.LANGUAGE_CODE field_value = getattr(self, _language_field_name(_name, language)) mt = getattr( self, "%s_markup_type" % _language_field_name(_name, language), ) if not field_value: field_value = getattr(self, _language_field_name(_name, settings.LANGUAGE_CODE)) mt = getattr( self, "%s_markup_type" % _language_field_name(_name, settings.LANGUAGE_CODE), ) if not field_value and not self._meta.get_field(_name).blank: # No value set for mandatory field for the current language! Has the default language been changed recently? return "" if mt == markup_settings.MARKUP_PLAIN_TEXT: field_value = field_value.strip() if field_value: field_value = escape(field_value) try: # try to urlize if there are no invalid IPv6 URLs field_value = urlize(field_value) except ValueError: pass field_value = linebreaks(field_value) elif mt == markup_settings.MARKUP_RAW_HTML: pass elif mt == markup_settings.MARKUP_HTML_WYSIWYG: pass elif mt == markup_settings.MARKUP_MARKDOWN: try: import markdown except ImportError: if settings.DEBUG: raise Warning("Error in {% markdown %} filter: The Python markdown library isn't installed.") return field_value else: field_value = markdown.markdown(field_value) # remove empty paragraphs field_value = field_value.replace('<p></p>', '') return mark_safe(field_value)