Advertisement
ep123pearce

Untitled

Jan 7th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. from django.http import HttpResponse
  2. from django.template import loader
  3. from django.shortcuts import get_object_or_404, render, render_to_response, redirect
  4. from .models import Question, Overview
  5. from django.contrib.auth import login, authenticate
  6. from django.contrib.auth.forms import UserCreationForm
  7. from django.utils.safestring import mark_safe
  8.  
  9. def update_profile(request, user_id):
  10. user = User.objects.get(pk=user_id)
  11. user.profile.bio = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit...'
  12. user.save()
  13.  
  14. @login_required
  15. @transaction.atomic
  16. def update_profile(request):
  17. if request.method == 'POST':
  18. user_form = UserForm(request.POST, instance=request.user)
  19. profile_form = ProfileForm(request.POST, instance=request.user.profile)
  20. if user_form.is_valid() and profile_form.is_valid():
  21. user_form.save()
  22. profile_form.save()
  23. messages.success(request, _('Your profile was successfully updated!'))
  24. return redirect('settings:profile')
  25. else:
  26. messages.error(request, _('Please correct the error below.'))
  27. else:
  28. user_form = UserForm(instance=request.user)
  29. profile_form = ProfileForm(instance=request.user.profile)
  30. return render(request, 'profiles/profile.html', {
  31. 'user_form': user_form,
  32. 'profile_form': profile_form
  33. })
  34.  
  35.  
  36. '''def calendar(request, year, month):
  37. year = int(year)
  38. month = int(month)
  39. my_workouts = Overview.objects.order_by('day').filter(
  40. day__year=year, day__month=month
  41. )
  42. cal = Calendar(my_workouts).formatmonth(year, month)
  43. return render_to_response('my_template.html', {'calendar': mark_safe(cal),})'''
  44.  
  45. def bandchange(request):
  46. return HttpResponse("You're on the alteration page")
  47.  
  48. def bandview(request):
  49. return HttpResponse("This is the band info page")
  50.  
  51. def signup(request):
  52. if request.method == 'POST':
  53. form = UserCreationForm(request.POST)
  54. if form.is_valid():
  55. form.save()
  56. username = form.cleaned_data.get('username')
  57. raw_password = form.cleaned_data.get('password1')
  58. user = authenticate(username=username, password=raw_password)
  59. login(request, user)
  60. return redirect('home')
  61. else:
  62. form = UserCreationForm()
  63. return render(request, 'signup.html', {'form': form})
  64.  
  65. """def index(request):
  66. latest_question_list = Question.objects.order_by('-pub_date')[:5]
  67. context = {'latest_question_list': latest_question_list}
  68. return render(request, 'polls/index.html', context)
  69.  
  70.  
  71. def results(request, question_id):
  72. response = "You're looking at the results of question %s."
  73. return HttpResponse(response % question_id)
  74.  
  75. def vote(request, question_id):
  76. return HttpResponse("You're voting on question %s." % question_id)
  77.  
  78. def detail(request, question_id):
  79. question = get_object_or_404(Question, pk=question_id)
  80. return render(request, 'polls/detail.html', {'question': question})"""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement