class PaperDocument(Document):
    autocomplete = TextField(attr="get_autocomplete",
                             analyzer=autocomplete_analyzer)
    main_file = IntegerField(attr="main_file_id")
    person_ids = IntegerField(attr="person_ids")
    organization_ids = IntegerField(attr="organization_ids")

    def get_queryset(self):
        return (Paper.objects.prefetch_related("persons").prefetch_related(
            "organizations").order_by("id"))

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

    class Django:
        model = Paper
        queryset_pagination = settings.ELASTICSEARCH_QUERYSET_PAGINATION

        fields = [
            "id",
            "short_name",
            "legal_date",
            "created",
            "name",
            "reference_number",
            "modified",
            "sort_date",
            "display_date",
        ]
Ejemplo n.º 2
0
class PaperDocument(DocType):
    autocomplete = TextField(attr="get_autocomplete", analyzer=autocomplete_analyzer)
    main_file = IntegerField(attr="main_file_id")
    person_ids = IntegerField(attr="person_ids")
    organization_ids = IntegerField(attr="organization_ids")

    def get_queryset(self):
        return (
            Paper.objects.prefetch_related("persons")
            .prefetch_related("organizations")
            .order_by("id")
        )

    class Meta:
        model = Paper
        queryset_pagination = 500

        fields = [
            "id",
            "short_name",
            "legal_date",
            "created",
            "name",
            "reference_number",
            "modified",
            "sort_date",
        ]
Ejemplo n.º 3
0
class ElasticFileDocument(Document):
    office_id = IntegerField()
    first_crawl_epoch = IntegerField()
    web_domains = KeywordField()

    class Django:
        model = Source_Document
        fields = [
            'id', 'intersection_status', 'min_income_year', 'max_income_year',
            'section_count', 'sha256'
        ]
Ejemplo n.º 4
0
class ElasticSectionDocument(Document):
    default_field_name = "person_name"
    source_document_id = IntegerField()
    office_id = IntegerField()

    class Django:
        model = Section
        fields = ['id', 'person_name', 'position', 'department']

    def prepare_source_document_id(self, instance):
        return instance.source_document_id

    def prepare_office_id(self, instance):
        return instance.source_document.office.id
Ejemplo n.º 5
0
class ElasticOfficeDocument(Document):
    default_field_name = "name"
    parent_id = IntegerField()
    source_document_count = IntegerField()
    region_id = IntegerField()

    class Django:
        model = Office
        fields = ['id', 'name', 'rubric_id']

    @property
    def rubric_str(self):
        if self.rubric_id is None:
            return "unknown"
        else:
            return get_russian_rubric_str(self.rubric_id)
Ejemplo n.º 6
0
class PersonDocument(DocType):
    autocomplete = TextField(attr="name_autocomplete", analyzer=autocomplete_analyzer)
    sort_date = DateField()
    organization_ids = IntegerField(attr="organization_ids")

    def get_queryset(self):
        sort_date_queryset = Membership.objects.filter(start__isnull=False).order_by(
            "-start"
        )

        return (
            Person.objects.order_by("id")
            .prefetch_related("membership_set")
            .prefetch_related(
                Prefetch(
                    "membership_set",
                    queryset=sort_date_queryset,
                    to_attr="sort_date_prefetch",
                )
            )
        )

    class Meta:
        model = Person
        queryset_pagination = 500

        fields = ["id", "name", "given_name", "family_name"]
class FileDocument(Document):
    autocomplete = TextField(attr="name_autocomplete",
                             analyzer=autocomplete_analyzer)
    coordinates = GeoPointField(attr="coordinates")
    person_ids = IntegerField(attr="person_ids")
    description = TextField(attr="description", analyzer=text_analyzer)
    # Elasticsearch wants `index_options: "offsets"` for the highlighter for large texts
    parsed_text = TextField(attr="parsed_text",
                            analyzer=text_analyzer,
                            index_options="offsets")

    def get_queryset(self):
        return (File.objects.prefetch_related("locations").prefetch_related(
            "mentioned_persons").order_by("id"))

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

    class Django:
        model = File
        queryset_pagination = settings.ELASTICSEARCH_QUERYSET_PAGINATION

        fields = [
            "id",
            "name",
            "filename",
            "page_count",
            "created",
            "modified",
            "sort_date",
        ]
Ejemplo n.º 8
0
class MeetingDocument(DocType):
    location = GeoPointField()
    sort_date = DateField()

    agenda_items = NestedField(
        attr="agendaitem_set",
        properties={
            "key": TextField(),
            "name": TextField(analyzer=text_analyzer),
            "position": IntegerField(),
            "public": BooleanField(),
        },
    )

    @staticmethod
    def prepare_location(instance: Meeting) -> Optional[Dict[str, Any]]:
        if instance.location:
            return instance.location.coordinates()

    def get_queryset(self):
        return (Meeting.objects.prefetch_related(
            "agendaitem_set").prefetch_related("location").order_by("id"))

    class Meta:
        model = Meeting
        queryset_pagination = 500

        fields = [
            "id", "name", "short_name", "start", "end", "created", "modified"
        ]
Ejemplo n.º 9
0
class MeetingDocument(DocType):
    location = GeoPointField()
    sort_date = DateField()

    agenda_items = NestedField(attr="agendaitem_set",
                               properties={
                                   "key": StringField(),
                                   "title": StringField(),
                                   "position": IntegerField(),
                                   "public": BooleanField(),
                               })

    @staticmethod
    def prepare_location(instance: Meeting):
        if instance.location:
            return instance.location.coordinates()

    class Meta:
        model = Meeting

        fields = [
            'id',
            'name',
            'short_name',
            'start',
            'end',
            'created',
            'modified',
        ]
Ejemplo n.º 10
0
class FileDocument(DocType):
    autocomplete = TextField(attr="name_autocomplete", analyzer=autocomplete_analyzer)
    coordinates = GeoPointField(attr="coordinates")
    person_ids = IntegerField(attr="person_ids")
    description = TextField(attr="description", analyzer=text_analyzer)
    # Elasticsearch wants `index_options: "offsets"` for the highlighter for large texts
    parsed_text = TextField(
        attr="parsed_text", analyzer=text_analyzer, index_options="offsets"
    )

    def get_queryset(self):
        return (
            File.objects.prefetch_related("locations")
            .prefetch_related("mentioned_persons")
            .order_by("id")
        )

    class Meta:
        model = File
        queryset_pagination = 500

        fields = [
            "id",
            "name",
            "filename",
            "page_count",
            "created",
            "modified",
            "sort_date",
        ]
class PersonDocument(Document):
    autocomplete = TextField(attr="name_autocomplete",
                             analyzer=autocomplete_analyzer)
    sort_date = DateField()
    organization_ids = IntegerField(attr="organization_ids")

    def get_queryset(self):
        sort_date_queryset = Membership.objects.filter(
            start__isnull=False).order_by("-start")

        return (Person.objects.order_by("id").prefetch_related(
            "membership_set").prefetch_related(
                Prefetch(
                    "membership_set",
                    queryset=sort_date_queryset,
                    to_attr="sort_date_prefetch",
                )))

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

    class Django:
        model = Person
        queryset_pagination = settings.ELASTICSEARCH_QUERYSET_PAGINATION

        fields = ["id", "name", "given_name", "family_name"]
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"]
Ejemplo n.º 13
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
Ejemplo n.º 14
0
class ElasticPersonDocument(Document):
    default_field_name = "person_name"
    section_count = IntegerField()

    class Django:
        model = Person
        fields = [
            'id',
            'person_name',
        ]
Ejemplo n.º 15
0
class PaperDocument(DocType):
    autocomplete = StringField(attr="get_autocomplete",
                               analyzer=autocomplete_analyzer)
    main_file = IntegerField(attr="main_file_id")
    person_ids = IntegerField(attr="person_ids")
    organization_ids = IntegerField(attr="organization_ids")

    class Meta:
        model = Paper

        fields = [
            'id',
            'name',
            'short_name',
            'description',
            'legal_date',
            'created',
            'modified',
            'sort_date',
        ]
Ejemplo n.º 16
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']
Ejemplo n.º 17
0
class ElasticOfficeDocument(Document):
    default_field_name = "name"
    parent_id = IntegerField()

    class Django:
        model = Office
        fields = [
            'id',
            'name',
        ]

    def prepare_parent_id(self, instance):
        return instance.parent_id
Ejemplo n.º 18
0
class ElasticFileDocument(Document):
    office_id = IntegerField()
    default_field_name = "file_path"

    class Django:
        model = Source_Document
        fields = [
            'id',
            'file_path',
        ]

    def prepare_office_id(self, instance):
        return instance.office_id
Ejemplo n.º 19
0
class PersonDocument(DocType):
    autocomplete = StringField(attr="name_autocomplete",
                               analyzer=autocomplete_analyzer)
    sort_date = DateField()
    organization_ids = IntegerField(attr="organization_ids")

    class Meta:
        model = Person

        fields = [
            'id',
            'name',
            'given_name',
            'family_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"
        ]
Ejemplo n.º 21
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"
        ]
Ejemplo n.º 22
0
class PaperDocument(DocType):
    # FIXME: Name should also autocomplete. Maybe add an extra negative bias
    # autocomplete_name = StringField(attr="name", analyzer=autocomplete_analyzer)
    autocomplete = StringField(attr="reference_number_autocomplete",
                               analyzer=autocomplete_analyzer)
    main_file = IntegerField(attr="main_file_id")

    class Meta:
        model = Paper

        fields = [
            'id',
            'name',
            'short_name',
            'description',
            'legal_date',
            'created',
            'modified',
        ]
Ejemplo n.º 23
0
class FileDocument(DocType):
    autocomplete = StringField(attr="name_autocomplete",
                               analyzer=autocomplete_analyzer)
    coordinates = GeoPointField(attr="coordinates")
    person_ids = IntegerField(attr="person_ids")

    class Meta:
        model = File

        fields = [
            'id',
            'name',
            'description',
            'displayed_filename',
            'page_count',
            'parsed_text',
            'created',
            'modified',
            'sort_date',
        ]
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',
        ]
Ejemplo n.º 25
0
class ElasticSectionDocument(Document):
    default_field_name = "person_name"
    source_document_id = IntegerField()
    office_id = IntegerField()
    position_and_department = TextField()
    income_size = IntegerField()
    spouse_income_size = IntegerField()
    person_id = IntegerField()
    region_id = IntegerField()
    car_brands = KeywordField()

    class Django:
        model = Section
        fields = ['id', 'person_name', 'income_year', 'rubric_id', 'gender']

    @property
    def rubric_str(self):
        if self.rubric_id is None:
            return "unknown"
        else:
            return get_russian_rubric_str(self.rubric_id)
Ejemplo n.º 26
0
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
Ejemplo n.º 27
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