def post(self, request, *args, **kwargs): response_data = {} email = request.POST.get('email') password = request.POST.get('password') if not all([email, password]): response_data['error'] = True response_data['message'] = "Email-id and password required!" return HttpResponseBadRequest(json.dumps(response_data), content_type="application/json") if get_or_none(User, username=email): response_data['error'] = True response_data['message'] = "Email-id already exists!" return HttpResponseBadRequest(json.dumps(response_data), content_type="application/json") u = User(username=email) try: u.set_password(password) u.save() except Exception as e: response_data['error'] = True response_data['message'] = "Some error occurred! please try again." response_data['details'] = "%s - %s" % (e.__doc__, repr(e)) return HttpResponse(json.dumps(response_data), status=500, content_type="application/json") response_data = { 'error': False, 'message': 'Successfully Created!', 'id': u.id, } return HttpResponse(json.dumps(response_data), status=201, content_type="application/json")
def post(self, request, *args, **kwargs): response_data = {} email = request.POST.get('email') password = request.POST.get('password') if not all([email, password]): response_data['error'] = True response_data['message'] = "Email-id, and password required!" return HttpJSONResponse(response_data, status=400) if get_or_none(User, username=email): response_data['error'] = True response_data['message'] = "Email-id already exists!" return HttpJSONResponse(response_data, status=400) u = User(email=email, username=email) try: u.first_name = request.POST.get('fname', '') u.last_name = request.POST.get('lname', '') u.institute = request.POST.get('institute') u.grad_year = request.POST.get('grad_year') u.location = request.POST.get('location') u.company = request.POST.get('company') u.set_password(password) u.save() except Exception as e: response_data['error'] = True response_data['message'] = "Some error occurred! please try again." response_data['details'] = "%s - %s" % (e.__doc__, repr(e)) return HttpJSONResponse(response_data, status=500) response_data = { 'error': False, 'message': 'Successfully Created!', 'id': u.id, } return HttpJSONResponse(response_data)
def post(self, request, *args, **kwargs): follower = request.user or User.objects.get(id=request.POST.get('follower_id')) # following = User.objects.get(id=request.POST.get('following_id')) following = get_or_none(User, id=request.POST.get('following_id')) if following is None: response_data = { 'error': False, 'message': 'Provide a valid id of following user' } return HttpJSONResponse(response_data, status=400) f = Follow(follower=follower, following=following) f.save() response_data = { 'error': False, 'message': 'user {} is following {}'.format(follower.username, following.username) } return HttpJSONResponse(response_data)