class GenericMembershipDocument:
    autocomplete = TextField(attr="name", analyzer=autocomplete_analyzer)
    sort_date = DateField()

    body = ObjectField(properties={"id": IntegerField(), "name": TextField()})

    class Meta:
        fields = ["id", "name", "short_name"]
Example #2
0
class GenericMembershipDocument:
    autocomplete = TextField(attr="name", analyzer=autocomplete_analyzer)
    sort_date = DateField()

    body = ObjectField(properties={"id": IntegerField(), "name": TextField()})

    class Django:
        fields = ["id", "name", "short_name"]
        queryset_pagination = settings.ELASTICSEARCH_QUERYSET_PAGINATION
Example #3
0
class GenericMembershipDocument:
    autocomplete = StringField(attr="name", analyzer=autocomplete_analyzer)
    sort_date = DateField()

    body = ObjectField(properties={
        'id': IntegerField(),
        'name': StringField(),
    })

    class Meta:
        fields = ['id', 'name', 'short_name']
class OrganizationDocument(DocType, GenericMembershipDocument):
    autocomplete = TextField(attr="name", analyzer=autocomplete_analyzer)
    sort_date = DateField()
    body = ObjectField(properties={"id": IntegerField(), "name": TextField()})

    def get_queryset(self):
        return Organization.objects.prefetch_related("body").order_by("id")

    class Meta(GenericMembershipDocument.Meta):
        model = Organization
        queryset_pagination = 500

        fields = [
            "id", "name", "short_name", "start", "end", "created", "modified"
        ]
Example #5
0
class OrganizationDocument(Document, GenericMembershipDocument):
    autocomplete = TextField(attr="name", analyzer=autocomplete_analyzer)
    sort_date = DateField()
    body = ObjectField(properties={"id": IntegerField(), "name": TextField()})

    def get_queryset(self):
        return Organization.objects.prefetch_related("body").order_by("id")

    class Index:
        name = settings.ELASTICSEARCH_PREFIX + "-organization"

    class Django(GenericMembershipDocument.Django):
        model = Organization
        queryset_pagination = settings.ELASTICSEARCH_QUERYSET_PAGINATION

        fields = [
            "id", "name", "short_name", "start", "end", "created", "modified"
        ]
class OrganizationDocument(DocType, GenericMembershipDocument):
    autocomplete = StringField(attr="name", analyzer=autocomplete_analyzer)
    sort_date = DateField(attr="sort_date")

    body = ObjectField(properties={
        'id': IntegerField(),
        'name': StringField(),
    })

    class Meta(GenericMembershipDocument.Meta):
        model = Organization

        fields = [
            'id',
            'name',
            'short_name',
            'start',
            'end',
            'created',
            'modified',
        ]
class PropertyDocument(Document):
    """Property Elasticsearch document."""

    id = IntegerField(attr="id")
    propertyName = TextField()
    landlord = TextField(attr="user_indexing", )
    numberOfBedrooms = IntegerField()
    numberOfBathrooms = IntegerField()
    propertyType = TextField()
    availableFrom = DateField()
    listingDescription = TextField()
    unit = IntegerField()
    size = FloatField()
    propertyStatus = TextField()
    monthlyRent = FloatField()
    securityDeposit = FloatField()
    created_at = DateField()
    propertyRules = ObjectField(
        properties={
            PROPERTY: TextField(attr="property_indexing", ),
            PropertyRules.SMOKING: BooleanField(),
            PropertyRules.PET: BooleanField(),
            PropertyRules.MUSICAL_INSTRUMENTS: BooleanField(),
        })
    propertyAddress = ObjectField(
        properties={
            PROPERTY: TextField(attr="property_indexing", ),
            PropertyAddress.ADDRESS: TextField(),
            PropertyAddress.STATE_NAME: TextField(),
            PropertyAddress.LATITUDE: FloatField(),
            PropertyAddress.LONGITUDE: FloatField(),
        })
    propertyAmenities = ObjectField(
        properties={
            PROPERTY: TextField(attr="property_indexing", ),
            PropertyAmenities.POOL: BooleanField(),
            PropertyAmenities.GARDEN: BooleanField(),
            PropertyAmenities.ELEVATOR: BooleanField(),
            PropertyAmenities.DOORMAN: BooleanField(),
            PropertyAmenities.DECK: BooleanField(),
            PropertyAmenities.WASHER: BooleanField(),
            PropertyAmenities.GYM: BooleanField(),
            PropertyAmenities.PARKING: BooleanField(),
            PropertyAmenities.FIRE_PLACE: BooleanField(),
            PropertyAmenities.AIR_CONDITION: BooleanField(),
            PropertyAmenities.DISH_WASHER: BooleanField(),
            PropertyAmenities.ITEM_STORAGE: BooleanField(),
            PropertyAmenities.WHEELCHAIR: BooleanField(),
            PropertyAmenities.BALCONY: BooleanField(),
            PropertyAmenities.HARD_FLOOR: BooleanField(),
            PropertyAmenities.FURNISHED: BooleanField(),
            PropertyAmenities.VIEW: BooleanField(),
            PropertyAmenities.HIGH_RISE: BooleanField(),
            PropertyAmenities.STUDENT_FRIENDLY: BooleanField(),
            PropertyAmenities.UTILITIES: BooleanField(),
        })
    propertyImage = ObjectField(
        properties={
            ID: IntegerField(attr="id"),
            PROPERTY: TextField(attr="property_indexing", ),
            PropertyImage.IMAGE: FileField(),
        })

    class Django(object):
        """The Django model associate with this Document"""

        model = Property
Example #8
0
class ContactDoc(DocType):
    accounts = ObjectField(properties={
        'id':
        IntegerField(),
        'name':
        CharField(),
        'phone_numbers':
        PhoneNumberField(related_model=PhoneNumber),
    },
                           related_model=Account)
    description = CharField()
    email_addresses = EmailAddressField(related_model=EmailAddress)
    full_name = CharField()
    phone_numbers = PhoneNumberField(related_model=PhoneNumber)
    tags = CharField(related_model=Tag)
    tenant_id = IntegerField()

    def get_queryset(self):
        return Contact.objects.prefetch_related('email_addresses',
                                                'phone_numbers', 'tags')

    def prepare_accounts(self, obj):
        functions = obj.functions.filter(
            account__is_deleted=False).select_related(
                'account').prefetch_related('account__phone_numbers')

        return [self._convert_function_to_account(func) for func in functions]

    def _convert_function_to_account(self, func):
        return {
            'id':
            func.account_id,
            'name':
            func.account.name if func.account.name else '',
            'phone_numbers': [
                phone_number.number
                for phone_number in func.account.phone_numbers.all()
            ],
        }

    def prepare_email_addresses(self, obj):
        return [email.email_address for email in obj.email_addresses.all()]

    def prepare_phone_numbers(self, obj):
        return [
            phone_number.number for phone_number in obj.phone_numbers.all()
        ]

    def prepare_tags(self, obj):
        return [tag.name for tag in obj.tags.all()]

    def get_instances_from_accounts(self, account):
        return account.contacts.all()

    def get_instances_from_accounts_phone_numbers(self, phone_number):
        return Contact.objects.filter(accounts__phone_numbers=phone_number)

    def get_instances_from_email_addresses(self, email_address):
        return email_address.contact_set.all()

    def get_instances_from_phone_numbers(self, phone_number):
        return phone_number.contact_set.all()

    def get_instances_from_tags(self, tag):
        if tag.content_type.model == 'contact':
            return Contact.objects.get(pk=tag.object_id)

    class Meta:
        model = Contact