class Event(BaseDocument):
    name = db.StringField(unique=True, required=True)
    date_time = db.DateTimeField(required=True)
    description = db.StringField()
    image = db.URLField()
    link = db.URLField(required=True)
    end_date_time = db.DateTimeField(required=True)
    attendees_count = db.IntField()
    event_status = db.StringField()
    event_type = db.StringField()
    loc = db.StringField()
class ClubEvent(BaseDocument):
    name = db.StringField(required=True)
    image = db.ImageField(size=(500, 500), thumbnail_size=(20, 20))
    tags = db.ListField(db.StringField())
    presenter = db.EmbeddedDocumentField(Presenter)
    start = db.DateTimeField(requried=True)
    end = db.DateTimeField(requried=True)
    description = db.StringField()
    location = db.StringField()

    meta = {"ordering": ["start"]}
示例#3
0
class Hacker(BaseDocument):  # Stored in the "user" collection

    meta = {"indexes": ["email"]}

    private_fields = ["id", "email_token_hash"]

    first_name = db.StringField()
    last_name = db.StringField()
    birthday = db.DateTimeField()
    country = db.StringField()
    phone_number = db.StringField()
    isaccepted = db.BooleanField(default=False)
    can_share_info = db.BooleanField(default=False)
    rsvp_status = db.BooleanField(default=False)
    beginner = db.BooleanField(default=False)
    ethnicity = db.StringField()
    pronouns = db.StringField()
    edu_info = db.EmbeddedDocumentField(Education_Info)
    resume = db.ReferenceField(Resume)
    socials = db.EmbeddedDocumentField(Socials)
    why_attend = db.StringField()
    what_learn = db.ListField()
    in_person = db.BooleanField(default=False)
    dietary_restrictions = db.StringField()

    email = db.EmailField(unique=True, required=True)
    date = db.DateTimeField(default=datetime.utcnow)

    mlh = db.EmbeddedDocumentField(MLH_Authorizations)

    def encode_email_token(self) -> str:
        """Encode the email token"""
        email_token = encode_jwt(sub=self.email)

        conf = app.config["BCRYPT_LOG_ROUNDS"]
        email_token_hash = bcrypt.generate_password_hash(email_token, conf)

        self.modify(set__email_token_hash=email_token_hash)
        self.save()

        return email_token

    @staticmethod
    def decode_email_token(email_token: str) -> str:
        """Decodes the email token"""
        return decode_jwt(email_token)["sub"]

    @classmethod
    def pre_delete(cls, sender, document, **kwargs):
        if document.resume:
            document.resume.delete()
示例#4
0
class Vote(db.Document):
    CUSTOM_VOTE_ID = 6
    voteFields = {
        1: 'Easy to read',
        2: 'Easy to use',
        3: 'Internet of things opportunities',
        4: 'Asynchronous coding benefits',
        5: 'Multiparadigm approach bests Java'
    }

    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    ip = db.StringField(max_length=15, required=True)
    votes = db.DictField(required=True)

    def get_absolute_url(self):
        return url_for('post', kwargs={"slug": self.slug})

    def __unicode__(self):
        return self.title

    def get_vote_title(self, vote_id):
        """
        Get title by identifier
        :type vote_id: int
        """
        vote_id = int(vote_id)
        return self.voteFields[vote_id] if vote_id in self.voteFields.keys(
        ) else None

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at', 'ip'],
        'ordering': ['-created_at']
    }
示例#5
0
class User(UserMixin, db.Document):
    phonenumber = db.StringField(max_length=13, required=True, unique=True)
    email = db.EmailField(max_length=128)
    password = db.StringField(min_length=8, max_length=128, required=True)
    fname = db.StringField(max_length=128)
    lname = db.StringField(max_length=256)
    sex = db.StringField()
    age = db.StringField(min_length=1, max_length=2)
    address = db.StringField()
    melli_code = db.StringField(min_length=10, max_length=10)
    role = db.StringField(default=ROLES['USER'], choices=ROLES)
    datetime = db.DateTimeField()

    # phonenumber_status = db.StringField(default=USER_INFO_STATUS['PENDING'])
    # email_status = db.StringField(default=USER_INFO_STATUS['NOT_FILLED'])
    # melli_code_status = db.StringField(default=USER_INFO_STATUS['NOT_FILLED'])
    # status = db.StringField(default=USER_STATUS['ACTIVE'], choices=USER_STATUS)
    # authorization_errors = db.ListField(db.EmbeddedDocumentField(AuthorizationError))
    # email_notifications = db.ListField(db.StringField(choices=EMAIL_NOTIFICATION))
    # email_verification_code = db.StringField()

    meta = {'indexes': ['phonenumber']}

    def register(self):
        pass
示例#6
0
class Order(db.Document):
    user_id = db.StringField()
    status = db.StringField(choices=tuple(
        types.get_events(types.EventType.Order())),
                            default=types.EventType.Order.CREATED)
    expires_at = db.DateTimeField(
        default=datetime.datetime.now() +
        datetime.timedelta(minutes=Config.ORDER_EXPIRE_TIME_MIN))
    ticket = db.ReferenceField('Ticket')
    version = db.IntField(default=0)

    def response(self):
        return {
            "id": str(self.id),
            "user_id": self.user_id,
            "status": self.status,
            "expires_at": str(self.expires_at),
            "ticket": self.ticket.response(),
            "version": self.version
        }

    def update_version_if_record_exists(self):
        if not self.id:
            return

        existing_record = Order.objects(id=self.id)
        if existing_record:
            self.version += 1

    def save(self, *args, **kwargs):
        self.update_version_if_record_exists()
        super().save(*args, **kwargs)
示例#7
0
class GenericNotification(db.Document):
    contents = {}
    meta = {'collection': 'notification', 'allow_inheritance': True}

    nid = db.UUIDField(default=uuid4, primary_key=True)
    created = db.DateTimeField(default=datetime.datetime.utcnow,
                               required=True,
                               null=False)

    def serialize(self):
        data = {}
        for key, value in self.params.items():
            data[key] = getattr(self, key)
        data['nid'] = str(self.nid)
        data['type'] = self._cls
        data['contents'] = self.get_contents()
        data['created'] = str(self.created)
        return data

    def get_contents(self):
        contents = deepcopy(self.contents)
        params = {}
        for id_name, value_name in self.params.items():
            id_data = getattr(self, id_name)
            params[value_name] = name_cache[id_data]
        for lang, msg in self.contents.items():
            contents[lang] = msg.format(**params)
        return contents
示例#8
0
class Ternary(db.EmbeddedDocument):
    start_time = db.DateTimeField()
    d1 = db.ListField()
    d2 = db.ListField()
    d3 = db.ListField()
    d4 = db.ListField()
    d5 = db.ListField()
    d6 = db.ListField()
    d7 = db.ListField()
    d8 = db.ListField()
    d9 = db.ListField()
    d10 = db.ListField()
    d11 = db.ListField()
    d12 = db.ListField()
    d13 = db.ListField()
    d14 = db.ListField()
    d15 = db.ListField()
    d16 = db.ListField()
    d17 = db.ListField()
    d18 = db.ListField()
    d19 = db.ListField()
    d20 = db.ListField()
    d21 = db.ListField()
    d22 = db.ListField()
    d23 = db.ListField()
    d24 = db.ListField()
    d25 = db.ListField()

    def create(self, property, result):
        self.__setattr__(property, result)
        return self
示例#9
0
class Post(UserMixin, db.Document):
    meta = {'collection': 'posts'}
    title = db.StringField(max_length=30)
    date = db.DateTimeField()
    content = db.StringField(max_length=1000)
    author = db.StringField(max_length=30)
    tags = db.ListField()
    owner = db.LazyReferenceField('User')
示例#10
0
class SpeechNoise(db.EmbeddedDocument):
    start_time = db.DateTimeField()
    right_silence = db.ListField()
    left_silence = db.ListField()
    right_noise = db.ListField()
    left_noise = db.ListField()

    def create(self, property, result):
        self.__setattr__(property, result)
        return self
示例#11
0
class D2VModel(db.Document):
    serialized_model = db.FileField()
    last_run = db.DateTimeField()

    vectors = db.DictField()

    # [
    #   [a1, a2],
    #   [b1, b2]
    # ]
    vectors_2d = db.ListField(db.ListField(db.FloatField()))

    @property
    def model(self):
        """
        load serialized model

        :return:
        """
        if not self.serialized_model:
            return None

        bytes_io = io.BytesIO(self.serialized_model)
        model = pickle.load(bytes_io)
        return model

    @model.setter
    def model(self, model):
        # instead of a file
        bytes_io = io.BytesIO()

        # save model to bytesio
        model.save(bytes_io)

        # getvalue has the actual bytes
        self.serialized_model = bytes_io.getvalue()

        # close buffer
        bytes_io.close()

        # update timestamp and save
        self.touch()

    @staticmethod
    def get():
        d2v_model = D2VModel.objects.first()
        if not d2v_model:
            d2v_model = D2VModel()
            d2v_model.touch()
            d2v_model.save()
        return d2v_model

    def touch(self):
        self.last_run = datetime.datetime.now()
示例#12
0
class Resume(BaseDocument):
    file = db.FileField(required=True)
    attached = db.BooleanField(default=False)
    created = db.DateTimeField(default=datetime.utcnow)
    meta = {
        "indexes": [{
            "fields": ["created"],
            "expireAfterSeconds": 86400,  # Expires after 24 hours
            "partialFilterExpression": {
                "attached": False
            }
        }]
    }
示例#13
0
class PureTone(db.EmbeddedDocument):
    start_time = db.DateTimeField()
    Right_250 = db.BooleanField()
    Right_500 = db.BooleanField()
    Right_1000 = db.BooleanField()
    Right_2000 = db.BooleanField()
    Right_4000 = db.BooleanField()
    Right_8000 = db.BooleanField()
    Left_250 = db.BooleanField()
    Left_500 = db.BooleanField()
    Left_1000 = db.BooleanField()
    Left_2000 = db.BooleanField()
    Left_4000 = db.BooleanField()
    Left_8000 = db.BooleanField()

    def __repr__(self):
        return '[PureTone] id: {}, status: {}'.format(self.start_time,
                                                      self.Left_125)

    def create(self, property, result):
        self.__setattr__(property, result)
        return self
示例#14
0
class Article(db.Document):
    feed = db.ReferenceField(Feed, required=True)
    source_id = db.StringField(required=True)
    url = db.StringField()

    title = db.StringField()
    top_image = db.StringField()
    movies = db.ListField()
    keywords = db.ListField()
    tags = db.ListField()
    authors = db.ListField()
    publish_date = db.DateTimeField()
    summary = db.StringField()
    html = db.StringField()
    meta_data = db.DictField()

    language = db.StringField()

    text = db.StringField()
    active = db.BooleanField(default=True)

    vector = db.ListField(db.FloatField())
    vector_2d = db.ListField(db.FloatField())

    def as_dict(self):
        return dict(feed=self.feed.url,
                    source_id=self.source_id,
                    url=self.url,
                    title=self.title,
                    top_image=self.top_image,
                    movies=self.movies,
                    keywords=self.keywords,
                    tags=self.tags,
                    authors=self.authors,
                    publish_date='%s' % self.publish_date,
                    summary=self.summary,
                    html=self.html,
                    meta_data=self.meta_data,
                    language=self.language,
                    text=self.text,
                    vector=self.vector,
                    vector_2d=self.vector_2d)

    @staticmethod
    def update_vectors(model, vectors_2d=[]):
        # https://stackoverflow.com/questions/30943076/mongoengine-bulk-update-without-objects-update
        bulk_operations = []

        keys = model.docvecs.doctags.keys()
        vectors = model.docvecs.vectors_docs

        for key, vector, vector_2d in zip(keys, vectors, vectors_2d):
            bulk_operations.append(
                UpdateOne({'_id': key}, {
                    '$set':
                    dict(vector=vector.tolist(), vector_2d=vector_2d)
                }))

        if bulk_operations:
            collection = Article._get_collection() \
                .bulk_write(bulk_operations, ordered=False)
示例#15
0
class LabInvoice(db.Document):
    date = db.DateTimeField(default=datetime.datetime.utcnow())
    items = db.ListField(db.ObjectIdField())
    total = db.FloatField()
示例#16
0
class PharmacyInvoice(db.Document):
    date = db.DateTimeField(default=datetime.datetime.utcnow())
    items = db.ListField(db.DictField())
    total = db.FloatField()