def update_question(request, username, question_id): """ Update a single answer for a particular profile question of a particular user """ profile = UserProfile.get_user_profile_from_username(username) # Make sure that the profile exists if profile: user = profile.user else: return form_failure_notification('User does not exist') # Make sure that a user is only able to update his profile and nobody else's. if request.user != user: return form_failure_notification('Uh oh! Something went wrong!') if request.method == 'POST': profile_answer_form = ProfileAnswerForm(request.POST) if profile_answer_form.is_valid(): new_answer = request.POST.get('answer', '') profile_answer = ProfileAnswer.get_answer(user, ProfileQuestion.objects.get(id=question_id)) profile_answer.answer = new_answer profile_answer.save() return ajax_http(form_success_notification('Question successfully updated')) else: return ajax_http(form_failure_notification('Answer too long'))
def update_question(request, username, question_id): """ Update a single answer for a particular profile question of a particular user """ profile = UserProfile.get_user_profile_from_username(username) # Make sure that the profile exists if profile: user = profile.user else: return form_failure_notification('User does not exist') # Make sure that a user is only able to update his profile and nobody else's. if request.user != user: return form_failure_notification('Uh oh! Something went wrong!') if request.method == 'POST': profile_answer_form = ProfileAnswerForm(request.POST) if profile_answer_form.is_valid(): new_answer = request.POST.get('answer', '') profile_answer = ProfileAnswer.get_answer( user, ProfileQuestion.objects.get(id=question_id)) profile_answer.answer = new_answer profile_answer.save() return ajax_http( form_success_notification('Question successfully updated')) else: return ajax_http(form_failure_notification('Answer too long'))
def send_message(request): if request.method == 'POST': send_message_form = SendMessageForm(request.POST, request=request) if send_message_form.is_valid(): sender = request.user ticket = send_message_form.cleaned_data.get('ticket') other_user = send_message_form.cleaned_data.get('other_user') body = send_message_form.cleaned_data.get('body') Message.objects.create_message(sender, other_user, ticket, body) return ajax_http(form_success_notification('Your message was sent successfully!')) else: return ajax_http(non_field_errors_notification(send_message_form))
def create_email_confirmation_link(request): EmailConfirmationLink.objects.create_email_confirmation(request.user) return ajax_http( form_success_notification( "An email is already on its way. Just click the link inside."))
def create_email_confirmation_link(request): EmailConfirmationLink.objects.create_email_confirmation(request.user) return ajax_http(form_success_notification("An email is already on its way. Just click the link inside."))