Ejemplo n.º 1
0
def invite_user(request):
    form = UserForm(name='invite', **json.loads(request.body))
    if not form.validate():
        raise Http400

    user = UserModel.invite_user(request, form.email.data)
    return JsonResponse(user)
Ejemplo n.º 2
0
 def test_responses_json_response_with_dict(self):
     result = {
         'user': '******'
     }
     response = JsonResponse(result)
     self.assertEqual(
         response._headers['content-type'],
         ('Content-Type', 'application/json'),
     )
     self.assertDictEqual(json.loads(response.content), result)
Ejemplo n.º 3
0
def update_profile(request):
    form = ProfileForm(**json.loads(request.body))
    if not form.validate():
        raise Http400

    user = UserModel.get_by_id(request.user.key().id())
    if user is None:
        raise Http404
    user.name = form.name.data
    user.put()
    return JsonResponse(user)
Ejemplo n.º 4
0
def update_user(request, user_id):
    user_id = long(user_id)
    form = UserForm(**json.loads(request.body))
    if not form.validate():
        raise Http400
    user = UserModel.get_by_id(user_id)
    if user is None:
        raise Http404
    user.name = form.name.data
    user.permission = form.permission.data
    user.put()
    return JsonResponse(user)
Ejemplo n.º 5
0
def get_user(request, user_id):
    user_id = long(user_id)
    user = UserModel.get_by_id(user_id)
    if user is None:
        raise Http404
    return JsonResponse(user)
Ejemplo n.º 6
0
def get_users(request):
    form = SearchForm(**request.GET.dict())
    query = UserModel.all().order('create_time')
    total = query.count()
    applications = query.fetch(utils.default_page_size, form.index.data * utils.default_page_size)
    return JsonResponse(PageList(form.index.data, utils.default_page_size, total, applications))
Ejemplo n.º 7
0
def get_profile(request):
    return JsonResponse(request.user.dict())