def add(email, password): uuid = str(uuid4()) red.set(User.email(email) & User.password, password) red.set(User.uuid(uuid) & User.data, json.dumps({ 'email': email, 'uuid': uuid })) red.sadd(User.uuid, uuid) return uuid
def add(event: dict) -> str: uuid = event['uuid'] = str(uuid4()) tags = event.setdefault('tags', []) state = event.setdefault('state', EventState.pending) red.set(Event.uuid(uuid) & Event.data, json.dumps(event)) red.sadd(EventState.name(state), uuid) red.sadd(Event.uuid, uuid) for tag in tags: red.sadd(Tag.name, tag) red.sadd(Tag.name(tag), uuid) return uuid
def mark_as_viewed(uuid, user_uuid) -> bool: return bool(red.sadd(Event.uuid(uuid) & Event.views, user_uuid))
def mark_as_upvoted(uuid, user_uuid) -> bool: if red.sadd(Event.upvotes_set, user_uuid): red.lpush(Event.uuid(uuid) & Event.views, user_uuid) return True return False
def set_state(cls, uuid, state): data = cls.get(uuid) red.srem(EventState.name(data['state']), uuid) data['state'] = state red.sadd(EventState.name(state), uuid) red.set(Event.uuid(uuid) & Event.data, json.dumps(data))