コード例 #1
0
class SkillDocument(DocType):
    title = fields.StringField(analyzer=title_analyzer)

    def prepare_title(self, instance):
        return instance.name

    class Meta:
        model = Skill
        fields = ['name', 'description', 'is_published']
コード例 #2
0
class ManufacturerDocument(DocType):
    country = fields.StringField()

    class Meta:
        model = Manufacturer
        fields = [
            'name',
            'created',
            'country_code',
        ]
コード例 #3
0
ファイル: documents.py プロジェクト: protostartup/djsaleor
class OrderDocument(DocType):
    user = fields.StringField(analyzer=email_analyzer)

    def prepare_user(self, instance):
        if instance.user:
            return instance.user.email
        return instance.user_email

    class Meta:
        model = Order
        fields = ['user_email', 'discount_name']
コード例 #4
0
class ContactDocument(DocType):
    full_name = fields.TextField(
        attr='_get_fullname',
        fields={
            'raw': fields.StringField(analyzer='keyword'),
            'suggest': fields.CompletionField(attr='_get_fullname')
        })

    class Meta:
        model = Contact
        fields = ['first_name', 'last_name']
コード例 #5
0
class ArticleDocument(DocType):
    """Article elasticsearch document"""

    id = fields.IntegerField(attr='id')
    title = fields.StringField(analyzer=html_strip,
                               fields={
                                   'raw':
                                   fields.StringField(analyzer='keyword'),
                               })
    body = fields.TextField(analyzer=html_strip,
                            fields={
                                'raw': fields.TextField(analyzer='keyword'),
                            })
    author = fields.IntegerField(attr='author_id')
    created = fields.DateField()
    modified = fields.DateField()
    pub_date = fields.DateField()

    class Meta:
        model = articles_models.Article
コード例 #6
0
class DataFileDocument(Document):
    class Index:
        name = 'datafile'
        settings = {'number_of_shards': 1, 'number_of_replicas': 0}

    filename = fields.TextField(fields={'raw': fields.KeywordField()},
                                analyzer=analyzer)
    created_time = fields.DateField()
    modification_time = fields.DateField()
    dataset = fields.NestedField(
        properties={
            'id':
            fields.IntegerField(),
            'experiments':
            fields.NestedField(
                properties={
                    'id':
                    fields.IntegerField(),
                    'objectacls':
                    fields.ObjectField(
                        properties={
                            'pluginId': fields.StringField(),
                            'entityId': fields.StringField()
                        }),
                    'public_access':
                    fields.IntegerField()
                }),
        })

    class Django:
        model = DataFile
        related_models = [Dataset, Experiment]
        queryset_pagination = 100000

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, Dataset):
            return related_instance.datafile_set.all()
        if isinstance(related_instance, Experiment):
            return DataFile.objects.filter(
                dataset__experiments=related_instance)
        return None
コード例 #7
0
class UserDocument(DocType):
    user = fields.StringField(analyzer=email_analyzer)
    first_name = fields.StringField()
    last_name = fields.StringField()

    def prepare_user(self, instance):
        return instance.email

    def prepare_first_name(self, instance):
        address = instance.default_billing_address
        if address:
            return address.first_name

    def prepare_last_name(self, instance):
        address = instance.default_billing_address
        if address:
            return address.last_name

    class Meta:
        model = User
        fields = ['email']
コード例 #8
0
class NoteDocument(DocType):
    """
    Using decorator create the notedocument class
    which describe the fields of note model
    """
    title = fields.StringField(
        analyzer=html_strip,
        fields={
            'raw': fields.StringField(analyzer='keyword'),
        }
    )
    description = fields.TextField(
        analyzer=html_strip,
        fields={
            'raw': fields.TextField(analyzer='keyword'),
        }
    )

    color = fields.StringField(
       analyzer=html_strip,
     fields={
         'raw': fields.StringField(analyzer='keyword'),
     }
     )
    reminder = fields.StringField(
        analyzer=html_strip,
        fields={
            'raw': fields.StringField(analyzer='keyword'),
        }
    )

    # defining the meta class
    class Meta(object):
        model = Note
コード例 #9
0
class CarDocument(DocType):
    # test can override __init__
    def __init__(self, *args, **kwargs):
        super(CarDocument, self).__init__(*args, **kwargs)

    manufacturer = fields.ObjectField(properties={
        'name': fields.StringField(),
        'country': fields.StringField(),
    })

    ads = fields.NestedField(
        properties={
            'description': fields.StringField(analyzer=html_strip),
            'title': fields.StringField(),
            'pk': fields.IntegerField(),
        })

    categories = fields.NestedField(
        properties={
            'title': fields.StringField(),
            'slug': fields.StringField(),
            'icon': fields.FileField(),
        })

    class Meta:
        model = Car
        fields = [
            'name',
            'launched',
            'type',
        ]

    def get_queryset(self):
        return super(CarDocument,
                     self).get_queryset().select_related('manufacturer')
コード例 #10
0
class JobDocument(DocType):
    # ID
    id = fields.IntegerField(attr='id')
    title = StringField(analyzer=html_strip, fields={
        'raw': KeywordField(),
    })
    description = fields.TextField()
    have_daily_perks = fields.BooleanField()
    daily_perks_budget = fields.DoubleField()
    have_transportation = fields.BooleanField()
    transportation_budget = fields.DoubleField()
    have_meal = fields.BooleanField()
    meal_budget = fields.DoubleField()
    have_space_rest = fields.BooleanField()
    space_rest_budget = fields.DoubleField()
    is_male = fields.BooleanField()
    is_female = fields.BooleanField()
    age = fields.IntegerField()
    hide_company = fields.BooleanField()
    latitude = fields.GeoPointField()
    longitude = fields.GeoPointField()
    slug = fields.StringField()
    publish_date = fields.DateField()

    tags = fields.ObjectField(attr='tag_field_indexing',
                              properties={
                                  'id': fields.IntegerField(),
                                  'name': fields.StringField()
                              })

    company = fields.ObjectField(attr='company_indexing',
                                 properties={
                                     'name': fields.StringField(),
                                     'avatar': fields.StringField(),
                                     'slug': fields.StringField(),
                                     'pk': fields.IntegerField()
                                 })

    class Django:
        model = Job
コード例 #11
0
class NoteDocument(Document):
    """Note Elastic search document."""
    class Django:
        model = Note

    id = fields.StringField(attr='id', analyzer="standard")

    title = fields.StringField(fields={
        'raw': fields.KeywordField(),
    })

    user = fields.StringField(attr='user_indexing',
                              fields={
                                  'raw': fields.KeywordField(),
                              })
    content = fields.StringField(fields={
        'raw': fields.KeywordField(),
    })

    label = fields.StringField(attr='label_indexing',
                               fields={'raw': fields.KeywordField()})

    collaborator = fields.StringField(attr='collaborator_indexing',
                                      fields={
                                          'raw': fields.KeywordField(),
                                      })
    is_archive = fields.BooleanField()
    is_pin = fields.BooleanField()
    is_trash = fields.BooleanField()
    reminder = fields.DateField()
コード例 #12
0
class DatasetDocument(Document):
    class Index:
        name = 'dataset'
        settings = {'number_of_shards': 1, 'number_of_replicas': 0}

    id = fields.IntegerField()
    description = fields.TextField(fields={'raw': fields.KeywordField()},
                                   analyzer=analyzer)
    experiments = fields.NestedField(
        properties={
            'id':
            fields.IntegerField(),
            'title':
            fields.TextField(fields={'raw': fields.KeywordField()}),
            'objectacls':
            fields.ObjectField(properties={
                'pluginId': fields.StringField(),
                'entityId': fields.StringField()
            }),
            'public_access':
            fields.IntegerField()
        })
    instrument = fields.ObjectField(
        properties={
            'id': fields.IntegerField(),
            'name': fields.TextField(fields={'raw': fields.KeywordField()}, )
        })
    created_time = fields.DateField()
    modified_time = fields.DateField()

    class Django:
        model = Dataset
        related_models = [Experiment, Instrument]

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, Experiment):
            return related_instance.datasets.all()
        if isinstance(related_instance, Instrument):
            return related_instance.dataset_set.all()
        return None
コード例 #13
0
class CarWithPrepareDocument(DocType):
    manufacturer = fields.ObjectField(properties={
        'name': fields.StringField(),
        'country': fields.StringField(),
    })

    manufacturer_short = fields.ObjectField(properties={
        'name': fields.StringField(),
    })

    class Django:
        model = Car
        related_models = [Manufacturer]
        fields = [
            'name',
            'launched',
            'type',
        ]

    class Index:
        name = 'car_with_prepare_index'

    def prepare_manufacturer_with_related(self, car, related_to_ignore):
        if (car.manufacturer is not None and car.manufacturer !=
                related_to_ignore):
            return {
                'name': car.manufacturer.name,
                'country': car.manufacturer.country(),
            }
        return {}

    def prepare_manufacturer_short(self, car):
        if car.manufacturer is not None:
            return {
                'name': car.manufacturer.name,
            }
        return {}

    def get_instances_from_related(self, related_instance):
        return related_instance.car_set.all()
コード例 #14
0
class AcceptedDatasetSubmissionDoc(Document):
    id = fields.IntegerField()
    is_active = fields.BooleanField()
    title = TranslatedTextField('title')
    notes = TranslatedTextField('notes')
    organization_name = TranslatedTextField('organization_name')
    potential_possibilities = TranslatedTextField('potential_possibilities')
    data_link = fields.TextField()
    comment = fields.TextField()
    submission_date = fields.DateField()
    decision = fields.TextField()
    decision_date = fields.DateField()
    published_at = fields.DateField()
    is_published_for_all = fields.BooleanField()

    feedback = fields.NestedField(properties={
        'user_id': fields.IntegerField(),
        'opinion': fields.StringField()
    })
    feedback_counters = fields.NestedField(properties={
        'plus': fields.IntegerField(),
        'minus': fields.IntegerField(),
    })

    status = fields.TextField()

    def prepare_feedback(self, instance):
        return [{
            'user_id': fb.user.id,
            'opinion': fb.opinion
        } for fb in instance.feedback.all()]

    def prepare_feedback_counters(self, instance):
        return instance.feedback_counters

    class Index:
        name = mcs.ELASTICSEARCH_INDEX_NAMES['accepted_dataset_submissions']
        settings = mcs.ELASTICSEARCH_DSL_INDEX_SETTINGS

    class Django:
        model = AcceptedDatasetSubmission
        related_models = [
            SubmissionFeedback,
        ]

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, SubmissionFeedback):
            return related_instance.submission

    def get_queryset(self):
        return super().get_queryset().filter(
            status__in=AcceptedDatasetSubmission.PUBLISHED_STATUSES)
コード例 #15
0
class CarDocument(DocType):
    color = fields.TextField()
    type = fields.StringField()

    def prepare_color(self, instance):
        return "blue"

    class Meta:
        fields = ['name', 'price']
        model = Car
        index = 'car_index'
        related_models = [Manufacturer]
        doc_type = 'car_document'
コード例 #16
0
class PackageDocument(DocType):
    # manager = fields.TextField(attr='_get_manager_product')
    package_name = fields.TextField(attr='_get_package_name',
                                    fields={
                                        'raw': fields.StringField(analyzer='keyword'),
                                        'suggest': fields.CompletionField(attr='_get_package_name')
                                        #  contexts=[{"name": "manager", "type": "category", "path": "manager"}]),
                                    }
                                    )

    class Meta:
        model = Package
        fields = ['name']
コード例 #17
0
def keyword_field(**kwargs):
    """Keyword field.

    :param kwargs:
    :return:
    """
    major = get_elasticsearch_version()[0]
    if major > 2:
        return fields.KeywordField(**kwargs)
    else:
        if 'analyzer' not in kwargs:
            kwargs['analyzer'] = 'keyword'
        return fields.StringField(**kwargs)
コード例 #18
0
class InterventionDocument(DocType):
    pk = fields.IntegerField()
    #category =  string_field('category_key')

    category = fields.StringField(attr='category_key',
                                  fields={
                                      'raw':
                                      fields.StringField(analyzer='keyword'),
                                  })

    choice = string_field('choice')
    application = string_field('application')
    time_unit = string_field('time_unit')
    time = fields.FloatField()
    substance = ObjectField(properties={'name': string_field('name')})
    study = string_field('study')
    route = string_field('route')
    form = string_field('form')
    name = string_field('name')
    normed = fields.BooleanField()
    raw = ObjectField(properties={'pk': fields.IntegerField()})
    value = fields.FloatField()
    mean = fields.FloatField()
    median = fields.FloatField()
    min = fields.FloatField()
    max = fields.FloatField()
    se = fields.FloatField()
    sd = fields.FloatField()
    cv = fields.FloatField()
    unit = string_field('unit')

    class Meta(object):
        model = Intervention
        # Ignore auto updating of Elasticsearch when a model is saved
        # or deleted:
        ignore_signals = True
        # Don't perform an index refresh after every update (overrides global setting):
        auto_refresh = False
コード例 #19
0
ファイル: documents.py プロジェクト: Mariya-Skakalina/vp
class PublicDocument(DocType):
    context = fields.TextField(attr="ctx")
    section = fields.ObjectField(properties={
        'name': fields.StringField(analyzer=html_strip),
    })
    # section = fields.ObjectField(properties={
    #     'to_dict': fields.ObjectField()
    # })
    author = fields.ObjectField(properties={
        'nickname': fields.StringField(analyzer=html_strip),
    })
    topic_public = fields.ObjectField(properties={
        'title': fields.StringField(analyzer=html_strip),
        'id': fields.IntegerField()
    },attr='topic_public')

    class Meta:
        model = Public
        related_models = [Section,Topic]
        fields = [
            'title',
            'id',
            'publication'
        ]

        queryset_pagination = 20


    def get_instances_from_related(self, related_instance):
        """If related_models is set, define how to retrieve the Car instance(s) from the related model.
        The related_models option should be used with caution because it can lead in the index
        to the updating of a lot of items.
        """
        print(related_instance)
        if isinstance(related_instance, Topic):
            return related_instance.public_set.all()
        elif isinstance(related_instance, Section):
            return related_instance.public_set.all()
コード例 #20
0
class CarDocument(DocType):
    manufacturer = fields.ObjectField(
        properties={
            'name': fields.StringField(),
            'country': fields.StringField(),
            'logo': fields.FileField(),
        })

    ads = fields.NestedField(
        properties={
            'description': fields.StringField(analyzer=html_strip),
            'title': fields.StringField(),
            'pk': fields.IntegerField(),
        })

    categories = fields.NestedField(properties={
        'title': fields.StringField(),
    })

    class Meta:
        model = Car
        related_models = [Ad, Manufacturer, Category]
        fields = [
            'name',
            'launched',
            'type',
        ]

    def get_queryset(self):
        return super(CarDocument,
                     self).get_queryset().select_related('manufacturer')

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, Ad):
            return related_instance.car

        # otherwise it's a Manufacturer or a Category
        return related_instance.car_set.all()
コード例 #21
0
class CarDocument(DocType):
    manufacturer = fields.ObjectField(properties={
        'name': fields.StringField(),
        'country': fields.StringField(),
    })

    ads = fields.NestedField(properties={
        'description': fields.StringField(analyzer=html_strip),
        'title': fields.StringField(),
        'pk': fields.IntegerField(),
    })

    class Meta:
        model = Car
        fields = [
            'name',
            'launched',
            'type',
        ]

    def get_queryset(self):
        return super(CarDocument, self).get_queryset().select_related(
            'manufacturer')
コード例 #22
0
ファイル: documents.py プロジェクト: pooog90001/fance-gates
class OrderDocument(DocType):
    user = fields.StringField(analyzer=email_analyzer)
    first_name = fields.StringField()
    last_name = fields.StringField()

    def prepare_user(self, instance):
        if instance.user:
            return instance.user.email
        return instance.user_email

    def prepare_first_name(self, instance):
        if instance.user:
            return get_user_first_name(instance.user)
        return None

    def prepare_last_name(self, instance):
        if instance.user:
            return get_user_last_name(instance.user)
        return None

    class Meta:
        model = Order
        fields = ['user_email', 'discount_name']
コード例 #23
0
class CourseDocument(DocType):

    title = fields.StringField(
        attr='course_title',
        fields={
            'raw': fields.StringField(analyzer='keyword'),
            'suggest': fields.Completion(),
        }
    )

    course_level = fields.StringField(
        attr='level',
        fields={
            'raw': fields.StringField(analyzer='keyword'),
        }
    )

    class Meta:
        model = Course
        fields = [
            'id',
            'course_title',
            'level'
        ]
コード例 #24
0
class CourseDoc(Document):
    id = fields.IntegerField()
    title = fields.StringField()
    notes = fields.TextField()
    participants_number = fields.IntegerField()
    venue = fields.StringField()
    start = fields.DateField()
    end = fields.DateField()
    file_type = fields.KeywordField()
    file_url = fields.KeywordField()
    materials_file_type = fields.KeywordField()
    materials_file_url = fields.KeywordField()
    sessions = fields.NestedField(
        properties={
            'id': fields.IntegerField(),
            'type': fields.KeywordField(),
            'type_name': fields.KeywordField(),
            'start': fields.DateField(),
            'end': fields.DateField(),
        }
    )

    class Index:
        name = mcs.ELASTICSEARCH_INDEX_NAMES['courses']
        settings = mcs.ELASTICSEARCH_DSL_INDEX_SETTINGS

    class Django:
        model = Course
        related_models = [CourseModule, ]

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, CourseModule):
            return related_instance.course

    def get_queryset(self):
        return super().get_queryset().published()
コード例 #25
0
class ManufacturerDocument(DocType):
    country = fields.StringField()

    class Django:
        model = Manufacturer
        fields = [
            'name',
            'created',
            'country_code',
            'logo',
        ]

    class Index:
        name = 'index_settings'
        settings = index_settings
コード例 #26
0
class PageDocument(DocType):
    category = fields.ObjectField(properties={
        'name': fields.StringField()
    })

    class Meta:
        model = Page

        fields = [
            'title',
        ]
        related_models = [Category]

    def __str__(self):
        return self.title
コード例 #27
0
class BookDocument(DocType):
    isbn = fields.TextField(attr="get_isbn")
    author_text = fields.TextField(attr="get_authors")
    author = fields.NestedField(properties={
        'id': fields.IntegerField(),
        'name': fields.StringField()
    })

    class Meta:
        model = Book  # The model associated with this DocType
        # queryset_pagination = 50000
        # The fields of the model you want to be indexed in Elasticsearch
        fields = [
            'id',
            'title'
        ]
コード例 #28
0
class PostDocument(DocType):
	username = fields.ObjectField(properties={'username': fields.StringField()})
	class Meta:
		model = BlogPost
		related_models=[User]

		fields = [
		'posted_date',
		'title',
		'text',
		]
	def get_queryset(self):
		return super(PostDocument, self).get_queryset().select_related('username')

	def get_instances_from_related(self, related_instance):
		return related_instance.username_set.all()
コード例 #29
0
class JobDocument(DocType):
    founder = fields.ObjectField(
        properties={
            'id':
            fields.IntegerField(),
            'startup_name':
            fields.StringField(),
            'description':
            fields.StringField(),
            'logo':
            fields.StringField(attr='logo_url'),
            # 'logo_thumbnail': fields.StringField(attr='logo_thumbnail_url'),
            'is_filled':
            fields.BooleanField(),
            'field':
            fields.StringField(attr='field', analyzer=leave_default),
            'user':
            fields.ObjectField(
                properties={
                    'is_active': fields.BooleanField(),
                    'is_account_disabled': fields.BooleanField(),
                    'last_activity': fields.DateField(
                        attr='last_activity.date')
                })
        })
    get_pay_display = fields.StringField(attr='get_pay_display')
    get_level_display = fields.StringField(attr='get_level_display')

    pay = fields.StringField(attr='pay', analyzer=leave_default)
    level = fields.StringField(attr='level', analyzer=leave_default)

    class Meta:
        model = Job
        related_models = [Founder, MyUser]
        fields = ['title', 'description']

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, MyUser):
            if hasattr(related_instance, 'founder'):
                return related_instance.founder.job_set.all()
        if isinstance(related_instance, Founder):
            return related_instance.job_set.all()
コード例 #30
0
class CampaignDocument(DocType):
    manager = fields.TextField(attr='_get_manager_campaign')
    campaigns_name = fields.TextField(
        attr='_get_campaign_name',
        fields={
            'raw':
            fields.StringField(analyzer='keyword'),
            'suggest':
            fields.CompletionField(attr='_get_campaign_name',
                                   contexts=[{
                                       "name": "manager",
                                       "type": "category",
                                       "path": "manager"
                                   }])
        })

    class Meta:
        model = Campaign
        fields = ['name']