Mercurial > agora-palash
annotate apps/profile/views.py @ 151:c7be7def8b57
Bundles! (basic functionality)
Changes made in this commit:
* Added new dependencies (see pip-requirements)
* Added new dependency and setup information to README
* Deleted the included mptt app (in apps/mptt) in favour of just adding
the dependency to pip-requirements (makes it easier to update, etc)
* Changed the import convention to use
`from apps.bundle.models import Bundle`
rather than
`from agora.apps.bundle.models import Bundle`
because Celery was having problems with the latter style. Everything
should still work.
* Moved the syntax-highlighting and related code for snippets into
separate HTML files so that they can be used by the bundle app
And, of course, the ability to upload bundles.
But wait! There's more! Changes still to come, for only $19.95 a month:
* Bundle versioning
* Automatic license integration (i.e. adding headers to files)
* The ability to download bundles (zip, tar, etc)
* Rating bundles
* And much, much more!
Batteries not included.
author | dellsystem <ilostwaldo@gmail.com> |
---|---|
date | Mon, 15 Oct 2012 00:52:00 -0400 |
parents | 5ab229c9d348 |
children |
rev | line source |
---|---|
130
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
1 from django.shortcuts import render, get_object_or_404, redirect |
29
6ba969517b9c
Implement initial profiles, cleanup models, change Free_license to FreeLicense
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
2 from django.contrib.auth.models import User |
35
290dd9208cc4
Implement editing user profiles and fix bugs related to the login/logout buttons. Implement 403 exception
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
33
diff
changeset
|
3 from django.contrib.auth.decorators import login_required |
290dd9208cc4
Implement editing user profiles and fix bugs related to the login/logout buttons. Implement 403 exception
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
33
diff
changeset
|
4 |
151
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
130
diff
changeset
|
5 from apps.free_license.models import FreeLicense |
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
130
diff
changeset
|
6 from apps.bundle.models import Bundle |
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
130
diff
changeset
|
7 from apps.snippet.models import Snippet |
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
130
diff
changeset
|
8 from apps.profile.models import Profile |
c7be7def8b57
Bundles! (basic functionality)
dellsystem <ilostwaldo@gmail.com>
parents:
130
diff
changeset
|
9 from apps.profile.forms import UserForm, ProfileForm |
29
6ba969517b9c
Implement initial profiles, cleanup models, change Free_license to FreeLicense
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
10 |
35
290dd9208cc4
Implement editing user profiles and fix bugs related to the login/logout buttons. Implement 403 exception
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
33
diff
changeset
|
11 |
130
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
12 def showprofile(request, username): |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
13 user = get_object_or_404(User, username=username) |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
14 profile = user.get_profile() |
29
6ba969517b9c
Implement initial profiles, cleanup models, change Free_license to FreeLicense
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
15 |
130
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
16 if user.first_name or user.last_name: |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
17 name = user.get_full_name() |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
18 else: |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
19 name = user.username |
35
290dd9208cc4
Implement editing user profiles and fix bugs related to the login/logout buttons. Implement 403 exception
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
33
diff
changeset
|
20 |
130
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
21 b = Bundle.objects.filter(uploader=user) |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
22 s = Snippet.objects.filter(author=user) |
33
28a512881850
Several fixes. See detailed commit message.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
30
diff
changeset
|
23 |
130
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
24 context = { |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
25 'profile': user.get_profile, |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
26 'name': name, |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
27 'bundles': Bundle.objects.filter(uploader=user), |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
28 'snippets': Snippet.objects.filter(author=user), |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
29 } |
29
6ba969517b9c
Implement initial profiles, cleanup models, change Free_license to FreeLicense
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
30 |
130
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
31 return render(request, 'profile/user.djhtml', context) |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
32 |
35
290dd9208cc4
Implement editing user profiles and fix bugs related to the login/logout buttons. Implement 403 exception
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
33
diff
changeset
|
33 |
290dd9208cc4
Implement editing user profiles and fix bugs related to the login/logout buttons. Implement 403 exception
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
33
diff
changeset
|
34 @login_required |
79
96ad476f52df
Tailor editprofile view to work only for the logged-in user
dellsystem <ilostwaldo@gmail.com>
parents:
49
diff
changeset
|
35 def editprofile(request): |
130
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
36 user = request.user |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
37 profile = user.get_profile() |
35
290dd9208cc4
Implement editing user profiles and fix bugs related to the login/logout buttons. Implement 403 exception
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
33
diff
changeset
|
38 |
130
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
39 if request.method == 'POST': |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
40 user_form = UserForm(request.POST, instance=user) |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
41 profile_form = ProfileForm(request.POST, instance=profile) |
35
290dd9208cc4
Implement editing user profiles and fix bugs related to the login/logout buttons. Implement 403 exception
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
33
diff
changeset
|
42 |
130
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
43 if user_form.is_valid() and profile_form.is_valid(): |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
44 user_form.save() |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
45 profile_form.save() |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
46 return redirect(user) |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
47 else: |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
48 user_form = UserForm(instance=user) |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
49 profile_form = ProfileForm(instance=profile) |
35
290dd9208cc4
Implement editing user profiles and fix bugs related to the login/logout buttons. Implement 403 exception
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
33
diff
changeset
|
50 |
130
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
51 context = { |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
52 'profile': profile, |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
53 'user_form': user_form, |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
54 'profile_form': profile_form, |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
55 } |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
56 |
5ab229c9d348
Add back ability to edit account settings
dellsystem <ilostwaldo@gmail.com>
parents:
101
diff
changeset
|
57 return render(request, 'profile/edit-user.djhtml', context) |