示例#1
0
class Role(ExtendedDocument):
    """
    ...
    """
    meta = {"collection": "roles"}

    name = db.StringField(required=True, unique=True)
    description = db.StringField()
    # TODO rethink the structure
    group = db.IntField(required=True)  # , unique_with=["priority_level"])
    priority_level = db.IntField(required=True)  # , unique_with=["group"])

    # Embedded Document Version
    _embedded = None

    @classmethod
    def as_embedded(cls, *args, **kwargs):
        if not cls._embedded:
            cls._embedded = type("EmbeddedRole", (ExtendedEmbeddedDocument,),
                                 {"name": db.StringField(required=True),
                                  "description": cls.description,
                                  "group": cls.group,
                                  "priority_level": cls.priority_level})

        if args or kwargs:
            return cls._embedded(*args, **kwargs)

        return cls._embedded
示例#2
0
class Attendee(db.Document):
    event_id = db.StringField()
    token = db.StringField(unique=True)
    user_id = db.StringField()
    scenario = db.DictField()
    attr = db.DictField()
    first_use = db.IntField()
    role = db.StringField()

    meta = {'indexes': ['event_id', 'token', 'role']}

    @property
    def public_token(self):
        return sha1(self.token.encode('utf-8')).hexdigest()

    def to_json(self):
        data = self.to_mongo()

        scenarios = []
        for k, v in data['scenario'].items():
            v.pop('_cls')
            v['id'] = k
            scenarios.append(v)

        data.pop('scenario')
        data['scenarios'] = sorted(scenarios, key=lambda k: k['order'])
        return bson.json_util.dumps(data)
class SubscriptionModel(gj.Document):
    email = db.EmailField(required=True)
    name = db.StringField(required=True)
    expired_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    deleted_at = db.DateTimeField(required=False)
    comment = db.StringField(required=False)
示例#4
0
class Task(ExtendedDocument):
    """
    ...
    """
    meta = {"collection": "tasks",
            "allow_inheritance": True}

    name = db.StringField(required=True)
    priority = db.IntField(required=True)
    description = db.StringField()
    subject = db.ObjectIdField(required=True)
示例#5
0
class Scenario(db.EmbeddedDocument):
    order = db.IntField()
    display_text = db.DictField()
    available_time = db.IntField()
    expire_time = db.IntField()
    used = db.IntField()
    disabled = db.StringField()
    countdown = db.IntField()
    attr = db.DictField()
示例#6
0
class PuzzleStatus(db.Document):
    puzzle = db.StringField()
    quantity = db.IntField(default=0)
    currency = db.IntField(default=0)

    meta = {
        'indexes': [
            'puzzle'
        ]
    }
示例#7
0
    def as_embedded(cls, *args, **kwargs):
        if not cls._embedded:
            cls._embedded = type("EmbeddedRole", (ExtendedEmbeddedDocument,),
                                 {"name": db.StringField(required=True),
                                  "description": cls.description,
                                  "group": cls.group,
                                  "priority_level": cls.priority_level})

        if args or kwargs:
            return cls._embedded(*args, **kwargs)

        return cls._embedded
示例#8
0
class PuzzleBucket(db.Document):
    attendee = db.ReferenceField(Attendee)
    public_token = db.StringField(unique=True)
    puzzle = db.ListField()
    valid = db.IntField()
    coupon = db.IntField()
    deliverer = db.ListField()

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

    @classmethod
    def init(cls, attendee):
        try:
            return PuzzleBucket.objects.create(attendee=attendee, public_token=attendee.public_token)
        except NotUniqueError:
            return PuzzleBucket.objects(public_token=attendee.public_token).get()
示例#9
0
class Announcement(db.Document):
    datetime = db.IntField()
    msg_zh = db.StringField()
    msg_en = db.StringField()
    uri = db.StringField()
    role = db.ListField()
示例#10
0
class Team(db.Document):
    group_id = db.IntField(unique=True)
    name = db.StringField()
    coin = db.IntField(default=0)

    meta = {'indexes': ['group_id']}
示例#11
0
class Keyword(db.Document):
    keyword = db.StringField(unique=True)
    solved_team = db.ListField(default=[])
示例#12
0
class Coupon(db.Document):
    coin = db.IntField()
    description = db.StringField()
    own_team = db.ReferenceField(Team)
    producer = db.StringField()