Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.http import HttpResponse
- from django.template import loader
- from django.shortcuts import get_object_or_404, render, render_to_response, redirect
- from .models import Question, Overview
- from django.contrib.auth import login, authenticate
- from django.contrib.auth.forms import UserCreationForm
- from django.utils.safestring import mark_safe
- def update_profile(request, user_id):
- user = User.objects.get(pk=user_id)
- user.profile.bio = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit...'
- user.save()
- @login_required
- @transaction.atomic
- def update_profile(request):
- if request.method == 'POST':
- user_form = UserForm(request.POST, instance=request.user)
- profile_form = ProfileForm(request.POST, instance=request.user.profile)
- if user_form.is_valid() and profile_form.is_valid():
- user_form.save()
- profile_form.save()
- messages.success(request, _('Your profile was successfully updated!'))
- return redirect('settings:profile')
- else:
- messages.error(request, _('Please correct the error below.'))
- else:
- user_form = UserForm(instance=request.user)
- profile_form = ProfileForm(instance=request.user.profile)
- return render(request, 'profiles/profile.html', {
- 'user_form': user_form,
- 'profile_form': profile_form
- })
- '''def calendar(request, year, month):
- year = int(year)
- month = int(month)
- my_workouts = Overview.objects.order_by('day').filter(
- day__year=year, day__month=month
- )
- cal = Calendar(my_workouts).formatmonth(year, month)
- return render_to_response('my_template.html', {'calendar': mark_safe(cal),})'''
- def bandchange(request):
- return HttpResponse("You're on the alteration page")
- def bandview(request):
- return HttpResponse("This is the band info page")
- def signup(request):
- if request.method == 'POST':
- form = UserCreationForm(request.POST)
- if form.is_valid():
- form.save()
- username = form.cleaned_data.get('username')
- raw_password = form.cleaned_data.get('password1')
- user = authenticate(username=username, password=raw_password)
- login(request, user)
- return redirect('home')
- else:
- form = UserCreationForm()
- return render(request, 'signup.html', {'form': form})
- """def index(request):
- latest_question_list = Question.objects.order_by('-pub_date')[:5]
- context = {'latest_question_list': latest_question_list}
- return render(request, 'polls/index.html', context)
- def results(request, question_id):
- response = "You're looking at the results of question %s."
- return HttpResponse(response % question_id)
- def vote(request, question_id):
- return HttpResponse("You're voting on question %s." % question_id)
- def detail(request, question_id):
- question = get_object_or_404(Question, pk=question_id)
- return render(request, 'polls/detail.html', {'question': question})"""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement