app/soc/views/user/roles.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Mon, 13 Oct 2008 21:54:51 +0000
changeset 316 9efdc7bc3565
parent 299 a1cc853a56e5
child 358 843d83b87282
permissions -rw-r--r--
Add missing blank lines between imports and sort all of the imports. 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
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 99
diff changeset
    36
def dashboard(request, 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.
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 99
diff changeset
    42
    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
    43
    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
    44
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    45
  Returns:
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    46
    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
    47
  """
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    48
  #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
    49
  
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 99
diff changeset
    50
  # 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
    51
  #   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
    52
  #   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
    53
  #   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
    54
  #   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
    55
  #   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
    56
  #   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
    57
  #   also exist...
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    58
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    59
  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
    60
      template, {'template': template})
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    61
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    62
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 99
diff changeset
    63
def public(request, link_name=None,
84
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    64
           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
    65
  """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
    66
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    67
  Args:
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    68
    request: the standard django request object.
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 99
diff changeset
    69
    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
    70
    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
    71
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    72
  Returns:
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    73
    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
    74
  """
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    75
  #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
    76
  
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    77
  # 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
    78
  # 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
    79
  
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    80
  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
    81
      template, {'template': template})
1b31d238ba39 Flesh out the user/roles placeholders a little bit more.
Todd Larsen <tlarsen@google.com>
parents: 82
diff changeset
    82