本文整理汇总了Python中transmeta.get_real_fieldname函数的典型用法代码示例。如果您正苦于以下问题:Python get_real_fieldname函数的具体用法?Python get_real_fieldname怎么用?Python get_real_fieldname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_real_fieldname函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
def save(self, commit=False):
section = section = self.get_section()
if self.is_menu():
menu = super(HotLinkForm, self).save(commit)
menu_parent = section.main_menu
menu.parent = menu_parent
menu.save()
ContentLink.objects.create(content=self.content, menu=menu)
return menu
elif self.is_standingout():
standinouts = self.get_standingout_of_section(section)
order = 0
if standinouts:
if standinouts[0].order:
order = standinouts[0].order + 1
else:
order = standinouts.count() + 1
from plugins.standingout.models import StandingOut
stand = StandingOut.objects.create(obj=self.content,
related=section,
order=order)
name_lang = transmeta.get_real_fieldname('name', settings.LANGUAGE_CODE)
name_text = self.cleaned_data.get(name_lang)
if name_text and name_text != self.content.name:
title_lang = transmeta.get_real_fieldname('title', settings.LANGUAGE_CODE)
setattr(stand, title_lang, name_text)
stand.save()
return stand
示例2: __new__
def __new__(cls, name, bases, dct):
new_dct = copy.copy(dct)
if 'prepopulated_fields_translate' in dct:
# First, we create the prepopulated fields entry
if 'prepopulated_fields' not in dct:
new_dct['prepopulated_fields'] = {}
# Then, we loop through each of them, creating one prepopulated field per language
for slug_field, other_fields in dct.get('prepopulated_fields_translate', {}).iteritems():
for lang, _ in getattr(settings, 'LANGUAGES', ()):
new_dct['prepopulated_fields'][transmeta.get_real_fieldname(slug_field, lang)] = \
tuple([transmeta.get_real_fieldname(other_field, lang) for other_field in other_fields])
return super(SlugMeta, cls).__new__(cls, name, bases, new_dct)
示例3: get_sync_sql
def get_sync_sql(self, field_name, missing_langs, model):
""" returns SQL needed for sync schema for a new translatable field """
qn = connection.ops.quote_name
style = no_style()
sql_output = []
db_table = model._meta.db_table
was_translatable_before = self.was_translatable_before(field_name, db_table)
for lang in missing_langs:
new_field = get_real_fieldname(field_name, lang)
f = model._meta.get_field(new_field)
col_type = f.db_type()
field_sql = [style.SQL_FIELD(qn(f.column)), style.SQL_COLTYPE(col_type)]
# column creation
sql_output.append("ALTER TABLE %s ADD COLUMN %s;" % (qn(db_table), ' '.join(field_sql)))
if lang == self.default_lang and not was_translatable_before:
# data copy from old field (only for default language)
sql_output.append("UPDATE %s SET %s = %s" % (qn(db_table), \
qn(f.column), qn(field_name)))
if not f.null and lang == self.default_lang:
# changing to NOT NULL after having data copied
sql_output.append("ALTER TABLE %s MODIFY COLUMN %s %s %s;" % \
(qn(db_table), qn(f.column), col_type, \
style.SQL_KEYWORD('NOT NULL')))
if not was_translatable_before:
# we drop field only if field was no translatable before
sql_output.append("ALTER TABLE %s DROP COLUMN %s;" % (qn(db_table), qn(field_name)))
return sql_output
示例4: get_displayfield_data
def get_displayfield_data(self, display_field, item):
"""
returns dictionary with data that will be processed by collection view
to display an item as defined in display_field option.
This method may be overriden in Collection subclasses.
"""
field_name = display_field.field_name
if field_name == 'content_type_name':
verbose_name = ugettext('Content type name')
else:
try:
field = item._meta.get_field(field_name)
verbose_name = field.verbose_name
except models.FieldDoesNotExist:
try:
lang = fallback_language()
field = item._meta.get_field(get_real_fieldname(field_name, lang))
verbose_name = unicode(field.verbose_name)[:-len(lang) - 1]
except:
# TODO: make this except not empty and discriminate errors
return None
return {
'name': verbose_name,
'field_name': field_name,
'show_label': display_field.show_label,
'value': _get_value(display_field, field_name, item),
'type': field.get_internal_type(),
'safe': display_field.safe,
}
示例5: __init__
def __init__(self, user, content, data=None, *args, **kwargs):
super(HotLinkForm, self).__init__(data, *args, **kwargs)
self.content = content
if user.is_superuser:
choices = BaseSection.objects.all()
else:
class_names = ['basesection']
subclasses = BaseSection.__subclasses__()
class_names += [subclass.__name__.lower() for subclass in subclasses]
choices = user.contents_owned.filter(class_name__in=class_names)
if choices.count() == 1:
self.fields['section'] = forms.ModelChoiceField(initial=choices[0],
queryset=choices,
label='',
widget=forms.HiddenInput)
else:
self.fields['section'] = forms.ModelChoiceField(queryset=choices,
label=_('Section'),
required=True,
help_text=_('Choose a section where save the menu'))
name_lang = transmeta.get_real_fieldname('name', settings.LANGUAGE_CODE)
self.fields['slug'].required = False
if not data:
self.fields['slug'].label = ''
self.fields['slug'].widget = forms.HiddenInput()
self.fields[name_lang].label = _('Name')
self.fields[name_lang].initial = getattr(content, name_lang, unicode(content))
示例6: get_adaptor_class
def get_adaptor_class(adaptor=None, obj=None, field_name=None):
if not adaptor:
try:
field = obj._meta.get_field_by_name(field_name)[0]
except FieldDoesNotExist:
if has_transmeta:
field = obj._meta.get_field_by_name(transmeta.get_real_fieldname(field_name))[0]
if isinstance(field, models.CharField):
adaptor = 'text'
if getattr(field, 'choices', None):
adaptor = 'choices'
elif isinstance(field, models.TextField):
adaptor = 'textarea'
elif isinstance(field, models.BooleanField):
adaptor = 'boolean'
elif isinstance(field, models.DateTimeField):
adaptor = 'datetime'
elif isinstance(field, models.DateField):
adaptor = 'date'
elif isinstance(field, ForeignKey):
adaptor = 'fk'
elif isinstance(field, ManyToManyField):
adaptor = 'm2mcomma'
from inplaceeditform.fields import BaseAdaptorField
path_adaptor = adaptor and ((getattr(settings, 'ADAPTOR_INPLACEEDIT', None) and
settings.ADAPTOR_INPLACEEDIT.get(adaptor, None)) or
(DEFAULT_ADAPTOR_INPLACEEDIT.get(adaptor, None)))
if not path_adaptor:
return BaseAdaptorField
path_module, class_adaptor = ('.'.join(path_adaptor.split('.')[:-1]), path_adaptor.split('.')[-1])
return getattr(import_module(path_module), class_adaptor)
示例7: autoslug_transmeta_func
def autoslug_transmeta_func(sender, instance, *args, **kwargs):
for lang, _ in getattr(settings, 'LANGUAGES', ()):
activate(lang)
value = slugify(getattr(instance, populate_from))
setattr(instance, transmeta.get_real_fieldname(populate_to, lang),
value)
deactivate()
示例8: get_type_of_db_field
def get_type_of_db_field(self, field_name, model, lang):
field = self.get_default_field(field_name, model)
if not field:
field = model._meta.get_field(get_real_fieldname(field_name, lang))
try:
col_type = field.db_type(connection)
except TypeError: # old django
col_type = field.db_type()
return col_type
示例9: __setattr__
def __setattr__(self, name, get_field_callback):
'''
Method tried to set full bunch of translatable field using get_field_callback method inside respect_to_language statement
'''
if callable(get_field_callback) and hasattr(self._meta, 'translatable_fields') and name in self._meta.translatable_fields:
for lang in settings.LANGUAGES:
with respect_to_language(lang[0]):
setattr(self, get_real_fieldname(name, lang[0]), get_field_callback())
else:
return super(SetTransMetaAttribute, self).__setattr__(name, get_field_callback)
示例10: _transmeta_processing
def _transmeta_processing(self):
if has_transmeta:
import transmeta
translatable_fields = self._get_translatable_fields(self.model)
if self.field_name in translatable_fields:
self.field_name = transmeta.get_real_fieldname(self.field_name)
self.transmeta = True
if not self.render_value(self.field_name):
self.initial = {self.field_name: ugettext('Write a traslation')}
return
self.transmeta = False
示例11: get_adaptor_class
def get_adaptor_class(adaptor=None, obj=None, field_name=None):
if not adaptor:
try:
field = obj._meta.get_field_by_name(field_name)[0]
except FieldDoesNotExist:
if has_transmeta:
field = obj._meta.get_field_by_name(transmeta.get_real_fieldname(field_name))[0]
if isinstance(field, models.URLField):
adaptor = 'url'
elif isinstance(field, models.EmailField):
adaptor = 'email'
elif isinstance(field, models.CharField):
adaptor = 'text'
elif isinstance(field, models.TextField):
adaptor = 'textarea'
elif isinstance(field, models.NullBooleanField):
adaptor = 'nullboolean'
elif isinstance(field, models.BooleanField):
adaptor = 'boolean'
elif isinstance(field, models.DateTimeField):
adaptor = 'datetime'
elif isinstance(field, models.DateField):
adaptor = 'date'
elif isinstance(field, models.TimeField):
adaptor = 'time'
elif isinstance(field, models.IntegerField):
adaptor = 'integer'
elif isinstance(field, models.FloatField):
adaptor = 'float'
elif isinstance(field, models.DecimalField):
adaptor = 'decimal'
elif isinstance(field, ForeignKey):
adaptor = 'fk'
elif isinstance(field, ManyToManyField):
adaptor = 'm2mcomma'
elif isinstance(field, models.ImageField):
adaptor = 'image'
elif isinstance(field, models.FileField):
adaptor = 'file'
elif gismodels:
if isinstance(field, gismodels.PointField):
adaptor = 'point'
if getattr(field, 'choices', None):
adaptor = 'choices'
from inplaceeditform.fields import BaseAdaptorField
path_adaptor = adaptor and (inplace_settings.ADAPTOR_INPLACEEDIT.get(adaptor, None) or
DEFAULT_ADAPTOR_INPLACEEDIT.get(adaptor, None))
if not path_adaptor and adaptor:
return get_adaptor_class(obj=obj, field_name=field_name)
elif not path_adaptor:
return BaseAdaptorField
path_module, class_adaptor = ('.'.join(path_adaptor.split('.')[:-1]), path_adaptor.split('.')[-1])
return getattr(import_module(path_module), class_adaptor)
示例12: _transmeta_processing
def _transmeta_processing(self):
if has_transmeta:
import transmeta
translatable_fields = self._get_translatable_fields(self.model)
if self.field_name in translatable_fields:
self.field_name = transmeta.get_real_fieldname(self.field_name)
self.transmeta = True
if not self.render_value(self.field_name):
message_translation = unicode(inplace_settings.INPLACEEDIT_EDIT_MESSAGE_TRANSLATION)
self.initial = {self.field_name: message_translation}
return
self.transmeta = False
示例13: get_db_change_languages
def get_db_change_languages(self, field_name, db_table_fields):
""" get only db changes fields """
for lang_code, lang_name in get_languages():
if get_real_fieldname(field_name, lang_code) not in db_table_fields:
yield lang_code
for db_table_field in db_table_fields:
pattern = re.compile('^%s_(?P<lang>\w{2})$' % field_name)
m = pattern.match(db_table_field)
if not m:
continue
lang = m.group('lang')
yield lang
示例14: handle
def handle(self, *args, **options):
""" command execution """
# assume_yes = options.get('assume_yes', False)
# for each language
default_language = fallback_language()
for lang in get_languages():
lang_code = lang[LANGUAGE_CODE]
if lang_code == default_language:
continue
for model in REGISTRY:
fields = REGISTRY[model].values()
total = model.objects.count()
current = 0
for instance in model.objects.all():
current += 1
save = False
# for each field in this model
for field in fields:
# get the real field name (with language suffix)
realname = get_real_fieldname(field.name, lang_code)
# original language
original = get_real_fieldname(field.name, default_language)
# original value
original_value = getattr(instance, original)
# get current value
value = getattr(instance, realname)
if value == None:
value = ""
new_value = KeyValue.objects.lookup(original_value, lang_code)
# if it's not the default message
if new_value != value:
# if it's not the same value
setattr(instance, realname, new_value)
save = True
print "(Lang %s) Processed %s model, %04d / %04d" % (lang_code, model, current, total),
if save:
instance.save()
print " (changed)"
else:
print ""
示例15: get_field_by_name
def get_field_by_name(model, field_name, checked_transmeta=True, api=None):
try:
return (field_name, model._meta.get_field_by_name(field_name)[0])
except models.FieldDoesNotExist, e:
if checked_transmeta and has_transmeta():
field_name_transmeta = transmeta.get_real_fieldname(field_name, get_language())
try:
field_name_transmeta, field = get_field_by_name(model,
field_name_transmeta,
checked_transmeta=False)
return (field_name, field)
except models.FieldDoesNotExist, e:
pass