annotate personasbackend/personas/views.py @ 149:98257bc9841e

We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
author Atul Varma <varmaa@toolness.com>
date Fri, 04 Apr 2008 12:01:44 -0700
parents 612212345759
children 052bf8a07b76
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
1 import os
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
2 import mimetypes
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
3
64
5f21f8d3334b Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
4 from django.http import HttpResponseRedirect, HttpResponseForbidden
132
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
5 from django.http import Http404
96
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
6 from django.http import HttpResponse, HttpResponseBadRequest
40
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
7 from django.template import RequestContext
31
ada72ce61fc2 Added a trivial login page.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
8 from django.contrib.auth.decorators import login_required
39
bd1cdb15ef85 Added persona form submission validation, fixed some things in model logic; submitting forms successfully now properly redirects the user to an edit page.
Atul Varma <varmaa@toolness.com>
parents: 38
diff changeset
9 from django.core.urlresolvers import reverse
42
6cde01f6012a Resolved a TODO involving get_object_or_404().
Atul Varma <varmaa@toolness.com>
parents: 41
diff changeset
10 from django.shortcuts import render_to_response, get_object_or_404
31
ada72ce61fc2 Added a trivial login page.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
11
128
9bcc77e37c19 Renamed all references of PersonasBackend to personasbackend, matching PEP-8.
Atul Varma <varmaa@toolness.com>
parents: 127
diff changeset
12 from personasbackend.personas import models
9bcc77e37c19 Renamed all references of PersonasBackend to personasbackend, matching PEP-8.
Atul Varma <varmaa@toolness.com>
parents: 127
diff changeset
13 from personasbackend.personas import forms
20
ccb027c6862a Added simple JSON views that generate personas_categories.dat and personas_all.dat.
Atul Varma <varmaa@toolness.com>
parents: 2
diff changeset
14
145
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
15 NO_THUMBNAIL_IMAGE = "https://addons.mozilla.org/img/addon-icn.png"
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
16
132
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
17 def _render_static_persona( img_src, action ):
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
18 if action == "footer":
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
19 position = "bottom left"
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
20 else:
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
21 position = "top right"
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
22
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
23 return render_to_response(
134
aaa032194990 Got rid of a TODO by renaming a file.
Atul Varma <varmaa@toolness.com>
parents: 132
diff changeset
24 "personas/static_persona.xul",
132
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
25 { "image" : img_src, "position" : position },
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
26 mimetype = "application/vnd.mozilla.xul+xml"
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
27 )
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
28
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
29 def hosted_static_persona( request, persona_id ):
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
30 persona = get_object_or_404( models.Persona, id=persona_id )
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
31
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
32 if not (persona.header_img and persona.footer_img):
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
33 raise Http404( "Persona is not statically hosted." )
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
34
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
35 action = request.GET.get( "action", "" )
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
36
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
37 if action == "footer":
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
38 img_src = persona.get_absolute_footer_img_url()
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
39 elif action == "header":
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
40 img_src = persona.get_absolute_header_img_url()
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
41 else:
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
42 return HttpResponseBadRequest( "Invalid or unsupported action: %s" %
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
43 action )
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
44
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
45 return _render_static_persona( img_src, action )
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
46
96
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
47 def legacy_cbeard_persona( request, name ):
130
694ff9b2474d Added support for persona thumbnails.
Atul Varma <varmaa@toolness.com>
parents: 129
diff changeset
48 urldict = {"name" : name}
96
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
49
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
50 action = request.GET.get( "action", "" )
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
51
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
52 if action == "footer":
130
694ff9b2474d Added support for persona thumbnails.
Atul Varma <varmaa@toolness.com>
parents: 129
diff changeset
53 img_src = models.LEGACY_FOOTER_URL % urldict
96
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
54 elif action == "header":
130
694ff9b2474d Added support for persona thumbnails.
Atul Varma <varmaa@toolness.com>
parents: 129
diff changeset
55 img_src = models.LEGACY_HEADER_URL % urldict
96
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
56 else:
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
57 return HttpResponseBadRequest( "Invalid or unsupported action: %s" %
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
58 action )
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
59
132
09c808e39a98 Re-added support for hosted static personas in the backend, although they're not very humanely supported by the UI at present.
Atul Varma <varmaa@toolness.com>
parents: 131
diff changeset
60 return _render_static_persona( img_src, action )
96
89c6f5ddaded Added a wrapper that wraps a legacy cbeard-style persona in the new dynamic persona API.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
61
140
e48318d2ff8a Thumbnails now look better, although the internal architecture used to generate them on-the-fly is a bit questionable.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
62 def thumbnail( request, persona_id ):
e48318d2ff8a Thumbnails now look better, although the internal architecture used to generate them on-the-fly is a bit questionable.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
63 persona = get_object_or_404( models.Persona, id=persona_id )
e48318d2ff8a Thumbnails now look better, although the internal architecture used to generate them on-the-fly is a bit questionable.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
64
145
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
65 if not persona.create_thumbnail():
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
66 return HttpResponseRedirect( NO_THUMBNAIL_IMAGE )
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
67
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
68 filename = persona.thumbnail_filename
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
69
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
70 mimetype = mimetypes.types_map[ os.path.splitext( filename )[1] ]
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
71
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
72 image_data = open( filename, "rb" ).read()
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
73
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
74 return HttpResponse( image_data,
f07025da528b Thumbnails are now dynamically generated by a view function; if things get slow, we'll rely on a front-end cache like squid to speed it up.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
75 mimetype = mimetype )
140
e48318d2ff8a Thumbnails now look better, although the internal architecture used to generate them on-the-fly is a bit questionable.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
76
25
197b05fbd4cc Added a trivial list view.
Atul Varma <varmaa@toolness.com>
parents: 20
diff changeset
77 def list_view( request ):
67
029e3ad3cde0 Personas list view now only shows published personas. Admin personas index view now shows columns for status and date published to make approving recently-changed personas and other workflow tasks easier.
Atul Varma <varmaa@toolness.com>
parents: 66
diff changeset
78 personas = models.Persona.objects.filter( status="published" )
40
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
79 return render_to_response(
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
80 "personas/list.html",
67
029e3ad3cde0 Personas list view now only shows published personas. Admin personas index view now shows columns for status and date published to make approving recently-changed personas and other workflow tasks easier.
Atul Varma <varmaa@toolness.com>
parents: 66
diff changeset
81 { "personas" : personas,
53
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
82 "title" : "Browse Personas" },
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
83 context_instance = RequestContext(request)
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
84 )
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
85
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
86 def home_view( request ):
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
87 return render_to_response(
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
88 "personas/home.html",
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
89 { "title" : "Home" },
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
90 context_instance = RequestContext(request)
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
91 )
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
92
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
93 def todo_view( request ):
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
94 return render_to_response(
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
95 "personas/todo.html",
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
96 { "title" : "Under Construction" },
40
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
97 context_instance = RequestContext(request)
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
98 )
37
ad477306dd51 A bit of refactoring to view logic.
Atul Varma <varmaa@toolness.com>
parents: 36
diff changeset
99
58
173d6fa4069f Added sections.py, which makes site navigation code simpler and more consistent.
Atul Varma <varmaa@toolness.com>
parents: 55
diff changeset
100 def new_view( request ):
173d6fa4069f Added sections.py, which makes site navigation code simpler and more consistent.
Atul Varma <varmaa@toolness.com>
parents: 55
diff changeset
101 return edit_view( request )
173d6fa4069f Added sections.py, which makes site navigation code simpler and more consistent.
Atul Varma <varmaa@toolness.com>
parents: 55
diff changeset
102
31
ada72ce61fc2 Added a trivial login page.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
103 @login_required
34
f83712466fe6 Added functionality to edit an existing persona, and a number of TODOs.
Atul Varma <varmaa@toolness.com>
parents: 33
diff changeset
104 def edit_view( request, persona_id=None ):
f83712466fe6 Added functionality to edit an existing persona, and a number of TODOs.
Atul Varma <varmaa@toolness.com>
parents: 33
diff changeset
105 if persona_id is None:
f83712466fe6 Added functionality to edit an existing persona, and a number of TODOs.
Atul Varma <varmaa@toolness.com>
parents: 33
diff changeset
106 persona = None
53
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
107 pageTitle = "Create a new Persona"
149
98257bc9841e We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents: 146
diff changeset
108 formClass = forms.NewPersonaForm
34
f83712466fe6 Added functionality to edit an existing persona, and a number of TODOs.
Atul Varma <varmaa@toolness.com>
parents: 33
diff changeset
109 else:
42
6cde01f6012a Resolved a TODO involving get_object_or_404().
Atul Varma <varmaa@toolness.com>
parents: 41
diff changeset
110 persona = get_object_or_404( models.Persona, id=persona_id )
64
5f21f8d3334b Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
111 if not persona.can_user_edit( request.user ):
5f21f8d3334b Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
112 return HttpResponseForbidden(
5f21f8d3334b Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
113 "<h1>You do not have permission to edit "
5f21f8d3334b Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
114 "this Persona.</h1>"
5f21f8d3334b Only users who have the personas.can_publish permission or who own a persona can edit them now; added more workflow logic. I'm not entirely happy with the way the workflow logic is structured right now, but this seems to work okay for the time being.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
115 )
149
98257bc9841e We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents: 146
diff changeset
116 pageTitle = "Edit Persona \"%s\"" % persona.name
98257bc9841e We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents: 146
diff changeset
117 formClass = forms.EditPersonaForm
34
f83712466fe6 Added functionality to edit an existing persona, and a number of TODOs.
Atul Varma <varmaa@toolness.com>
parents: 33
diff changeset
118
33
2b5a8b3b8bef It's now possible for normal end-users to create new personas.
Atul Varma <varmaa@toolness.com>
parents: 31
diff changeset
119 if request.method == "POST":
149
98257bc9841e We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents: 146
diff changeset
120 form = formClass( request.POST, request.FILES,
98257bc9841e We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents: 146
diff changeset
121 instance=persona )
40
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
122 if form.is_valid():
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
123 newPersona = form.save( commit=False )
135
bc25c5570ad8 If the user doesn't submit a new header/footer image on the edit form, then the old one is retained.
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
124
40
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
125 if persona is None:
136
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
126 msgText = "Persona created successfully."
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
127 waitText = ("It will need "
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
128 "to be reviewed by a staff member "
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
129 "before it is published.")
40
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
130 else:
135
bc25c5570ad8 If the user doesn't submit a new header/footer image on the edit form, then the old one is retained.
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
131 if (not newPersona.header_img) and persona.header_img:
bc25c5570ad8 If the user doesn't submit a new header/footer image on the edit form, then the old one is retained.
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
132 newPersona.header_img = persona.header_img
bc25c5570ad8 If the user doesn't submit a new header/footer image on the edit form, then the old one is retained.
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
133 if (not newPersona.footer_img) and persona.footer_img:
bc25c5570ad8 If the user doesn't submit a new header/footer image on the edit form, then the old one is retained.
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
134 newPersona.footer_img = persona.footer_img
136
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
135 msgText = "Persona edited successfully."
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
136 waitText = ("Your changes "
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
137 "will need to be approved by a staff member "
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
138 "before they can take effect.")
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
139
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
140 if not request.user.has_perm("personas.can_publish"):
51c2cba0edcd Messages telling users they'll have to wait for their persona/changes to be approved are now only shown if the user doesn't have permission to publish.
Atul Varma <varmaa@toolness.com>
parents: 135
diff changeset
141 msgText += " " + waitText
135
bc25c5570ad8 If the user doesn't submit a new header/footer image on the edit form, then the old one is retained.
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
142
bc25c5570ad8 If the user doesn't submit a new header/footer image on the edit form, then the old one is retained.
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
143 newPersona.save( updater = request.user )
40
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
144 request.user.message_set.create( message = msgText )
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
145 url = reverse("edit-persona", args=[newPersona.id])
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
146 return HttpResponseRedirect( url )
33
2b5a8b3b8bef It's now possible for normal end-users to create new personas.
Atul Varma <varmaa@toolness.com>
parents: 31
diff changeset
147 else:
149
98257bc9841e We no longer require users to manually click the 'agree to terms' button after they've initially created their persona.
Atul Varma <varmaa@toolness.com>
parents: 146
diff changeset
148 form = formClass( instance=persona )
40
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
149
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
150 return render_to_response(
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
151 "personas/edit.html",
53
7a20574bedc8 Made templates more robust, fixed broken links, etc.
Atul Varma <varmaa@toolness.com>
parents: 46
diff changeset
152 { "form" : form,
146
612212345759 Persona thumbnails are now displayed on the edit persona form.
Atul Varma <varmaa@toolness.com>
parents: 145
diff changeset
153 "title" : pageTitle,
612212345759 Persona thumbnails are now displayed on the edit persona form.
Atul Varma <varmaa@toolness.com>
parents: 145
diff changeset
154 "persona" : persona },
40
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
155 context_instance = RequestContext(request)
748547f73357 Refactored some view logic and added messaging capabilities, so that the end-user is properly notified when persona creation/editing is successful.
Atul Varma <varmaa@toolness.com>
parents: 39
diff changeset
156 )