Mercurial > agora
annotate views.py @ 156:8c5810c3be63
Fix reference to snippet_new view on code page
author | dellsystem <ilostwaldo@gmail.com> |
---|---|
date | Mon, 15 Oct 2012 01:43:53 -0400 |
parents | c7be7def8b57 |
children | a5547f079190 |
rev | line source |
---|---|
107 | 1 from django.contrib.auth import login, authenticate |
2 from django.contrib.auth.forms import AuthenticationForm | |
3 from django.shortcuts import render, redirect | |
4 from django.core.urlresolvers import reverse | |
5 from registration.forms import RegistrationForm | |
6 | |
7 from agora.apps.snippet.models import Snippet | |
151
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
139
diff
changeset
|
8 from agora.apps.bundle.models import Bundle |
107 | 9 |
10 | |
11 def code(request): | |
12 context = { | |
139
b8e0bdc37e32
Hide snippets created by anonymous users
dellsystem <ilostwaldo@gmail.com>
parents:
107
diff
changeset
|
13 'snippets': Snippet.objects.public()[:5], |
151
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
139
diff
changeset
|
14 'bundles': Bundle.objects.all()[:5], |
107 | 15 'forge': None, # temp |
16 } | |
17 | |
18 return render(request, 'code.djhtml', context) | |
19 | |
20 | |
21 def login_register(request): | |
22 form = None | |
23 next_url = None | |
24 | |
25 if request.method == 'POST': | |
26 action = request.POST.get('action') | |
27 next_url = request.GET.get('next') or reverse('login') | |
28 | |
29 if action == 'login': | |
30 username = request.POST.get('username', '') | |
31 password = request.POST.get('password1', '') | |
32 | |
33 if username and password: | |
34 user = authenticate(username=username, password=password) | |
35 login(request, user) | |
36 | |
37 return redirect(next_url) | |
38 else: | |
39 form = { | |
40 'password1': { | |
41 'errors': 'Please enter a username and password.', | |
42 }, | |
43 } | |
44 elif action == 'register': | |
45 form = RegistrationForm(request.POST) | |
46 | |
47 if form.is_valid(): | |
48 user = form.save() | |
49 login(request, user) | |
50 return redirect(next_url) | |
51 else: | |
52 # The action is not set. Malicious submission? | |
53 pass | |
54 | |
55 context = { | |
56 'next_url': next_url, | |
57 'form': form, | |
58 } | |
59 | |
60 return render(request, 'login.djhtml', context) |