def deact_profile(request, nick, curr_user): "Admin Action: Deactivate profile nick" # error if curr_user doesn't have the rights if not curr_user.is_admin: return render(request, 'error.html', {'error': 'You are not allowed to be here!'}) target_user = user(nick=nick) # error if target user doesn't exist or is an admin if target_user.user_obj == None: return render(request, 'error.html', {'error': 'User %s does not exist!' % nick}) if target_user.is_admin: return render(request, 'error.html', {'error': 'Cannot Deactivate an Admin!'}) if not target_user.is_active: return render(request, 'error.html', {'error': 'User %s already deactivated!' % nick}) if request.method == 'POST': form = ConfirmForm(request.POST) if form.is_valid(): if not form.cleaned_data.get('confirm', False): return HttpResponseRedirect(target_user.user_obj.get_url()) else: return HttpResponseRedirect(target_user.user_obj.get_url()) else: return render(request, 'confirm.html', {'form': ConfirmForm(), 'title': 'Deactivate user %s' % nick}) target_user.user_obj.is_active = False target_user.user_obj.save() logging.info('Admin Action: Deactivated account %s' % target_user.user_obj.nick) return HttpResponseRedirect(target_user.user_obj.get_url())
def view_profile(request, nick): "Profile page of another user (nick)" curr_user = user(nick=nick) if curr_user.user_obj!=None: return render(request, 'view_profile.html', {'target_user': curr_user, 'user_info': curr_user.get_info(), 'links': main.user_links}) else: return render(request, 'error.html', {'error': 'User %s not found!' % nick})
def predict(): json = request.json predictionUser = engine.user(json.get("name"), json.get("gender"), json.get("numChildren", 0), json.get("ownsHouse", 0), json.get("yearBorn"), json.get("numCats", 0), json.get("numDogs", 0), json.get("numHorses", 0)) return jsonify(engine.predict(predictionUser))
def test_get_user(self): expected = {"username": "******", "id": 123, "groups": ["Editors"]} (pact.given("UserA exists and is not an administrator").upon_receiving( "a request for UserA").with_request( "get", "/users/UserA.json").will_respond_with(200, body=expected)) with pact: result = user("UserA") self.assertEqual(result, expected)
def test_main2(): b=2 assert main()==user()
def constructUser(json): return engine.user(json.get("name"), json.get("gender"), json.get("numChildren", 0), json.get("ownsHouse", 0), json.get("yearBorn"), json.get("numCats", 0), json.get("numDogs", 0), json.get("numHorses", 0))