Style fixes and removal of unused imports in soc.views.models.
Patch by: Pawel Solyga
Reviewed by: to-be-reviewed
--- a/app/soc/views/models/base.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/base.py Fri Apr 03 17:41:08 2009 +0000
@@ -25,7 +25,6 @@
import csv
-import datetime
import StringIO
from google.appengine.ext import db
@@ -745,22 +744,25 @@
params = params.copy()
params['export_extension'] = '.csv'
params['export_content_type'] = 'text/csv'
- fieldnames = params['csv_fieldnames']
+ # fieldnames = params['csv_fieldnames']
- f = StringIO.StringIO()
+ file_handler = StringIO.StringIO()
if key_order:
- writer = csv.DictWriter(f, key_order, dialect='excel')
+ writer = csv.DictWriter(file_handler, key_order, dialect='excel')
writer.writerow(dicts.identity(key_order))
# encode the data to UTF-8 to ensure compatibiliy
for row_dict in data:
for key in row_dict.keys():
value = row_dict[key]
- row_dict[key] = value.encode("utf-8") if isinstance(value, basestring) else str(value)
+ if isinstance(value, basestring):
+ row_dict[key] = value.encode("utf-8")
+ else:
+ row_dict[key] = str(value)
writer.writerow(row_dict)
else:
- writer = csv.writer(f, dialect='excel')
+ writer = csv.writer(file_handler, dialect='excel')
# encode the data to UTF-8 to ensure compatibiliy
for row in data:
@@ -769,7 +771,7 @@
else:
writer.writerow(row)
- data = f.getvalue()
+ data = file_handler.getvalue()
return self.download(request, data, filename, params)
@@ -834,7 +836,8 @@
field = getter(entity)
form.fields[field_name].initial = field.link_id if field else None
except db.Error:
- pass
+ # TODO(Pawel.Solyga): use logging to log exception
+ return
for field, value in request.GET.iteritems():
if field in form.fields:
--- a/app/soc/views/models/club_app.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/club_app.py Fri Apr 03 17:41:08 2009 +0000
@@ -34,8 +34,6 @@
from soc.views.helper import decorators
from soc.views.models import group_app
-import soc.logic.dicts
-
class View(group_app.View):
"""View methods for the Club Application model.
--- a/app/soc/views/models/club_member.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/club_member.py Fri Apr 03 17:41:08 2009 +0000
@@ -132,6 +132,6 @@
list = decorators.view(view.list)
manage = decorators.view(view.manage)
process_request = decorators.view(view.processRequest)
-request = decorators.view(view.request)
+role_request = decorators.view(view.request)
public = decorators.view(view.public)
export = decorators.view(view.export)
--- a/app/soc/views/models/comment.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/comment.py Fri Apr 03 17:41:08 2009 +0000
@@ -22,33 +22,19 @@
'"Matthew Wilkes" <matthew@matthewwilkes.co.uk>',
]
+
import time
-from google.appengine.api import users
-from google.appengine.ext.db import Key
-
from django import forms
-from soc.logic import cleaning
from soc.logic import dicts
-from soc.logic import validate
from soc.logic.models.user import logic as user_logic
from soc.logic.models.comment import logic as comment_logic
-from soc.logic.models.document import logic as document_logic
-from soc.logic.models.linkable import logic as link_logic
-from soc.models import linkable
from soc.views import helper
from soc.views.helper import access
from soc.views.helper import redirects
-from soc.views.helper import params as params_helper
from soc.views.models import base
-import soc.models.comment
-import soc.logic.models.comment
-import soc.logic.dicts
-import soc.views.helper
-import soc.views.helper.widgets
-
class View(base.View):
"""View methods for the comment model.
@@ -65,9 +51,10 @@
"""
rights = access.Checker(params)
- rights['create'] = [('checkSeeded', ['checkIsDocumentReadable','scope_path'])]
- rights['edit'] = [('checkIsMyEntity', [comment_logic,'author', True])]
- rights['delete'] = [('checkIsMyEntity', [comment_logic,'author', True])]
+ rights['create'] = [('checkSeeded', ['checkIsDocumentReadable',
+ 'scope_path'])]
+ rights['edit'] = [('checkIsMyEntity', [comment_logic, 'author', True])]
+ rights['delete'] = [('checkIsMyEntity', [comment_logic, 'author', True])]
new_params = {}
new_params['logic'] = comment_logic
@@ -95,8 +82,8 @@
new_params['edit_extra_dynaproperties'] = {
'link_id': forms.CharField(widget=forms.HiddenInput, required=True),
- 'created_by': forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(),
- required=False),
+ 'created_by': forms.fields.CharField(
+ widget=helper.widgets.ReadOnlyInput(), required=False),
}
params = dicts.merge(params, new_params)
@@ -121,7 +108,7 @@
context['comment_on_name'] = self._params['comment_on_name']
context['work_link'] = redirect
- def _editPost(self, request, entity, fields, params=None):
+ def _editPost(self, request, entity, fields):
"""See base.View._editPost().
"""
@@ -130,7 +117,7 @@
if not entity:
fields['author'] = user
- fields['link_id'] = 't%i' %(int(time.time()*100))
+ fields['link_id'] = 't%i' % (int(time.time()*100))
else:
fields['author'] = entity.author
fields['link_id'] = entity.link_id
--- a/app/soc/views/models/document.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/document.py Fri Apr 03 17:41:08 2009 +0000
@@ -115,8 +115,8 @@
super(View, self).__init__(params=params)
- def list(self, request, access_type, page_name=None,
- params=None, filter=None, **kwargs):
+ def list(self, request, access_type,
+ page_name=None, params=None, filter=None, order=None, **kwargs):
"""See base.View.list.
"""
--- a/app/soc/views/models/group.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/group.py Fri Apr 03 17:41:08 2009 +0000
@@ -95,11 +95,13 @@
'clean_contact_street': cleaning.clean_ascii_only('contact_street'),
'clean_contact_city': cleaning.clean_ascii_only('contact_city'),
'clean_contact_state': cleaning.clean_ascii_only('contact_state'),
- 'clean_contact_postalcode': cleaning.clean_ascii_only('contact_postalcode'),
+ 'clean_contact_postalcode': cleaning.clean_ascii_only(
+ 'contact_postalcode'),
'clean_shipping_street': cleaning.clean_ascii_only('shipping_street'),
'clean_shipping_city': cleaning.clean_ascii_only('shipping_city'),
'clean_shipping_state': cleaning.clean_ascii_only('shipping_state'),
- 'clean_shipping_postalcode': cleaning.clean_ascii_only('shipping_postalcode'),
+ 'clean_shipping_postalcode': cleaning.clean_ascii_only(
+ 'shipping_postalcode'),
}
--- a/app/soc/views/models/group_app.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/group_app.py Fri Apr 03 17:41:08 2009 +0000
@@ -136,7 +136,7 @@
@decorators.merge_params
@decorators.check_access
def list(self, request, access_type,
- page_name=None, params=None, filter={}, **kwargs):
+ page_name=None, params=None, filter=None, order=None, **kwargs):
"""Lists all notifications in separate tables, depending on their status.
for parameters see base.list()
@@ -203,7 +203,7 @@
@decorators.merge_params
@decorators.check_access
def listSelf(self, request, access_type,
- page_name=None, params=None, **kwargs):
+ page_name=None, params=None, **kwargs):
"""List all applications from the current logged-in user.
For params see base.View.public().
--- a/app/soc/views/models/mentor.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/mentor.py Fri Apr 03 17:41:08 2009 +0000
@@ -225,7 +225,7 @@
list = decorators.view(view.list)
manage = decorators.view(view.manage)
process_request = decorators.view(view.processRequest)
-request = decorators.view(view.request)
+role_request = decorators.view(view.request)
public = decorators.view(view.public)
export = decorators.view(view.export)
--- a/app/soc/views/models/notification.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/notification.py Fri Apr 03 17:41:08 2009 +0000
@@ -29,10 +29,8 @@
from soc.logic import cleaning
from soc.logic import dicts
-from soc.logic import validate
from soc.models import notification as notification_model
from soc.views import helper
-from soc.views import out_of_band
from soc.views.helper import access
from soc.views.helper import decorators
from soc.views.helper import lists as list_helper
@@ -109,7 +107,7 @@
@decorators.merge_params
@decorators.check_access
def list(self, request, access_type,
- page_name=None, params=None, filter=None):
+ page_name=None, params=None, filter=None, order=None, **kwargs):
"""Lists all notifications that the current logged in user has stored.
for parameters see base.list()
@@ -163,7 +161,7 @@
# get the current user
current_user = user_logic.getForCurrentAccount()
- fields['link_id'] = 't%i' %(int(time.time()*100))
+ fields['link_id'] = 't%i' % (int(time.time()*100))
fields['scope'] = fields['to_user']
fields['from_user'] = current_user
fields['scope_path'] = fields['to_user'].link_id
--- a/app/soc/views/models/org_app.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/org_app.py Fri Apr 03 17:41:08 2009 +0000
@@ -133,7 +133,8 @@
initial=False, required=True),
'clean_description': cleaning.clean_html_content('description'),
- 'clean_contrib_template': cleaning.clean_html_content('contrib_template'),
+ 'clean_contrib_template': cleaning.clean_html_content(
+ 'contrib_template'),
'clean_ideas': cleaning.clean_url('ideas'),
'clean': cleaning.validate_new_group('link_id', 'scope_path',
model_logic.organization, org_app_logic)}
@@ -151,7 +152,8 @@
new_params['review_template'] = 'soc/org_app/review.html'
# TODO use a proper template that works for each program
- new_params['accepted_mail_template'] = 'soc/org_app/mail/accepted_gsoc2009.html'
+ new_params['accepted_mail_template'] = \
+ 'soc/org_app/mail/accepted_gsoc2009.html'
new_params['rejected_mail_template'] = 'soc/org_app/mail/rejected.html'
params = dicts.merge(params, new_params)
@@ -234,7 +236,7 @@
# use the accepted template and subject
template = params['accepted_mail_template']
context['subject'] = 'Congratulations!'
- context['HTTP_host'] = 'http://%s' %(os.environ['HTTP_HOST'])
+ context['HTTP_host'] = 'http://%s' % (os.environ['HTTP_HOST'])
elif status == 'rejected':
# use the rejected template and subject
template = params['rejected_mail_template']
--- a/app/soc/views/models/organization.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/organization.py Fri Apr 03 17:41:08 2009 +0000
@@ -36,7 +36,6 @@
from soc.logic.models import organization as org_logic
from soc.logic.models import org_admin as org_admin_logic
from soc.logic.models import org_app as org_app_logic
-from soc.logic.models import program as program_logic
from soc.logic.models import user as user_logic
from soc.views import helper
from soc.views import out_of_band
@@ -47,7 +46,6 @@
from soc.views.helper import redirects
from soc.views.helper import widgets
from soc.views.models import group
-from soc.views.models import program as program_view
import soc.models.organization
import soc.logic.models.organization
@@ -63,7 +61,9 @@
Params:
original_params: a dict with params for this View
"""
-
+
+ from soc.views.models import program as program_view
+
rights = access.Checker(params)
rights['any_access'] = ['allow']
rights['show'] = ['allow']
@@ -138,7 +138,8 @@
widget=helper.widgets.FullTinyMCE(
attrs={'rows': 25, 'cols': 100})),
'clean_description': cleaning.clean_html_content('description'),
- 'clean_contrib_template': cleaning.clean_html_content('contrib_template'),
+ 'clean_contrib_template': cleaning.clean_html_content(
+ 'contrib_template'),
'clean_ideas': cleaning.clean_url('ideas'),
'clean': cleaning.validate_new_group('link_id', 'scope_path',
soc.logic.models.organization, org_app_logic)
@@ -257,10 +258,11 @@
assigned_proposals = []
- # only when the program allows allocations to be seen we should color the list
+ # only when the program allows allocations
+ # to be seen we should color the list
if org_entity.scope.allocations_visible:
# get the limit and offset for the list
- limit, offset = lists.getLimitAndOffset(request, 'offset_0', 'limit_0')
+ _, offset = lists.getLimitAndOffset(request, 'offset_0', 'limit_0')
# determine the amount of proposals to color
to_color = max(0, org_entity.slots - offset)
--- a/app/soc/views/models/presence.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/presence.py Fri Apr 03 17:41:08 2009 +0000
@@ -24,18 +24,15 @@
from google.appengine.ext import db
-from django import forms
from django.utils.translation import ugettext
from soc.cache import home
from soc.logic import cleaning
from soc.logic import dicts
-from soc.logic import validate
from soc.logic.models import document as document_logic
from soc.views import helper
from soc.views.helper import access
from soc.views.helper import decorators
-from soc.views.helper import redirects
from soc.views.helper import widgets
from soc.views.models import base
@@ -143,7 +140,8 @@
if entity.home:
form.fields['home_link_id'].initial = entity.home.link_id
except db.Error:
- pass
+ # TODO(Pawel.Solyga): use logging to log exception
+ return
super(View, self)._editGet(request, entity, form)
--- a/app/soc/views/models/presence_with_tos.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/presence_with_tos.py Fri Apr 03 17:41:08 2009 +0000
@@ -24,12 +24,10 @@
from google.appengine.ext import db
-from django import forms
from django.utils.translation import ugettext
from soc.logic import cleaning
from soc.logic import dicts
-from soc.logic.models import document as document_logic
from soc.views.models import presence
from soc.views.helper import widgets
--- a/app/soc/views/models/program.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/program.py Fri Apr 03 17:41:08 2009 +0000
@@ -27,7 +27,6 @@
from django import forms
from django import http
-from django.utils import simplejson
from django.utils.translation import ugettext
from soc.logic import allocations
@@ -42,7 +41,6 @@
from soc.logic.models import student_proposal as student_proposal_logic
from soc.logic.models import program as program_logic
from soc.logic.models import student as student_logic
-from soc.logic.models.document import logic as document_logic
from soc.views import helper
from soc.views import out_of_band
from soc.views.helper import access
@@ -265,9 +263,11 @@
page_name: the page name displayed in templates as page and header title
params: a dict with params for this View, not used
"""
+
+ from django.utils import simplejson
program = program_logic.logic.getFromKeyFieldsOr404(kwargs)
- slots = program.slots
+ program_slots = program.slots
filter = {
'scope': program,
@@ -308,7 +308,7 @@
iterative = False
allocator = allocations.Allocator(orgs.keys(), applications, mentors,
- slots, max_slots_per_org,
+ program_slots, max_slots_per_org,
min_slots_per_org, iterative)
result = allocator.allocate(locked_slots, adjusted_slots)
@@ -369,7 +369,8 @@
@decorators.check_access
def showDuplicates(self, request, access_type, page_name=None,
params=None, **kwargs):
- """View in which a host can see which students have been assigned multiple slots.
+ """View in which a host can see which students have been assigned
+ multiple slots.
For params see base.view.Public().
"""
@@ -462,7 +463,8 @@
'slots >': 0,
'status': 'active'}
- org_entities = org_logic.logic.getForFields(fields, limit=limit, offset=offset)
+ org_entities = org_logic.logic.getForFields(fields,
+ limit=limit, offset=offset)
orgs_data = {}
proposals_data = []
@@ -644,7 +646,8 @@
(redirects.getApplyRedirect(program_entity, {'url_name': 'org_app'}),
"Apply to become an Organization", 'any_access')]
- if user and timeline_helper.isAfterEvent(timeline_entity, 'org_signup_start'):
+ if user and timeline_helper.isAfterEvent(timeline_entity,
+ 'org_signup_start'):
filter = {
'applicant': user,
'scope': program_entity,
--- a/app/soc/views/models/role.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/role.py Fri Apr 03 17:41:08 2009 +0000
@@ -31,7 +31,6 @@
from soc.logic import dicts
from soc.logic.models import request as request_logic
from soc.logic.models import user as user_logic
-from soc.logic.helper import notifications as notifications_helper
from soc.logic.helper import request as request_helper
from soc.views.helper import decorators
from soc.views.helper import redirects
@@ -107,7 +106,7 @@
'soc.views.models.%(module_name)s.process_request',
'Process request for %(name)s'),
(r'^%(url_name)s/(?P<access_type>request)/%(scope)s$',
- 'soc.views.models.%(module_name)s.request',
+ 'soc.views.models.%(module_name)s.role_request',
'Create a Request to become %(name)s')]
elif params.get('allow_invites'):
# add patterns concerning only invites
@@ -265,8 +264,7 @@
key_name = request_logic.logic.getKeyNameFromFields(request_fields)
# create the request entity
- entity = request_logic.logic.updateOrCreateFromKeyName(request_fields,
- key_name)
+ request_logic.logic.updateOrCreateFromKeyName(request_fields, key_name)
group_view = params.get('group_view')
if not group_view:
--- a/app/soc/views/models/student.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/student.py Fri Apr 03 17:41:08 2009 +0000
@@ -179,7 +179,7 @@
"""See base.View._editContext().
"""
- entity = context['entity']
+ # entity = context['entity']
form = context['form']
if 'scope_path' in form.initial:
--- a/app/soc/views/models/student_project.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/student_project.py Fri Apr 03 17:41:08 2009 +0000
@@ -33,7 +33,6 @@
from soc.views.helper import access
from soc.views.helper import decorators
from soc.views.helper import redirects
-from soc.views.helper import responses
from soc.views.helper import widgets
from soc.views.models import base
from soc.views.models import organization as org_view
@@ -55,7 +54,9 @@
rights = access.Checker(params)
rights['create'] = ['checkIsDeveloper']
- rights['edit'] = ['checkIsDeveloper'] # TODO who should be able to edit this?
+ # TODO who should be able to edit this?
+ rights['edit'] = ['checkIsDeveloper']
+
rights['delete'] = ['checkIsDeveloper']
rights['show'] = ['allow']
rights['list'] = ['checkIsDeveloper']
@@ -119,7 +120,7 @@
"""
if not entity:
- fields['link_id'] = 't%i' %(int(time.time()*100))
+ fields['link_id'] = 't%i' % (int(time.time()*100))
else:
fields['link_id'] = entity.link_id
--- a/app/soc/views/models/student_proposal.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/student_proposal.py Fri Apr 03 17:41:08 2009 +0000
@@ -234,7 +234,8 @@
'label': 'Set to rank',
'help_text':
'Set this proposal to the given rank (ignores the given score)',
- 'example_text': 'A rank will only be assigned if the review is private!',
+ 'example_text': 'A rank will only be assigned if the '
+ 'review is private!',
'min_value': 1,
'required': False,
'passthrough': ['min_value', 'required', 'help_text'],
@@ -271,7 +272,7 @@
"""
if not entity:
- fields['link_id'] = 't%i' %(int(time.time()*100))
+ fields['link_id'] = 't%i' % (int(time.time()*100))
else:
fields['link_id'] = entity.link_id
@@ -362,7 +363,8 @@
# no org_admin found, maybe it's a mentor?
reviewer = mentor_logic.logic.getForFields(fields, unique=True)
- # create the review (reviewer might be None if a Host or Developer is posting)
+ # create the review (reviewer might be None
+ # if a Host or Developer is posting)
self._createReviewFor(entity, reviewer, comment, is_public=True)
# redirect to the same page
@@ -532,7 +534,7 @@
student_entity = student_logic.logic.getFromKeyName(kwargs['scope_path'])
- filter = {'scope' : student_entity.scope,
+ filter = {'scope': student_entity.scope,
'status': 'active'}
list_params = org_view.view.getParams().copy()
@@ -585,8 +587,8 @@
# get the context for this webpage
context = responses.getUniversalContext(request)
responses.useJavaScript(context, params['js_uses_all'])
- context['page_name'] = '%s "%s" from %s' %(page_name, entity.title,
- entity.scope.name())
+ context['page_name'] = '%s "%s" from %s' % (page_name, entity.title,
+ entity.scope.name())
context['entity'] = entity
context['entity_type'] = params['name']
context['entity_type_url'] = params['url_name']
@@ -650,7 +652,8 @@
rank = fields['rank']
if rank:
ranker = self._logic.getRankerFor(entity)
- # if a very high rank is filled in use the highest one that returns a score
+ # if a very high rank is filled in use the highest
+ # one that returns a score
rank = min(ranker.TotalRankedScores(), rank)
# ranker uses zero-based ranking
score_and_rank = ranker.FindScore(rank-1)
@@ -768,19 +771,23 @@
comment_private = ['score']
comment_admin = ['rank', 'mentor']
class FilterForm(object):
+ """Helper class used for form filtering.
+ """
def __init__(self, form, fields):
self.__form = form
self.__fields = fields
@property
def fields(self):
- return dict([(k,i) for k, i in self.__form.fields.iteritems() if k in self.__fields])
+ """Property that returns all fields as dictionary."""
+ fields = self.__form.fields.iteritems()
+ return dict([(k, i) for k, i in fields if k in self.__fields])
def __iter__(self):
- for x in self.__form:
- if x.name not in self.__fields:
+ for field in self.__form:
+ if field.name not in self.__fields:
continue
- yield x
+ yield field
_marker = []
def __getattr__(self, key, default=_marker):
@@ -933,8 +940,10 @@
properties = {'mentor': mentor_entity}
self._logic.updateEntityProperties(entity, properties)
- def _createReviewFor(self, entity, reviewer, comment, score=0, is_public=True):
- """Creates a review for the given proposal and sends out a message to all followers.
+ def _createReviewFor(self, entity, reviewer, comment,
+ score=0, is_public=True):
+ """Creates a review for the given proposal and sends
+ out a message to all followers.
Args:
entity: Student Proposal entity for which the review should be created
@@ -944,14 +953,12 @@
is_public: Determines if the review is a public review
"""
- import time
-
from soc.logic.helper import notifications as notifications_helper
from soc.logic.models.review import logic as review_logic
from soc.logic.models.review_follower import logic as review_follower_logic
# create the fields for the review entity
- fields = {'link_id': 't%i' %(int(time.time()*100)),
+ fields = {'link_id': 't%i' % (int(time.time()*100)),
'scope': entity,
'scope_path': entity.key().name(),
'author': user_logic.logic.getForCurrentAccount(),
--- a/app/soc/views/models/user.py Fri Apr 03 17:34:20 2009 +0000
+++ b/app/soc/views/models/user.py Fri Apr 03 17:41:08 2009 +0000
@@ -24,15 +24,12 @@
]
-from google.appengine.api import users
-
from django import forms
from soc.logic import cleaning
from soc.logic import dicts
from soc.logic.models.site import logic as site_logic
from soc.logic.models.user import logic as user_logic
-from soc.views import helper
from soc.views.helper import access
from soc.views.helper import decorators
from soc.views.helper import redirects