示例#1
0
 def get(self):
     user_id = self.request.matchdict.get('user_id')
     with create_transaction() as transaction:
         state = transaction.query(UserSql).filter(
             UserSql.id == user_id).first()
         return HTTPOk(state.val()) if state is not None \
             else HTTPNotFound(FailResultSimple("UserNotFound", "Пользователь не найдена"))
示例#2
0
 def _get_permission(sub: Urn, obj: Urn):
     with create_transaction() as transaction:
         permission = transaction.query(PermissionSql) \
             .filter((PermissionSql.subject == str(sub)) & (PermissionSql.object == str(obj)))\
             .first()
         return HTTPOk(permission.val()) if permission is not None \
             else HTTPNotFound(Permission(sub, obj, Permissions.Null))
示例#3
0
 def session(self):
     with create_transaction() as transaction:
         auth_sid = self.request.matchdict.get('auth_sid')
         state = transaction.query(SessionStateSql).filter(
             SessionStateSql.id == auth_sid).first()
         return HTTPOk(state.val()) if state is not None \
             else HTTPNotFound(FailResultSimple("SessionNotFound", "Сессия не найдена"))
示例#4
0
 def get_form(self):
     id = self.request.matchdict.get('id')
     with create_transaction() as transaction:
         form = transaction.query(FormSql) \
             .filter(FormSql.id == id) \
             .first()
         return HTTPOk(form.val()) if form \
             else HTTPNotFound(FailResultSimple('FormNotFound', 'Форма не найдена'))
示例#5
0
 def delete_answer(self):
     id = self.request.matchdict.get('id')
     with create_transaction() as transaction:
         deleted = transaction.query(AnswerSql) \
             .filter(AnswerSql.id == id) \
             .delete()
         return HTTPOk() if deleted \
             else HTTPNotFound(FailResultSimple('AnswerNotFound', 'Ответ не найдена'))
示例#6
0
 def get_answer(self):
     id = self.request.matchdict.get('id')
     with create_transaction() as transaction:
         answer = transaction.query(AnswerSql) \
             .filter(AnswerSql.id == id) \
             .first()
         return HTTPOk(answer.val()) if answer \
             else HTTPNotFound(FailResultSimple('AnswerNotFound', 'Ответ не найдена'))
示例#7
0
 def delete_binding(self):
     form_id = self.request.matchdict.get('form_id')
     place_id = self.request.matchdict.get('place_id')
     with create_transaction() as transaction:
         deleted = transaction.query(BindingSql) \
             .filter(BindingSql.form_id == form_id and BindingSql.place_id == place_id) \
             .delete()
         return HTTPOk() if deleted \
             else HTTPNotFound(FailResultSimple('BindingNotFound', 'Привязка не найдена'))
示例#8
0
 def set_answer(self):
     id = self.request.matchdict.get('id')
     answer = self.request.body.decode()
     with create_transaction() as transaction:
         patched = transaction.query(AnswerSql) \
             .filter(AnswerSql.id == id) \
             .update({AnswerSql.answer: answer})
         return HTTPOk() if patched \
             else HTTPNotFound(FailResultSimple('AnswerNotFound', 'Ответ не найдена'))
示例#9
0
 def set_form(self):
     id = self.request.matchdict.get('id')
     data = self.request.body.decode()
     data = json.loads(data)
     with create_transaction() as transaction:
         patched = transaction.query(FormSql) \
             .filter(FormSql.id == id) \
             .update(data)
         return HTTPOk() if patched \
             else HTTPNotFound(FailResultSimple('FormNotFound', 'Форма не найдена'))
示例#10
0
 def put_form(self):
     id = self.request.matchdict.get('id')
     data = self.request.body.decode()
     data = json.loads(data)
     data["id"] = id
     form = FormSql(**data)
     try:
         with create_transaction() as transaction:
             transaction.add(form)
         return HTTPOk()
     except IntegrityError:
         return HTTPNotFound(FailResultSimple('FormNotCreated', 'Форма не создана'))
示例#11
0
 def put_answer(self):
     id = self.request.matchdict.get('id')
     data = self.request.body.decode()
     data = json.loads(data)
     data["id"] = id
     answer = AnswerSql(**data)
     try:
         with create_transaction() as transaction:
             transaction.add(answer)
         return HTTPOk()
     except IntegrityError:
         return HTTPNotFound(FailResultSimple('AnswerNotCreated', 'Ответ не создана'))
示例#12
0
    def _get_permissions(sub: Urn, skip: int, take: int):
        with create_transaction() as transaction:
            count = transaction.query(PermissionSql) \
                .filter(PermissionSql.subject == str(sub)) \
                .count()

            if count == 0 or skip >= count:
                return HTTPNotFound(ItemsResult([], skip, take, count))

            permissions = transaction.query(PermissionSql)\
                .filter(PermissionSql.subject == sub)\
                [skip:take]
            items = list(map(lambda p: p.val().__dict__, permissions))
            return HTTPOk(ItemsResult(items, skip, take, count))
示例#13
0
 def get_forms_by_place(self):
         place_id = self.request.matchdict.get('place_id')
         skip = int(self.request.matchdict.get('skip', 0))
         take = int(self.request.matchdict.get('take', 50000))
         with create_transaction() as transaction:
             count = transaction.query(FormSql) \
                 .join(BindingSql, BindingSql.form_id == FormSql.id) \
                 .filter(BindingSql.place_id == place_id) \
                 .count()
             if count == 0 or skip >= count:
                 return HTTPNotFound(ItemsResult([], skip, take, count))
             answers = transaction.query(FormSql) \
                 .join(BindingSql, BindingSql.form_id == FormSql.id) \
                 .filter(BindingSql.place_id == place_id) \
                 [skip:take]
             items = list(map(lambda p: p.val().__dict__, answers))
             return HTTPOk(ItemsResult(items, skip, take, count))
示例#14
0
    def get_forms(self):
        user_id = self.request.matchdict.get('user_id')
        skip = int(self.request.matchdict.get('skip', 0))
        take = int(self.request.matchdict.get('take', 50000))

        with create_transaction() as transaction:
            count = transaction.query(FormSql)\
                .filter(FormSql.creator == user_id)\
                .count()

            if count == 0 or skip >= count:
                return HTTPNotFound(ItemsResult([], skip, take, count))

            answers = transaction.query(FormSql)\
                .filter(FormSql.creator == user_id)\
                [skip:take]
            items = list(map(lambda p: p.val().__dict__, answers))
            return HTTPOk(ItemsResult(items, skip, take, count))