Пример #1
0
    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
0
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'})
Пример #3
0
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'})
Пример #4
0
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'})
Пример #5
0
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'})
 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
0
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
0
from selectable.base import ModelLookup
from selectable.registry import registry
from localidade.models import Cidade


class CidadeChainedLookup(ModelLookup):
    model = Cidade
    search_fields = ('nome__icontains', )

    def get_query(self, request, term):
        results = super(CidadeChainedLookup, self).get_query(request, term)
        estado = request.GET.get('estado', '')
        if estado:
            results = results.filter(estado=estado)
        return results

    # def get_item_label(self, item):
    #     return "%s, %s" % (item.nome, item.estado)


registry.register(CidadeChainedLookup)
Пример #9
0
        for result_type, lookup in self.lookups.items():
            for item in lookup.get_query(request, q)[:10]:
                label = lookup.get_item_label(item)
                value = lookup.get_item_value(item)
                results.append(SearchResult(result_type, item, label, value))

        results.sort(key=lambda a: a.value)
        return results

    def get_item_label(self, item):
        return item.label

    def get_item_id(self, item):
        return '{0}-{1}'.format(item.result_type, item.item.pk)

    def get_item(self, value):
        try:
            result_type, pk = value.split('-', 1)
            return self.lookups[result_type].get_item(pk)
        except (ValueError, KeyError):
            return None

    def get_item_value(self, item):
        return item.value if item else ''


registry.register(BusinessLookup)
registry.register(ProjectLookup)
registry.register(UserLookup)
registry.register(QuickLookup)
Пример #10
0
    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)
Пример #11
0
        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
0
from selectable.base import ModelLookup
from selectable.registry import registry

from models import School

class SchoolLookup(ModelLookup):
    model = School
    search_field = 'name__icontains'

registry.register(SchoolLookup)
Пример #13
0
    model = models.Endpoint
    search_fields = ('name__icontains', )
    related_filter = 'assessment_id'

    def get_query(self, request, term):
        return super().get_query(request, term)\
            .distinct('name')


class EndpointIdByAssessmentLookup(EndpointByAssessmentLookup):

    def get_item_value(self, obj):
        return obj.id


registry.register(ExperimentByStudyLookup)
registry.register(AnimalGroupByExperimentLookup)
registry.register(RelatedExperimentCASLookup)
registry.register(RelatedAnimalGroupLifestageExposedLookup)
registry.register(RelatedAnimalGroupLifestageAssessedLookup)
registry.register(RelatedEndpointSystemLookup)
registry.register(RelatedEndpointOrganLookup)
registry.register(RelatedEndpointEffectLookup)
registry.register(RelatedEndpointEffectSubtypeLookup)

registry.register(ExpChemicalLookup)
registry.register(ExpCasLookup)
registry.register(ExpChemSourceLookup)
registry.register(ExpGlpLookup)
registry.register(EndpointSystemLookup)
registry.register(EndpointOrganLookup)
Пример #14
0
from selectable.base import ModelLookup
from selectable.registry import registry
from catalog.models import City, County


class CityLookup(ModelLookup):
    model = City
    search_fields = ('name__icontains', )


class CountyLookup(ModelLookup):
    model = County
    search_fields = ('name__icontains', )


registry.register(CityLookup)
registry.register(CountyLookup)

Пример #15
0
class AnimalStudyLookup(StudyLookup):
    filters = {
        'bioassay': True,
    }


class EpiStudyLookup(StudyLookup):
    filters = {
        'epi': True,
    }


class EpimetaStudyLookup(StudyLookup):
    filters = {
        'epi_meta': True,
    }


class InvitroStudyLookup(StudyLookup):
    filters = {
        'in_vitro': True,
    }


registry.register(StudyLookup)
registry.register(AnimalStudyLookup)
registry.register(EpiStudyLookup)
registry.register(EpimetaStudyLookup)
registry.register(InvitroStudyLookup)
Пример #16
0
##        """override buggy method from SelectWidget"""
##        old_values = [ unicode(i) for i in (initial or [u''])]
##        new_values = [ unicode(i) for i in (data or [u''])]
##        return not set(new_values) == set(old_values)


class DnaLookup(ModelLookup):
    """Lookup definition for selectable auto-completion fields"""
    model = M.DnaComponent
    search_fields = ('displayId__startswith', 'name__icontains')

    def get_item_id(self, item):
        return item.pk


registry.register(DnaLookup)


class OligoLookup(ModelLookup):
    model = M.OligoComponent
    search_fields = ('displayId__startswith', 'name__icontains')

    def get_item_id(self, item):
        return item.pk


registry.register(OligoLookup)


class SequencingOligoLookup(OligoLookup):
    filters = {'componentType': T.ocSequencing}
Пример #17
0
from django.contrib.admin import ModelAdmin, site, register
from django.contrib.auth.models import User

from selectable.base import ModelLookup
from selectable.forms import AutoCompleteSelectWidget, AutoCompleteSelectField
from selectable.registry import registry

from . import models


class UserLookup(ModelLookup):
    model = User
    search_fields = ('username__icontains', )


registry.register(UserLookup)


class LibraryAdminForm(forms.ModelForm):
    user = AutoCompleteSelectField(
        UserLookup,
        widget=AutoCompleteSelectWidget(UserLookup),
        required=True,
    )
    owner = AutoCompleteSelectField(
        UserLookup,
        widget=AutoCompleteSelectWidget(UserLookup),
        required=True,
    )

    class Meta(object):
Пример #18
0
from selectable.base import ModelLookup
from selectable.registry import registry
from busca.models import Busca


class BuscaLookup(ModelLookup):
    model = Busca
    search_fields = ('email__icontains', )


registry.register(BuscaLookup)
Пример #19
0
            try:
                item = Edition.objects.get(pk=value)
            except (ValueError, Edition.DoesNotExist):
                item = None
        return item

class SubjectLookup(ModelLookup):
    model = Subject
    search_fields = ('name__icontains',)

    def get_query(self, request, term):
        return super(SubjectLookup, self).get_query(
            request, term
        ).annotate(Count('works')).order_by('-works__count')

class EditionNoteLookup(ModelLookup):
    model = EditionNote
    search_fields = ('note__icontains',)
    def create_item(self, value):
        new_note, created = EditionNote.objects.get_or_create(note=value)
        new_note.save()
        return new_note

registry.register(OwnerLookup)
registry.register(WorkLookup)
registry.register(PublisherNameLookup)
registry.register(EditionLookup)
registry.register(SubjectLookup)
registry.register(EditionNoteLookup)
registry.register(EbookLookup)
Пример #20
0
from selectable.base import ModelLookup
from selectable.registry import registry

from users.models import Profile


class ProfileLookup(ModelLookup):
    model = Profile
    search_fields = (
        'name__icontains',
        'user__email__icontains',
    )

    def get_item_value(self, item):
        """Display for currently selected item"""
        return item.display_name

    def get_item_label(self, item):
        """Display for choice listings"""
        return item.display_name

    def get_queryset(self):
        qs = super(ProfileLookup, self).get_queryset()
        qs.order_by('name')
        return qs


registry.register(ProfileLookup)
Пример #21
0
from django.contrib.auth.models import User

from selectable.base import ModelLookup
from selectable.registry import registry

from example.core.models import Fruit, City


class FruitLookup(ModelLookup):
    model = Fruit
    search_fields = ('name__icontains', )

registry.register(FruitLookup)


class OwnerLookup(ModelLookup):
    model = User
    search_fields = ('username__icontains', )


registry.register(OwnerLookup)


class CityLookup(ModelLookup):
    model = City
    search_fields = ('name__icontains', )

    def get_query(self, request, term):
        results = super(CityLookup, self).get_query(request, term)
        state = request.GET.get('state', '')
        if state:
Пример #22
0
        term = functools.reduce(
            lambda x, y: re.sub(y[0], y[1], x),
            self.sub_patterns,
            term,
        )
        term = self.join_pattern.join(term)
        return super(FlexModelLookup, self).get_query(request, term)


class DepartmentLookup(ModelLookup):

    model = Department
    search_fields = ('name__icontains',)


class InstitutionLookup(FlexModelLookup):

    model = Institution
    search_fields = ('name__iregex',)
    sub_patterns = [
        ['[\s\-,]', ''],
    ]
    join_pattern = '[\s\-,]*'


for lookup in [DepartmentLookup, InstitutionLookup]:
    try:
        registry.register(lookup)
    except LookupAlreadyRegistered:
        pass
Пример #23
0
    def get_query(self, request, term):
        try:
            pk = int(request.GET.get('assessment_id'))
            self.filters = {'assessment_id': pk}
        except Exception:
            return self.model.objects.none()
        return super(EndpointByAssessmentLookup, self).get_query(request, term)

    def get_item_label(self, obj):
        return u"{} | {} | {} | {}".format(obj.animal_group.experiment.study,
                                           obj.animal_group.experiment,
                                           obj.animal_group, obj)

    def get_item_value(self, obj):
        return '<a href="{}" target="_blank">{}</a>'.format(
            obj.get_absolute_url(), self.get_item_label(obj))


registry.register(SpeciesLookup)
registry.register(StrainLookup)
registry.register(ExperimentCASLookup)
registry.register(AnimalGroupLifestageExposedLookup)
registry.register(AnimalGroupLifestageAssessedLookup)
registry.register(DoseUnitsLookup)
registry.register(EndpointSystemLookup)
registry.register(EndpointOrganLookup)
registry.register(EndpointEffectLookup)
registry.register(EndpointStatisticalTestLookup)
registry.register(EndpointByStudyLookup)
registry.register(EndpointByAssessmentLookup)
Пример #24
0
            print u'No results'
        return results
    
    def get_item_label(self, item):
        return unicode(item)
#        name_flat = ' '.join(item.givenName)
#        surname_flat = ' '.join(item.surname)
#        return u'%s %s' % (name_flat, surname_flat)
    
    def get_item_id(self, item):
        return item.id

class ValidationReportLookup(LookupBase):
    pass

registry.register(PersonLookup)
registry.register(ValidationReportLookup)

from django import forms

class MetadataForm(forms.ModelForm):
    class Meta:
        model = metadataInfoType_model
        widgets = {'metadataCreator' : AutoCompleteSelectMultipleWidget(lookup_class=PersonLookup)}

class MetadataInline(ReverseInlineModelAdmin):
    form = MetadataForm
            
class ResourceForm(forms.ModelForm):
    class Meta:
        model = resourceInfoType_model
Пример #25
0
from selectable.base import ModelLookup
from selectable.registry import registry

from nc.models import Agency


class AgencyLookup(ModelLookup):
    model = Agency
    search_fields = (
        'name__icontains',
    )

registry.register(AgencyLookup)
Пример #26
0
        for result_type, lookup in self.lookups.items():
            for item in lookup.get_query(request, q)[:10]:
                label = lookup.get_item_label(item)
                value = lookup.get_item_value(item)
                results.append(SearchResult(result_type, item, label, value))

        results.sort(key=lambda a: a.value)
        return results

    def get_item_label(self, item):
        return item.label

    def get_item_id(self, item):
        return '{0}-{1}'.format(item.result_type, item.item.pk)

    def get_item(self, value):
        try:
            result_type, pk = value.split('-', 1)
            return self.lookups[result_type].get_item(pk)
        except (ValueError, KeyError):
            return None

    def get_item_value(self, item):
        return item.value if item else ''


registry.register(BusinessLookup)
registry.register(ProjectLookup)
registry.register(UserLookup)
registry.register(QuickLookup)
Пример #27
0
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)
Пример #28
0
        return results
    def get_item_label(self, item):
        return u"%s, %s" % (item, item.parent)
    
class MeasureLookup(SimpleNameLookup):
    model = Measure    
    
class WorkTypeLookup(ModelLookup):
    model = WorkType  
    search_fields = ('name__icontains',)
    def get_query(self, request, term):
        results = super(WorkTypeLookup, self).get_query(request, term)       
        results = results.exclude(parent=None)
        return results
    def get_item_label(self, item):
        return u"%s, %s" % (item, item.parent)
    
try:
    registry.register(PartnerTypeLookup)  
    registry.register(WorkTypeLookup)
    registry.register(GearLookup)
    registry.register(QualityLookup)
    registry.register(ExperienceLookup)
    registry.register(PartnerLookup)
    registry.register(CitizenshipLookup)
    registry.register(PartnerIdLookup)
    registry.register(MeasureLookup)    
    registry.register(GoodsLookup)
    registry.register(DevProfileIdLookup)
except LookupAlreadyRegistered:
    pass      
Пример #29
0
    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
Пример #30
0
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)
Пример #31
0
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)
Пример #32
0
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)

Пример #33
0
    search_fields = ("health_outcome__icontains", )
    related_filter = "protocol__study__assessment_id"


class MetaResultExposureNameLookup(RelatedDistinctStringLookup):
    model = models.MetaResult
    distinct_field = "exposure_name"
    search_fields = ("exposure_name__icontains", )
    related_filter = "protocol__study__assessment_id"


class MetaProtocolLookup(RelatedLookup):
    model = models.MetaProtocol
    search_fields = ("name__icontains", )
    related_filter = "study__assessment_id"


class ExposureLookup(RelatedDistinctStringLookup):
    model = models.MetaResult
    distinct_field = "exposure_name"
    search_fields = ("exposure_name__icontains", )
    related_filter = "protocol__study__assessment_id"


registry.register(MetaResultByStudyLookup)
registry.register(MetaResultByAssessmentLookup)
registry.register(MetaResultHealthOutcomeLookup)
registry.register(MetaResultExposureNameLookup)
registry.register(MetaProtocolLookup)
registry.register(ExposureLookup)
Пример #34
0
from selectable.base import ModelLookup
from selectable.registry import registry, LookupAlreadyRegistered
from app import models

class BeerTypeLookup(ModelLookup):
  model = models.BeerType
  search_fields = ('name__icontains',)

class BrewerLookup(ModelLookup):
  model = models.Brewer
  search_fields = ('name__icontains',)

try:
  registry.register(BeerTypeLookup)
except LookupAlreadyRegistered:
  pass

try:
  registry.register(BrewerLookup)
except LookupAlreadyRegistered:
  pass
Пример #35
0
# -*- coding: utf-8 -*-

from selectable.base import ModelLookup
from selectable.registry import registry

from chercheurs.models import Chercheur


class ChercheurLookup(ModelLookup):
    model = Chercheur
    search_field = 'nom__icontains'

registry.register(ChercheurLookup)
Пример #36
0
            obj.animal_group.experiment.study,
            obj.animal_group.experiment,
            obj.animal_group,
            obj
        )

    def get_item_value(self, obj):
        return self.get_item_label(obj)


class EndpointByAssessmentLookupHtml(EndpointByAssessmentLookup):

    def get_item_value(self, obj):
        return '<a href="{}" target="_blank">{}</a>'.format(
            obj.get_absolute_url(),
            self.get_item_label(obj)
        )


registry.register(ExperimentCASLookup)
registry.register(AnimalGroupLifestageExposedLookup)
registry.register(AnimalGroupLifestageAssessedLookup)
registry.register(EndpointSystemLookup)
registry.register(EndpointOrganLookup)
registry.register(EndpointEffectLookup)
registry.register(EndpointEffectSubtypeLookup)
registry.register(EndpointStatisticalTestLookup)
registry.register(EndpointByStudyLookup)
registry.register(EndpointByAssessmentLookup)
registry.register(EndpointByAssessmentLookupHtml)
Пример #37
0
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)
Пример #38
0
from selectable.base import ModelLookup
from selectable.registry import registry

from .models import Taxonomy


class TaxonomyLookup(ModelLookup):
    model = Taxonomy
    search_fields = ('name__icontains', )

registry.register(TaxonomyLookup)
Пример #39
0
            return self.model.objects.none()
        return super(EndpointByAssessmentLookup, self).get_query(request, term)

    def get_item_label(self, obj):
        return u"{} | {} | {} | {}".format(
            obj.animal_group.experiment.study,
            obj.animal_group.experiment,
            obj.animal_group,
            obj
        )

    def get_item_value(self, obj):
        return '<a href="{}" target="_blank">{}</a>'.format(
            obj.get_absolute_url(),
            self.get_item_label(obj)
        )


registry.register(SpeciesLookup)
registry.register(StrainLookup)
registry.register(ExperimentCASLookup)
registry.register(AnimalGroupLifestageExposedLookup)
registry.register(AnimalGroupLifestageAssessedLookup)
registry.register(DoseUnitsLookup)
registry.register(EndpointSystemLookup)
registry.register(EndpointOrganLookup)
registry.register(EndpointEffectLookup)
registry.register(EndpointStatisticalTestLookup)
registry.register(EndpointByStudyLookup)
registry.register(EndpointByAssessmentLookup)
Пример #40
0
from selectable.base import ModelLookup
from selectable.registry import registry

from .models import User


class UserLookup(ModelLookup):
    model = User
    search_fields = ('email__icontains', 'name__icontains')

registry.register(UserLookup)
Пример #41
0
from django.contrib.auth.models import User

from selectable.base import ModelLookup
from selectable.registry import registry

from core.models import Fruit, City


class FruitLookup(ModelLookup):
    model = Fruit
    search_fields = ('name__icontains', )


registry.register(FruitLookup)


class OwnerLookup(ModelLookup):
    model = User
    search_fields = ('username__icontains', )


registry.register(OwnerLookup)


class CityLookup(ModelLookup):
    model = City
    search_fields = ('name__icontains', )

    def get_query(self, request, term):
        results = super().get_query(request, term)
        state = request.GET.get('state', '')