本文整理汇总了Python中selectable.registry.registry.register函数的典型用法代码示例。如果您正苦于以下问题:Python register函数的具体用法?Python register怎么用?Python register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self, request):
# pylint: disable=E1101
# Instance of <class> has no <member>
# pylint: disable=W0142
# Used * or ** magic
# import from selectable locally so it's not a hard dependency
from selectable.forms import AutoCompleteWidget
from selectable.registry import registry
data = request.GET
model_class = get_model(data['app_label'], data['model_name'])
if not model_class:
raise Http404('"{0}" model not found'.format(data['model_name']))
lookup_name = data.get('lookup', None)
if lookup_name:
lookup_class = registry.get(lookup_name)
else:
lookup_class_name = u'Flyedit{app_label}{model_name}Lookup'.format(
app_label=data['app_label'].title(),
model_name=model_class._meta.object_name)
lookup_name = ('flyedit-{0}'.format(lookup_class_name.lower()))
lookup_class = registry.get(lookup_name)
if not lookup_class:
# create a default lookup class on the fly
from selectable.base import ModelLookup
first_charfield = (f for f in model_class._meta.fields
if isinstance(f, CharField)).next()
search_field = '{0}__icontains'.format(first_charfield.name)
lookup_class = type(
lookup_class_name.encode('ascii'),
(ModelLookup,),
{'model': model_class,
'search_fields': [search_field]})
registry.register(lookup_class)
print lookup_class.model
print lookup_class.search_fields
# Use a dummy form class to render just the auto-complete field
class Form(forms.Form):
autocomplete = forms.CharField(
label=u'',
widget=AutoCompleteWidget(lookup_class))
return HttpResponse(Form()._html_output(
normal_row='<li class="new item">%(field)s</li>',
error_row='',
row_ender='',
help_text_html='',
errors_on_separate_row=False))
示例2: get_cliente_lookup_widget
def get_cliente_lookup_widget(ruc_empresa):
""" Construye un widget lookup para autobus """
print 'get_cliente_lookup_widget - Para empresa', ruc_empresa
class ClienteLookup(ModelLookup):
model = impd_models.ImpdCliente
search_fields = ('identificacion__icontains', 'razon_social__icontains')
filters = {'estado': estado_activo, 'ruc_empresa':ruc_empresa}
def get_item_label(self, item):
return u'%s, %s' % (item.identificacion, item.razon_social)
try:
registry.register(ClienteLookup)
except:
pass
return ClientSearchWidget(lookup_class=ClienteLookup, attrs={'placeholder': __.PH_CLIENTE, 'class':'search_input', 'size':'30'})
示例3: get_factura_config_lookup_widget
def get_factura_config_lookup_widget(ruc_empresa):
""" Construye un widget lookup para autobus """
print 'get_factura_config_lookup_widget - Para empresa', ruc_empresa
class FacturaConfigLookup(ModelLookup):
model = impd_models.ImpdFacturaConfiguracion
search_fields = ('descripcion__icontains', 'establecimiento__icontains')
filters = {'estado': estado_activo, 'ruc_empresa':ruc_empresa}
def get_item_label(self, item):
return u'%s, %s' % (item.establecimiento, item.descripcion)
try:
registry.register(FacturaConfigLookup)
except:
pass
return ConfigSearchWidget(lookup_class=FacturaConfigLookup, attrs={'placeholder': __.PH_CONFIG, 'class':'search_input', 'size':'30'})
示例4: get_productos_lookup_widget
def get_productos_lookup_widget(ruc_empresa):
""" Construye un widget lookup para autobus """
print 'get_productos_lookup_widget - Para empresa', ruc_empresa
class ProductoLookup(ModelLookup):
model = core_models.Producto
search_fields = ('nombre__icontains', 'titulo__icontains', 'codigo_sku__icontains')
filters = {'estado': estado_activo, 'ruc_empresa':ruc_empresa}
def get_item_label(self, item):
return u'%s, %s' % (item.codigo_sku, item.nombre)
try:
registry.register(ProductoLookup)
except Exception as e:
print 'SELECTABLE ERROR', e
return selectable.AutoCompleteSelectWidget(lookup_class=ProductoLookup, attrs={'placeholder': __.PH_PRODUCTO, 'class':'form-control'})
示例5: get_destinatario_lookup_widget
def get_destinatario_lookup_widget(ruc_empresa):
""" Construye un widget lookup para autobus """
print 'get_destinatario_lookup_widget - Para empresa', ruc_empresa
class DestinarioLookup(ModelLookup):
model = impd_models.ImpdGRDestinatario
search_fields = ('identificacion_destinatario__icontains', 'razon_social_destinatario__icontains')
filters = {'estado': estado_activo, 'ruc_empresa':ruc_empresa}
def get_item_label(self, item):
return u'%s' % item.get_descripcion()
try:
registry.unregister(DestinarioLookup)
except:
pass
registry.register(DestinarioLookup)
return DestinatarioSearchWidget(lookup_class=DestinarioLookup,
attrs={'placeholder': __.PH_DESTINATARIO, 'class':'big-field', 'size':'30'})
示例6: formfield_for_dbfield
def formfield_for_dbfield(self, db_field, **kwargs):
if isinstance(db_field, models.ForeignKey):
request = kwargs.get("request")
related_modeladmin = self.admin_site._registry.get(db_field.rel.to)
can_change_related = bool(related_modeladmin and
related_modeladmin.has_add_permission(request))
if (isinstance(db_field, models.ForeignKey) and
db_field.name in self.related_search_fields):
class_name = self.__class__.__name__.lower()
model_name = db_field.name
name = u'%s-%s' % (class_name, model_name)
class Lookup(ModelLookup):
model = db_field.rel.to
search_fields = ['%s__icontains' % f for f in self.related_search_fields[db_field.name]]
def _name(cls):
return name
name = classmethod(_name)
def get_query(self, request, term):
qs = self.get_queryset()
if term:
for bit in term.split():
or_queries = [models.Q(**{field_name: smart_str(bit)})
for field_name in self.search_fields]
qs = qs.filter(reduce(operator.or_, or_queries))
return qs
try:
registry.register(Lookup)
except LookupAlreadyRegistered:
pass
if db_field.name in self.related_combobox:
kwargs['widget'] = AutoComboboxSelectEditWidget(db_field.rel,
self.admin_site, Lookup, can_change_related=can_change_related)
else:
kwargs['widget'] = AutoCompleteSelectEditWidget(db_field.rel,
self.admin_site, Lookup, can_change_related=can_change_related)
#elif isinstance(db_field, models.ForeignKey):
#kwargs['widget'] = SelectEditWidget(db_field.rel, self.admin_site,
#can_change_related=can_change_related)
return super(SelectableAdminMixin, self).formfield_for_dbfield(db_field, **kwargs)
示例7: get_producto_factura_lookup_widget
def get_producto_factura_lookup_widget(ruc_empresa):
""" Construye un widget lookup para autobus """
print 'get_productos_lookup_widget - Para empresa', ruc_empresa
class ProductoFacturaLookup(ModelLookup):
model = impd_models.ImpdProducto
search_fields = ('descripcion__icontains', 'codigo_principal__icontains', 'codigo_secundario__icontains')
filters = {'estado': estado_activo, 'ruc_empresa':ruc_empresa}
def get_item_label(self, item):
return u'%s, %s' % (item.codigo_principal, item.descripcion)
try:
registry.unregister(ProductoFacturaLookup)
except:
pass
try:
registry.register(ProductoFacturaLookup)
except:
pass
return ProductSearchWidget(lookup_class=ProductoFacturaLookup,
attrs={'placeholder': __.PH_PRODUCTO, 'class':'big-field', 'size':'30'})
示例8: ScientificNameLookup
from selectable.base import ModelLookup
from selectable.registry import registry
from demo.prpv.models import TOrganismeTaxo, Fruit
class ScientificNameLookup(ModelLookup):
model = TOrganismeTaxo
search_field = 'nom_scientifique__icontains'
class FruitLookup(ModelLookup):
model = Fruit
search_field = 'name__icontains'
registry.register(FruitLookup)
#registry.register(ScientificNameLookup)
示例9: T3DonorCodeLookup
search_fields = ('code__icontains', )
filters = {'donor_code_type': DonorCode.T1, }
class T3DonorCodeLookup(ModelLookup):
model = DonorCode
search_fields = ('code__icontains', )
filters = {'donor_code_type': DonorCode.T3, }
class ItemCategoryLookup(ModelLookup):
model = ItemCategory
search_fields = ('name__icontains', )
class CatalogItemLookup(ModelLookup):
model = CatalogItem
search_fields = ('item_code__icontains', 'description__icontains')
def get_item_label(self, item):
if item.donor_id:
return '{} ({})'.format(item.description, item.donor)
else:
return item.description
registry.register(T1DonorCodeLookup)
registry.register(T3DonorCodeLookup)
registry.register(ItemCategoryLookup)
registry.register(CatalogItemLookup)
示例10: FruitLookup
from selectable.base import ModelLookup
from selectable.registry import registry
from sabr.models import Master
class FruitLookup(ModelLookup):
model = Fruit
search_field = 'name__icontains'
class PlayerLookup(ModelLookup)
model = Master
search_field = 'playerid__icontains'
registry.register(PlayerLookup)
示例11: suggestions
return suggestions(idiom=IDIOM_GRISCHUN,
direction=SEARCH_DIRECTION_RUM_DEU,
term=term,
limit=10)
class LookupBidirGri(LookupBase):
def get_query(self, request, term):
suggRum = suggestions(idiom=IDIOM_GRISCHUN,
direction=SEARCH_DIRECTION_RUM_DEU,
term=term,
limit=7)
suggDeu = suggestions(idiom=IDIOM_GRISCHUN,
direction=SEARCH_DIRECTION_DEU_RUM,
term=term,
limit=7)
sugg = suggRum + suggDeu
sugg.sort()
return sugg
registry.register(LookupDeuVal)
registry.register(LookupValDeu)
registry.register(LookupBidirVal)
registry.register(LookupDeuPut)
registry.register(LookupPutDeu)
registry.register(LookupBidirPut)
registry.register(LookupDeuGri)
registry.register(LookupGriDeu)
registry.register(LookupBidirGri)
示例12: ElementLookup
from __future__ import unicode_literals
from selectable.base import ModelLookup
from selectable.registry import registry
from .models import Element
class ElementLookup(ModelLookup):
model = Element
search_fields = ('text__icontains', )
registry.register(ElementLookup)
示例13: MediumLookup
search_fields = ('label__icontains', 'reference__icontains')
class MediumLookup(ModelLookup):
model = ContactMedium
search_fields = ('label__icontains', )
class ActivityLookup(ModelLookup):
model = ActivityNomenclature
search_fields = ('path__icontains', )
filters = {'level': settings.ACTIVITY_NOMENCLATURE_LOOKUP_LEVEL}
try:
registry.register(LocationLookup)
except LookupAlreadyRegistered:
pass
try:
registry.register(AreaLookup)
except LookupAlreadyRegistered:
pass
try:
registry.register(MediumLookup)
except LookupAlreadyRegistered:
pass
try:
registry.register(ActivityLookup)
except LookupAlreadyRegistered:
pass
示例14: RegionLookup
from selectable.base import ModelLookup
from selectable.registry import registry
from cities.models import Region
class RegionLookup(ModelLookup):
model = Region
search_fields = ('name__icontains', )
filters = {'country__code': "CA", }
def get_item_value(self, item):
return item.name
def get_item_id(self, item):
return item.id
if not 'event-regionlookup' in registry._registry:
registry.register(RegionLookup)
示例15: NeighbourhoodLookup
from selectable.base import LookupBase
from selectable.registry import registry
from .models import Neighbourhood, City
class NeighbourhoodLookup(LookupBase):
def get_query(self, request, term):
neighbourhoods = Neighbourhood.objects.all()
cities = City.objects.all()
if term.strip() != '':
neighbourhoods = neighbourhoods.filter(name__icontains=term)
cities = cities.filter(name__icontains=term)
cities = [city for city in cities]
neighbourhoods = [neighbourhood for neighbourhood in neighbourhoods]
locations = cities + neighbourhoods
return locations
registry.register(NeighbourhoodLookup)