コード例 #1
0
class Audio(Model):
    id = IDField()
    ayah_id = TextField()
    ayah_number = NumberField()
    edition_id = TextField()
    type = TextField(format='capitalize')  # Translation or Arabic
    audio = TextField()
コード例 #2
0
    def from_query_result(cls, model, doc, nested_doc=False):
        parent_key = None
        if nested_doc:
            doc_dict = doc
        elif doc:
            parent_key = utils.get_parent_doc(doc.reference.path)
            if doc.to_dict():
                doc_dict = doc.to_dict()
            else:
                return None
        else:
            return None

        # instance values is changed according to firestore
        # so mark it modified this will help later for figuring
        # out the updated fields when need to update this document
        setattr(model, '_instance_modified', True)
        for k, v in doc_dict.items():
            field = model._meta.get_field_by_column_name(k)
            # if missing field setting is set to "ignore" then
            # get_field_by_column_name return None So, just skip this field
            if field is None:
                continue
            # Check if it is Reference field
            if isinstance(field, ReferenceField):
                val = ReferenceFieldWrapper.from_doc_ref(
                    model, field, field.field_value(v))
            elif isinstance(field, NestedModel):
                nested_doc_val = field.field_value(v)
                if nested_doc_val:
                    val = NestedModelWrapper.from_model_dict(
                        field, nested_doc_val)
                else:
                    val = None
            else:
                val = field.field_value(v)
            setattr(model, field.name, val)

        # If parent key is None but here is parent key from doc then set the parent for this model
        # This is case when you filter the documents parent key not auto set just set it
        if not model.parent and parent_key is not None:
            model.parent = parent_key

        # If it is not nested model then set the id for this model
        if not nested_doc:
            # When getting document attach the IDField if there is no user specify
            # it will prevent to generate new id everytime when document save
            # For more information see issue #45 https://github.com/octabytes/FireO/issues/45
            if model._meta.id is None:
                model._meta.id = ('id', IDField())

            setattr(model, '_id', doc.id)
            # save the firestore reference doc so that further actions can be performed (i.e. collections())
            model._meta.set_reference_doc(doc.reference)
            # even though doc.reference currently points to self, there is no guarantee this will be true
            # in the future, therefore we should store the create time and update time separate.
            model._meta._firestore_create_time = doc.create_time
            model._meta._firestore_update_time = doc.update_time
        return model
コード例 #3
0
class User(Model):
    """User Class Model, extending from ```fireo.models.Model``` package.

    Attributes
    ----------
    id : str
        User unique id composed by subject id given by google auth.
    name : str
        User display name.
    contacts_statistics : dict
        dictionary containg the statistics about contacts, in other words,
        contacts per domain, contacts per City Adresss, contacts per organization

    """

    id = IDField()
    query_id = TextField()
    name = TextField()
    contacts_statistics = MapField()

    @staticmethod
    def statistics_to_chart(data):
        """Return a dictionary with label and data to plot statistics.
        
        Parameters
        ----------
        data : Dict
            Dictionary with contacts statistics in the following format:
            {
                'organization': {
                    'google': 25, 'facebook': 30
                },
                ...
            }
            
        Returns
        -------
        dict
            Dictionary in the following format:
            {
                'organization': {
                    'label': ["google", "facebook", ...],
                    'data': [25, 30, ...]
                }
            }
        """
        data = data['contacts_statistics']

        chart_data = {}

        for key, item in data.items():
            print(key, item)
            chart_data[key] = {"label": [], "data": []}

            for label, value in item.items():
                chart_data[key]["label"].append(label)
                chart_data[key]["data"].append(value)

        return chart_data
コード例 #4
0
class CityQueryAndFiltering(Model):
    short_name = IDField()
    name = TextField()
    state = TextField()
    country = TextField()
    capital = BooleanField()
    population = NumberField()
    regions = ListField()
コード例 #5
0
class CityOrderAndLimit(Model):
    short_name = IDField()
    name = TextField()
    state = TextField()
    country = TextField()
    capital = BooleanField()
    population = NumberField()
    regions = ListField()
コード例 #6
0
ファイル: user.py プロジェクト: guohaolee/ghost_name_picker
class User(Model):
    id = IDField()
    name = TextField()
    email = TextField()
    profile_pic = TextField()
    last_login = DateTime()

    class Meta:
        collection_name = 'users'
コード例 #7
0
class Edition(Model):
    id = IDField()
    language = TextField()
    name = TextField()
    translator = TextField()

    class Meta:
        to_lowercase = True
        collection_name = "quran_editions"
コード例 #8
0
ファイル: ayah.py プロジェクト: islam-786/quran-data-importer
class Ayah(Model):
    id = IDField()
    surah_id = TextField()
    number = NumberField(int_only=True)
    number_in_surah = NumberField(int_only=True)
    arabic = TextField()

    class Meta:
        collection_name = "quran_ayahs"
コード例 #9
0
ファイル: ayah.py プロジェクト: octabytes/data-importer
class Ayah(Model):
    id = IDField()
    number = NumberField()
    surah_number = NumberField()
    content = MapField()
    uci = TextField(required=True)

    class Meta:
        collection_name = "quran"
コード例 #10
0
class Translation(Model):
    id = IDField()
    ayah_id = TextField()
    edition_id = TextField()
    ayah_number = NumberField()
    text = TextField()
    
    class Meta:
        collection_name = "translations"
コード例 #11
0
class Edition(Model):
    id = IDField()
    language = TextField()
    name = TextField()
    english_name = TextField()
    type = TextField()

    class Meta:
        to_lowercase = True
        collection_name = "editions"
コード例 #12
0
ファイル: audio.py プロジェクト: OctaByteInc/quran-data
class Audio(Model):
    id = IDField()
    ayah_id = TextField()
    ayah_number = NumberField()
    edition_id = TextField()
    type = TextField()  # Translation or Arabic
    link = TextField()

    class Meta:
        collection_name = "audios"
コード例 #13
0
class Edition(Model):
    id = IDField()
    language = TextField()
    name = TextField(format='title')
    translator = TextField(format='title')
    type = TextField(format='capitalize')
    format = TextField(format='capitalize')
    direction = TextField()

    class Meta:
        to_lowercase = True
コード例 #14
0
class Surah(Model):
    id = IDField()
    number = NumberField(int_only=True)
    name = TextField(format='title')
    english_name = TextField(format='title')
    english_name_translation = TextField(format='title')
    number_of_ayahs = NumberField(int_only=True)
    revelation_type = TextField(format='capitalize')

    class Meta:
        to_lowercase = True
コード例 #15
0
ファイル: ayah.py プロジェクト: OctaByteInc/quran
class Ayah(Model):
    id = IDField()
    surah_id = TextField()
    number = NumberField(int_only=True)
    number_in_surah = NumberField(int_only=True)
    juz = NumberField(int_only=True)
    manzil = NumberField(int_only=True)
    ruku = NumberField(int_only=True)
    hizb_quarter = NumberField(int_only=True)
    sajda = BooleanField()
    arabic = TextField()
コード例 #16
0
ファイル: ibnemaja.py プロジェクト: octabytes/data-importer
class IbneMaja(Model):
    id = IDField()
    hadith_number = NumberField()
    book_number = NumberField()
    book_name = MapField()
    chapter = MapField()
    text = MapField()
    is_sahih = BooleanField()
    uci = TextField(required=True)

    class Meta:
        collection_name = "ibne_maja"
コード例 #17
0
ファイル: surah.py プロジェクト: islam-786/quran-backend-api
class Surah(Model):
    id = IDField()
    number = NumberField(int_only=True)
    name = TextField()
    english_name = TextField()
    english_name_translation = TextField()
    number_of_ayahs = NumberField(int_only=True)
    revelation_type = TextField()

    class Meta:
        to_lowercase = True
        collection_name = "quran_surahs"
コード例 #18
0
class AbuDawud(Model):
    id = IDField()
    hadith_number = NumberField()
    book_number = NumberField()
    book_name = MapField()
    chapter = MapField()
    text = MapField()
    is_sahih = BooleanField()
    uci = TextField(required=True)

    class Meta:
        collection_name = "abu_dawud"
コード例 #19
0
class Edition(Model):
    id = IDField()
    language = TextField()
    name = TextField()
    translator = TextField()
    type = TextField()
    format = TextField()
    direction = TextField()

    class Meta:
        to_lowercase = True
        collection_name = "editions"
コード例 #20
0
ファイル: muslim.py プロジェクト: octabytes/data-importer
class Muslim(Model):
    id = IDField()
    hadith_number = NumberField()
    book_number = NumberField()
    international_number = NumberField()
    book_name = MapField()
    chapter = MapField()
    text = MapField()
    is_sahih = BooleanField()
    uci = TextField(required=True)

    class Meta:
        collection_name = "muslim"
コード例 #21
0
class Mishkat(Model):
    id = IDField()
    hadith_number = NumberField()
    book_number = NumberField()
    book_name = MapField()
    chapter = MapField()
    text = MapField()
    is_muttafaqun_alayh = BooleanField()
    is_sahih = BooleanField()
    uci = TextField(required=True)

    class Meta:
        collection_name = "mishkat"
コード例 #22
0
class GhostRecord(Model):

    id = IDField()
    name = TextField()
    description = TextField()
    picked = BooleanField(default=False)
    user_first_name = TextField(default=None)
    user_last_name = TextField(default=None)
    user_email = TextField(default=None)
    user_ghost_name = TextField(default=None)
    class_name = 'ghost_name'

    class Meta:
        collection_name = 'ghost_name'

    @classmethod
    def get_unallocated_ghost(cls):
        return cls.collection.filter('picked', '==', False).fetch()

    @classmethod
    def get_allocated_ghost(cls):
        return cls.collection.filter('picked', '==', True).fetch()

    @classmethod
    def get_single_ghost(cls, ghost):
        return cls.collection.get(f"{cls.class_name}/{ghost}")

    @classmethod
    def get_email_record(cls, email):
        return cls.collection.filter('user_email', '==', email).fetch()

    @classmethod
    def reset(cls, email):
        """ reset the record """
        record = cls.collection.filter('user_email', '==', email).fetch()
        for r in record:
            r.picked = False
            r.user_first_name = None
            r.user_last_name = None
            r.user_email = None
            r.user_ghost_name = None
            r.save()

    @classmethod
    def has_record(cls, email):
        result = cls.collection.filter('user_email', '==', email).get()
        if result:
            return True
        else:
            return False
コード例 #23
0
class TestDB(Model):
    id = IDField()
    name = TextField()
    class_name = 'test_users'

    class Meta:
        collection_name = 'test_users'

    @classmethod
    def delete(cls, id):
        try:
            cls.collection.delete(f"{cls.class_name}/{id}")
            return True
        except Exception as e:
            return False
コード例 #24
0
class Task(Model):
    id = IDField()
    pkl_path = TextField()
    generation = NumberField()
    assigned_to = TextField(default="nobody")
    state = TextField(default="incomplete")
    created_at = DateTime(default=datetime.datetime.now())
    assigned_at = DateTime()
    ngrok_url = TextField()
    pkl_data = TextField()
    result_pkl_data = TextField()
    network_id = NumberField()
    extra_workers = NumberField(default=0)
    run_code = TextField(default="none")
    client_stream = TextField(default="tpu")

    def __str__(self):
        return str({k: str(v)[:15] for k, v in self.to_dict().items()})
コード例 #25
0
class HadithBukhari(Model):
    id = IDField()
    bookName = TextField()
    bookNameArabic = TextField()
    bookNumber = NumberField()
    hadithNumber = TextField()
    numberInBook = NumberField()
    chapterName = TextField()
    chapterNameArabic = TextField()
    narratedBy = TextField()
    narratedByArabic = TextField()
    narratedByArabicDetail = TextField()
    narratedByUrdu = TextField()
    text = TextField()
    textArabic = TextField()
    textUrdu = TextField()

    class Meta:
        collection_name = 'hadith_bukhari'
コード例 #26
0
class Hero(Model):
    """Model Hero"""
    id = IDField()
    description = TextField()
    image_url = TextField()
    name = TextField()
    universe = TextField()

    class Meta:
        collection_name = "Hero"

    @classmethod
    def all(cls, cursor=None, list_type='cursor'):
        """
        Get all heroes
        :param int limit: limit of heroes
        :return: Heroes list
        """
        if list_type == 'all':
            limit = 100
        else:
            limit = 20

        if cursor:
            return cls.collection.cursor(cursor).fetch(limit)
        else:
            return cls.collection.fetch(limit)

    @classmethod
    def get_by_id(cls, hero_id):
        """
        Get by id
        :param hero_id:
        :return:
        """
        return cls.collection.get('Hero/%s' % hero_id)

    def to_dict(self):
        """"""
        hero_dict = super(Hero, self).to_dict()
        hero_dict['imageUrl'] = self.image_url
        del (hero_dict['image_url'])
        return hero_dict
コード例 #27
0
ファイル: test_issue_87.py プロジェクト: octabytes/FireO
 class CompanyIssue87(Model):
     id = IDField()
     name = TextField()
コード例 #28
0
ファイル: image.py プロジェクト: OctaByteInc/quran-data
class Image(Model):
    ayah_id = IDField()
    link = TextField()

    class Meta:
        collection_name = "images"
コード例 #29
0
class Fstore(Model):
    id = IDField()
    language = TextField()

    class Meta:
        collection_name = "fstore"
コード例 #30
0
 class UserIssue63(Model):
     user_id = IDField()
     name = TextField()
     date_added = DateTime()