app/soc/views/user/roles.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Thu, 16 Oct 2008 15:22:41 +0000
changeset 358 843d83b87282
parent 316 9efdc7bc3565
child 365 74dec172944e
permissions -rw-r--r--
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module. Patch by: Pawel Solyga Review by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
82
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Views of a User's various Roles on the site.
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
dashboard:  dashboard view of all of a User's Roles on the site
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    20
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    21
public:  a public view of the User's Roles on the site
82
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
"""
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
__authors__ = [
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
  '"Todd Larsen" <tlarsen@google.com>',
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
  ]
1456e633bf8a Create placeholders for User Roles prototype.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    28
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    29
from google.appengine.api import users
316
9efdc7bc3565 Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    30
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    31
from django import http
316
9efdc7bc3565 Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    32
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    33
from soc.views.helpers import response_helpers
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    34
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    35
358
843d83b87282 Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    36
def dashboard(request, page=None, link_name=None,
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    37
              template='soc/user/roles/dashboard.html'):
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    38
  """A per-User dashboard of that User's Roles on the site.
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    39
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    40
  Args:
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    41
    request: the standard django request object.
358
843d83b87282 Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    42
    page: a soc.logic.site.page.Page object which is abstraction that combines 
843d83b87282 Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    43
      a Django view with sidebar menu info
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 99
diff changeset
    44
    link_name: the User's site-unique "link_name" extracted from the URL
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    45
    template: the template path to use for rendering the template.
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    46
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    47
  Returns:
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    48
    A subclass of django.http.HttpResponse with generated template.
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    49
  """
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    50
  #TODO(tlarsen): this module is currently a placeholder for future work
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    51
  
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 99
diff changeset
    52
  # TODO: check that user is logged in and "owns" the link_name;
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    53
  #   if not, call public() view instead
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    54
  #   This might be tricky, since we want to use the same style
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    55
  #   of template that was passed to us, but how do we figure out
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    56
  #   what the equivalent public.html template is?  Perhaps this
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    57
  #   view needs to require that, for a foo/bar/dashboard.html
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    58
  #   template, a corresponding foo/bar/public.html template must
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    59
  #   also exist...
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    60
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    61
  return response_helpers.respond(request,
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    62
      template, {'template': template})
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    63
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    64
358
843d83b87282 Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    65
def public(request, page=None, link_name=None,
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    66
           template='soc/user/roles/public.html'):
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    67
  """A "general public" view of a User's Roles on the site.
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    68
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    69
  Args:
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    70
    request: the standard django request object.
358
843d83b87282 Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    71
    page: a soc.logic.site.page.Page object which is abstraction that combines 
843d83b87282 Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    72
      a Django view with sidebar menu info
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 99
diff changeset
    73
    link_name: the User's site-unique "link_name" extracted from the URL
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    74
    template: the template path to use for rendering the template.
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    75
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    76
  Returns:
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    77
    A subclass of django.http.HttpResponse with generated template.
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    78
  """
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    79
  #TODO(tlarsen): this module is currently a placeholder for future work
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    80
  
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    81
  # TODO: if link_name is empty or not a valid link_name on the site, display
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    82
  # some sort of "user does not exist" page (a custom 404 page, maybe?).
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    83
  
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    84
  return response_helpers.respond(request,
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    85
      template, {'template': template})
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    86