Пример #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
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
class CityQueryAndFiltering(Model):
    short_name = IDField()
    name = TextField()
    state = TextField()
    country = TextField()
    capital = BooleanField()
    population = NumberField()
    regions = ListField()
class CityOrderAndLimit(Model):
    short_name = IDField()
    name = TextField()
    state = TextField()
    country = TextField()
    capital = BooleanField()
    population = NumberField()
    regions = ListField()
Пример #6
0
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
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
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
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
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
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
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
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
 class CompanyIssue87(Model):
     id = IDField()
     name = TextField()
Пример #28
0
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()