Example #1
0
 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
Example #2
0
 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
Example #3
0
 def mark_as_viewed(uuid, user_uuid) -> bool:
     return bool(red.sadd(Event.uuid(uuid) & Event.views, user_uuid))
Example #4
0
 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
Example #5
0
 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))