Style fixes, add missing docstring, fix some wrong calls to super classes and removal of unused imports in soc.views.helper.
authorPawel Solyga <Pawel.Solyga@gmail.com>
Fri, 03 Apr 2009 17:43:41 +0000
changeset 2077 fd2e83a297c7
parent 2076 1cd180cc56c9
child 2078 0b45b07a9d0c
Style fixes, add missing docstring, fix some wrong calls to super classes and removal of unused imports in soc.views.helper. Patch by: Pawel Solyga Reviewed by: to-be-reviewed
app/soc/views/helper/access.py
app/soc/views/helper/decorators.py
app/soc/views/helper/dynaform.py
app/soc/views/helper/forms.py
app/soc/views/helper/list_info.py
app/soc/views/helper/lists.py
app/soc/views/helper/responses.py
app/soc/views/helper/templatetags/forms_helpers.py
app/soc/views/helper/widgets.py
--- a/app/soc/views/helper/access.py	Fri Apr 03 17:41:08 2009 +0000
+++ b/app/soc/views/helper/access.py	Fri Apr 03 17:43:41 2009 +0000
@@ -165,6 +165,8 @@
 
   @wraps(fun)
   def wrapper(self, django_args, *args, **kwargs):
+    """Decorator wrapper method.
+    """
     if django_args.get('SIDEBAR_CALLING'):
       return
     return fun(self, django_args, *args, **kwargs)
@@ -179,6 +181,8 @@
 
   @wraps(fun)
   def wrapper(self, django_args, *args, **kwargs):
+    """Decorator wrapper method.
+    """
     if django_args.get('SIDEBAR_CALLING'):
       raise out_of_band.Error("Sidebar Calling")
     return fun(self, django_args, *args, **kwargs)
@@ -197,6 +201,8 @@
 
     @wraps(fun)
     def wrapper(self, django_args=None, *args, **kwargs):
+      """Decorator wrapper method.
+      """
       try:
         # if the check passes we allow access regardless
         return self.doCheck(checker_name, django_args, [])
@@ -207,8 +213,8 @@
 
   return decorator
 
-
-allowDeveloper = allowIfCheckPasses('checkIsDeveloper')
+# pylint: disable-msg=C0103
+allowDeveloper = allowIfCheckPasses('checkIsDeveloper') 
 
 
 class Checker(object):
@@ -439,7 +445,7 @@
     checks raised is reraised.
     """
 
-    first = None
+    first = Exception()
 
     for checker_name, args in checks:
       try:
@@ -723,7 +729,11 @@
     self._checkIsActive(django_args, logic, fields)
 
   def checkHasActiveRoleForKeyFieldsAsScope(self, django_args, logic):
-    """
+    """Checks that the user has the specified active role.
+    
+    Args:
+      django_args: a dictionary with django's arguments
+      logic: the logic that should be used to look up the entity
     """
 
     key_fields = "%(scope_path)s/%(link_id)s" % django_args
@@ -1125,7 +1135,8 @@
     if not django_args.get('scope_path'):
       raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_DENIED_MSG)
 
-    program_entity = program_logic.getFromKeyNameOr404(django_args['scope_path'])
+    program_entity = program_logic.getFromKeyNameOr404(
+        django_args['scope_path'])
     user_entity = user_logic.getForCurrentAccount()
 
     filter = {'user': user_entity,
@@ -1140,7 +1151,7 @@
           message_fmt=DEF_ALREADY_PARTICIPATING_MSG)
 
     # fill the role_list with all the mentor and org admin roles for this user
-    role_list = []
+    # role_list = []
 
     filter = {'user': user_entity,
               'program': program_entity,
@@ -1392,13 +1403,14 @@
 
   @allowDeveloper
   @denySidebar
-  def checkIsAllowedToManageRole(self, django_args, role_logic, manage_role_logic):
+  def checkIsAllowedToManageRole(self, django_args, logic_for_role, 
+      manage_role_logic):
     """Returns an alternate HTTP response if the user is not allowed to manage
        the role given in args.
 
      Args:
        django_args: a dictionary with django's arguments
-       role_logic: determines the logic for the role in args.
+       logic_for_role: determines the logic for the role in args.
        manage_role_logic: determines the logic for the role which is allowed
            to manage this role.
 
@@ -1413,12 +1425,13 @@
 
     try:
       # check if it is my role the user's own role
-      self.checkHasActiveRoleForScope(django_args, role_logic)
+      self.checkHasActiveRoleForScope(django_args, logic_for_role)
       return
     except out_of_band.Error:
       pass
 
-    # apparently it's not the user's role so check if managing this role is allowed
+    # apparently it's not the user's role so check 
+    # if managing this role is allowed
     fields = {
         'link_id': django_args['link_id'],
         'scope_path': django_args['scope_path'],
--- a/app/soc/views/helper/decorators.py	Fri Apr 03 17:41:08 2009 +0000
+++ b/app/soc/views/helper/decorators.py	Fri Apr 03 17:43:41 2009 +0000
@@ -37,6 +37,9 @@
 
 
 class Error(Exception):
+  """Base class for all exceptions raised by this module.
+  """
+  
   pass
 
 
@@ -52,6 +55,8 @@
 
   @wraps(func)
   def view_wrapper(request, *args, **kwds):
+    """View decorator wrapper method.
+    """
     site = site_logic.getSingleton()
 
     # don't redirect admins, or if we're at /maintenance already
@@ -87,6 +92,8 @@
 
   @wraps(func)
   def wrapper(self, *args, **kwargs):
+    """Decorator wrapper method.
+    """
     params = kwargs.get('params', {})
     kwargs['params'] = dicts.merge(params, self._params)
     return func(self, *args, **kwargs)
@@ -108,6 +115,8 @@
 
   @wraps(func)
   def wrapper(self, request, access_type, *args, **kwargs):
+    """Decorator wrapper method.
+    """
     params = kwargs.get('params', {})
 
     # Try to extract rights
--- a/app/soc/views/helper/dynaform.py	Fri Apr 03 17:41:08 2009 +0000
+++ b/app/soc/views/helper/dynaform.py	Fri Apr 03 17:43:41 2009 +0000
@@ -41,7 +41,7 @@
   and the values are used as the property value.
   """
 
-  def __new__(cls, class_name, bases, attrs):
+  def __new__(mcs, class_name, bases, attrs):
     """See djangoforms.ModelFormMetaclass on how the __new__ method
     is used, for an explanation on how this class modifies the default
     behavior, see the DynaFormMetaclass's docstring.
@@ -61,7 +61,7 @@
         attrs[key] = value
 
     # Leave the rest to djangoforms.ModelFormMetaclass.
-    return super(DynaFormMetaclass, cls).__new__(cls, class_name, bases, attrs)
+    return super(DynaFormMetaclass, mcs).__new__(mcs, class_name, bases, attrs)
 
 
 def newDynaForm(dynamodel=None, dynabase=None, dynainclude=None, 
@@ -164,7 +164,7 @@
   and the values are used as the property value.
   """
 
-  def __new__(cls, name, bases, attrs):
+  def __new__(mcs, name, bases, attrs):
     """See djangoforms.ModelFormMetaclass on how the __new__ method
     is used, for an explanation on how this class modifies the default
     behavior, see the DynaFormMetaclass's docstring.
@@ -177,7 +177,7 @@
       attrs[key] = value
 
     # Leave the rest to type
-    return super(DynaFieldMetaclass, cls).__new__(cls, name, bases, attrs)
+    return super(DynaFieldMetaclass, mcs).__new__(mcs, name, bases, attrs)
 
 
 def newDynaField(field, base, passthrough):
@@ -202,7 +202,7 @@
     if key in properties:
       del properties[key]
 
-  class DynaField(base):
+  class DynaField(object):
     """The dynamically created Field class.
     """
 
--- a/app/soc/views/helper/forms.py	Fri Apr 03 17:41:08 2009 +0000
+++ b/app/soc/views/helper/forms.py	Fri Apr 03 17:43:41 2009 +0000
@@ -28,7 +28,6 @@
 
 from django import forms
 from django.utils import safestring
-from django.utils.safestring import mark_safe
 
 
 class BaseForm(djangoforms.ModelForm):
@@ -60,7 +59,7 @@
       *args, **kwargs:  passed through to parent __init__() constructor
     """
 
-    super(djangoforms.ModelForm, self).__init__(*args, **kwargs)
+    super(BaseForm, self).__init__(*args, **kwargs)
 
     renames = {
         'verbose_name': 'label',
--- a/app/soc/views/helper/list_info.py	Fri Apr 03 17:41:08 2009 +0000
+++ b/app/soc/views/helper/list_info.py	Fri Apr 03 17:43:41 2009 +0000
@@ -31,6 +31,8 @@
   """
 
   def wrapper(item, _):
+    """Decorator wrapper method.
+    """
     info = {'rank': ranking[item]}
 
     if item in assigned_proposals:
--- a/app/soc/views/helper/lists.py	Fri Apr 03 17:41:08 2009 +0000
+++ b/app/soc/views/helper/lists.py	Fri Apr 03 17:43:41 2009 +0000
@@ -23,8 +23,6 @@
   ]
 
 
-import itertools
-
 from soc.logic import dicts
 from soc.logic.models.user import logic as user_logic
 
@@ -166,7 +164,7 @@
   if more:
     del data[limit:]
 
-  newest = next = prev = export_link =''
+  newest = next = prev = export_link = ''
 
   base_params = dict(i for i in request.GET.iteritems() if
                      i[0].startswith('offset_') or i[0].startswith('limit_'))
--- a/app/soc/views/helper/responses.py	Fri Apr 03 17:41:08 2009 +0000
+++ b/app/soc/views/helper/responses.py	Fri Apr 03 17:43:41 2009 +0000
@@ -25,7 +25,6 @@
 
 
 from google.appengine.api import users
-from google.appengine.ext import db
 
 from django import http
 from django.template import loader
@@ -39,9 +38,6 @@
 from soc.views.helper import templates
 from soc.views.sitemap import sidebar
 
-import soc.logic
-import soc.views.helper.requests
-
 
 def respond(request, template, context=None, response_args=None,
             response_headers=None):
--- a/app/soc/views/helper/templatetags/forms_helpers.py	Fri Apr 03 17:41:08 2009 +0000
+++ b/app/soc/views/helper/templatetags/forms_helpers.py	Fri Apr 03 17:43:41 2009 +0000
@@ -33,8 +33,6 @@
 
 from soc.logic import accounts
 from soc.logic import dicts
-from soc.logic.models import user as user_logic
-from soc.views.helper import redirects
 from soc.views.helper import widgets
 
 
--- a/app/soc/views/helper/widgets.py	Fri Apr 03 17:41:08 2009 +0000
+++ b/app/soc/views/helper/widgets.py	Fri Apr 03 17:43:41 2009 +0000
@@ -23,8 +23,6 @@
   ]
 
 
-import copy
-
 from django import forms
 from django.forms import util
 from django.forms import widgets
@@ -118,7 +116,7 @@
       *args, **kwargs:  passed through to parent __init__() constructor
     """
 
-    super(forms.widgets.Textarea, self).__init__(*args, **kwargs)
+    super(FullTinyMCE, self).__init__(*args, **kwargs)
     self.mce_settings = self.DEF_MCE_SETTINGS
   
   def render(self, name, value, attrs=None):
@@ -189,10 +187,10 @@
     super(AgreementField, self).__init__(*args, **kwargs)
 
   def render(self, name, value, attrs=None):
-    """
+    """HTML renderer for Agreement field.
     """
-
-    url = '<a href="%s" target="_blank">Full Text</a>' % self.url if self.url else ""
+    url_text = '<a href="%s" target="_blank">Full Text</a>'
+    url = url_text % self.url if self.url else ""
     value = self.text.replace('\n', '<BR />')
     result = self.HTML_CODE % {'url': url, 'text': value}
     return result