本文整理汇总了Python中transmeta.get_real_fieldname函数的典型用法代码示例。如果您正苦于以下问题:Python get_real_fieldname函数的具体用法?Python get_real_fieldname怎么用?Python get_real_fieldname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_real_fieldname函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:creativify,项目名称:merengueproj,代码行数:28,代码来源:forms.py
示例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)
开发者ID:hult,项目名称:django-slugmeta,代码行数:15,代码来源:__init__.py
示例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
开发者ID:zyegfryed,项目名称:django-transmeta,代码行数:27,代码来源:sync_transmeta_db.py
示例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,
}
开发者ID:creativify,项目名称:merengueproj,代码行数:29,代码来源:models.py
示例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))
开发者ID:djangozoom,项目名称:merengue_plugins,代码行数:27,代码来源:forms.py
示例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)
开发者ID:averrin,项目名称:eliar,代码行数:31,代码来源:commons.py
示例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()
开发者ID:arnemutab,项目名称:django-fixmystreet,代码行数:7,代码来源:utils.py
示例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
开发者ID:erny,项目名称:django-transmeta,代码行数:9,代码来源:sync_transmeta_db.py
示例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)
开发者ID:ramusus,项目名称:django-transmeta,代码行数:10,代码来源:utils.py
示例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
开发者ID:averrin,项目名称:eliar,代码行数:11,代码来源:fields.py
示例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)
开发者ID:tlevine,项目名称:django-inplaceedit,代码行数:54,代码来源:commons.py
示例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
开发者ID:JeffHeard,项目名称:django-inplaceedit,代码行数:12,代码来源:fields.py
示例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
开发者ID:erny,项目名称:django-transmeta,代码行数:12,代码来源:sync_transmeta_db.py
示例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 ""
开发者ID:UniversidadeSaoPaulo,项目名称:cifonauta,代码行数:40,代码来源:sync_datatrans_to_transmeta.py
示例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
开发者ID:Alotor,项目名称:intranet,代码行数:13,代码来源:utils.py
示例16: create_itag_from_tag
def create_itag_from_tag(sender, instance, **kwargs):
try:
instance.itag
except ITag.DoesNotExist:
itag = ITag(tag_ptr=instance)
lang = get_plugin('itags').get_config().get('main_language', None)
lang = lang and lang.value or None
if lang in dict(settings.LANGUAGES).keys():
setattr(itag, get_real_fieldname('tag_name', lang), instance.name)
else:
setattr(itag, get_fallback_fieldname('tag_name'), instance.name)
itag.save_base(raw=True)
开发者ID:creativify,项目名称:merengueproj,代码行数:13,代码来源:models.py
示例17: 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)
default_f = self.get_default_field(field_name, model)
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
if not new_field in self.get_table_fields(db_table):
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:
# changing to NOT NULL after having data copied
sql_output.append(
"ALTER TABLE %s ALTER COLUMN %s SET %s"
% (qn(db_table), qn(f.column), style.SQL_KEYWORD("NOT NULL"))
)
elif default_f and not default_f.null and lang == self.default_lang:
# data copy from old field (only for default language)
sql_output.append(
"UPDATE %(db_table)s SET %(f_colum)s = '%(value_default)s'\
WHERE %(f_colum)s is %(null)s or %(f_colum)s = '' "
% {
"db_table": qn(db_table),
"f_colum": qn(f.column),
"value_default": qn(VALUE_DEFAULT),
"null": style.SQL_KEYWORD("NULL"),
}
)
# changing to NOT NULL after having data copied
sql_output.append(
"ALTER TABLE %s ALTER COLUMN %s DROP %s"
% (qn(db_table), qn(default_f.column), style.SQL_KEYWORD("NOT NULL"))
)
sql_output.append(
"ALTER TABLE %s ALTER COLUMN %s SET %s"
% (qn(db_table), qn(f.column), 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
开发者ID:myvasyabigi,项目名称:Polonne,代码行数:51,代码来源:sync_transmeta_db.py
示例18: make_single_item
def make_single_item(self, feed_item, entry):
feed_item.item_cached = base64.encodestring(pickle.dumps(entry))
if self.order_by:
feed_item.order_field = getattr(entry, self.order_by, None)
else:
feed_item.order_field = None
if self.group_by:
feed_item.group_field = getattr(entry, self.group_by, None)
else:
feed_item.group_field = None
title_field = self.title_field or 'title'
field_name = get_real_fieldname('name', fallback_language())
setattr(feed_item, field_name, getattr(entry, title_field, getattr(entry, 'id', None)))
feed_item.excluded = self.is_excluded(entry)
feed_item.save()
开发者ID:creativify,项目名称:merengueproj,代码行数:15,代码来源:models.py
示例19: search
def search(request):
q = request.GET['q'].strip()
results = {}
results['resources'] = Resource.objects.filter(name__icontains=q)
results['tags'] = Tag.objects.filter(value__icontains=q)
from transmeta import get_real_fieldname
fname = get_real_fieldname('name')
results['views'] = View.objects.filter(**{'%s__icontains' % fname : q})
import wiki
results['pages'] = wiki.models.Article.objects.filter(content__icontains=q)
return render_to_response('openresources/search_results.html', RequestContext(request, locals()))
开发者ID:schoeke,项目名称:django-openresources,代码行数:16,代码来源:views.py
示例20: 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.BooleanField):
adaptor = "boolean"
elif isinstance(field, models.DateField):
adaptor = "date"
elif isinstance(field, models.DateTimeField):
adaptor = "datetime"
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 isinstance(field, (models.IntegerField, models.DecimalField)):
adaptor = "number"
if getattr(field, "choices", None):
adaptor = "choices"
elif isinstance(field, models.CharField):
adaptor = "text"
if getattr(field, "choices", None):
adaptor = "choices"
elif isinstance(field, models.TextField):
adaptor = "textarea"
else:
adaptor = "default"
path_adaptor = (
getattr(settings, "ADAPTOR_INPLACEEDIT", None) and 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)
parts = path_adaptor.split(".")
path_module, class_adaptor = (".".join(parts[:-1]), parts[-1])
return getattr(import_module(path_module), class_adaptor)
开发者ID:peter-conalgo,项目名称:django-inplaceedit,代码行数:46,代码来源:commons.py
注:本文中的transmeta.get_real_fieldname函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论