Construct names automatically from base name.
authorSverre Rabbelier <srabbelier@gmail.com>
Sat, 10 Jan 2009 18:17:16 +0000
changeset 799 30a912906a57
parent 798 bd655740c03f
child 800 738f6335b0e2
Construct names automatically from base name. Saves a lot of typing for the common case Patch by: Sverre Rabbelier
app/soc/views/helper/params.py
app/soc/views/models/club.py
app/soc/views/models/club_app.py
app/soc/views/models/document.py
app/soc/views/models/group_app.py
app/soc/views/models/host.py
app/soc/views/models/notification.py
app/soc/views/models/organization.py
app/soc/views/models/presence.py
app/soc/views/models/program.py
app/soc/views/models/request.py
app/soc/views/models/site.py
app/soc/views/models/sponsor.py
app/soc/views/models/timeline.py
app/soc/views/models/user.py
app/soc/views/models/user_self.py
--- a/app/soc/views/helper/params.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/helper/params.py	Sat Jan 10 18:17:16 2009 +0000
@@ -86,6 +86,18 @@
   new_params['rights'] = rights
   new_params['scope_logic'] = logic.getScopeLogic()
 
+  if 'name_short' not in params:
+    params['name_short'] = params['name']
+
+  if 'name_plural' not in params:
+    params['name_plural'] = params['name'] + 's'
+
+  if 'module_name' not in params:
+    params['module_name'] = params['name_short'].replace(' ', '_').lower()
+
+  if 'url_name' not in params:
+    params['url_name'] = params['module_name']
+
   # Do not expand edit_redirect to allow it to be overriden without suffix
   new_params['edit_redirect'] = '/%(url_name)s/edit/%(suffix)s'
   new_params['missing_redirect'] = '/%(url_name)s/create' % params
--- a/app/soc/views/models/club.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/club.py	Sat Jan 10 18:17:16 2009 +0000
@@ -51,11 +51,7 @@
     new_params['logic'] = soc.logic.models.club.logic
 
     new_params['name'] = "Club"
-    new_params['name_short'] = "Club"
-    new_params['name_plural'] = "Clubs"
-    new_params['url_name'] = "club"
-    new_params['module_name'] = "club"
-    
+
     new_params['extra_dynaexclude'] = ['founder', 'home']
     new_params['edit_extra_dynafields'] = {
         'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(),
--- a/app/soc/views/models/club_app.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/club_app.py	Sat Jan 10 18:17:16 2009 +0000
@@ -86,10 +86,7 @@
     new_params['extra_django_patterns'] = patterns
     
     new_params['name'] = "Club Application"
-    new_params['name_short'] = "Club Application"
-    new_params['name_plural'] = "Club Applications"
-    new_params['url_name'] = "club_app"
-    new_params['module_name'] = "club_app"
+    new_params['name_short'] = "Club App"
 
     new_params['sidebar_additional'] = [
         ('/%(url_name)s/review' % new_params,
--- a/app/soc/views/models/document.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/document.py	Sat Jan 10 18:17:16 2009 +0000
@@ -105,10 +105,6 @@
     new_params['rights'] = rights
 
     new_params['name'] = "Document"
-    new_params['name_short'] = "Document"
-    new_params['name_plural'] = "Documents"
-    new_params['url_name'] = "document"
-    new_params['module_name'] = "document"
 
     new_params['edit_form'] = EditForm
     new_params['create_form'] = CreateForm
--- a/app/soc/views/models/group_app.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/group_app.py	Sat Jan 10 18:17:16 2009 +0000
@@ -46,11 +46,8 @@
     new_params = {}
     new_params['logic'] = soc.logic.models.group_app.logic
 
-    new_params['name'] = "Group App"
+    new_params['name'] = "Group Application"
     new_params['name_short'] = "Group App"
-    new_params['name_plural'] = "Group Apps"
-    new_params['url_name'] = "group_app"
-    new_params['module_name'] = "group_app"
 
     params = dicts.merge(params, new_params)
 
--- a/app/soc/views/models/host.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/host.py	Sat Jan 10 18:17:16 2009 +0000
@@ -106,9 +106,6 @@
     new_params['invite_filter'] = {'group_ln': 'link_id'}
 
     new_params['name'] = "Program Administrator"
-    new_params['name_short'] = "Program Administrator"
-    new_params['name_plural'] = "Program Administrators"
-    new_params['url_name'] = "host"
     new_params['module_name'] = "host"
 
     new_params['edit_form'] = EditForm
--- a/app/soc/views/models/notification.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/notification.py	Sat Jan 10 18:17:16 2009 +0000
@@ -93,10 +93,6 @@
     new_params['rights'] = rights
 
     new_params['name'] = "Notification"
-    new_params['name_short'] = "Notification"
-    new_params['name_plural'] = "Notifications"
-    new_params['url_name'] = "notification"
-    new_params['module_name'] = "notification"
 
     new_params['no_create_with_key_fields'] = True
     new_params['create_form'] = CreateForm
--- a/app/soc/views/models/organization.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/organization.py	Sat Jan 10 18:17:16 2009 +0000
@@ -53,10 +53,7 @@
     new_params['scope_redirect'] = redirects.getCreateRedirect
 
     new_params['name'] = "Organization"
-    new_params['name_short'] = "Organization"
-    new_params['name_plural'] = "Organizations"
     new_params['url_name'] = "org"
-    new_params['module_name'] = "organization"
 
     new_params['create_extra_dynafields'] = {
         'scope_path': forms.CharField(widget=forms.HiddenInput,
--- a/app/soc/views/models/presence.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/presence.py	Sat Jan 10 18:17:16 2009 +0000
@@ -115,8 +115,6 @@
     new_params['rights'] = rights
 
     new_params['name'] = "Home Settings"
-    new_params['name_short'] = "Home Settings"
-    new_params['name_plural'] = "Home Settings"
     new_params['url_name'] = "home/settings"
     new_params['module_name'] = "presence"
 
--- a/app/soc/views/models/program.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/program.py	Sat Jan 10 18:17:16 2009 +0000
@@ -64,10 +64,6 @@
     new_params['scope_redirect'] = redirects.getCreateRedirect
 
     new_params['name'] = "Program"
-    new_params['name_short'] = "Program"
-    new_params['name_plural'] = "Programs"
-    new_params['url_name'] = "program"
-    new_params['module_name'] = "program"
 
     new_params['edit_template'] = 'soc/program/edit.html'
 
--- a/app/soc/views/models/request.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/request.py	Sat Jan 10 18:17:16 2009 +0000
@@ -110,10 +110,6 @@
     new_params['logic'] = soc.logic.models.request.logic
 
     new_params['name'] = "Request"
-    new_params['name_short'] = "Request"
-    new_params['name_plural'] = "Requests"
-    new_params['url_name'] = "request"
-    new_params['module_name'] = "request"
 
     new_params['edit_form'] = EditForm
     new_params['create_form'] = CreateForm
--- a/app/soc/views/models/site.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/site.py	Sat Jan 10 18:17:16 2009 +0000
@@ -78,11 +78,8 @@
     new_params['logic'] = soc.logic.models.site.logic
     new_params['rights'] = rights
 
-    # TODO(alturin): add ugettext_lazy ?
     new_params['name'] = "Site Settings"
     new_params['name_short'] = "Site"
-    new_params['name_plural'] = "Site Settings"
-    # lower name and replace " " with "/"
     new_params['url_name'] = "site/settings"
     new_params['module_name'] = "site"
 
--- a/app/soc/views/models/sponsor.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/sponsor.py	Sat Jan 10 18:17:16 2009 +0000
@@ -48,12 +48,6 @@
     new_params['logic'] = soc.logic.models.sponsor.logic
 
     new_params['name'] = "Program Owner"
-    new_params['name_short'] = "Program Owner"
-    new_params['name_plural'] = "Program Owners"
-    # TODO(pawel.solyga): create url_name and module_name automatically 
-    # from name. Make that work for all other Views too. Hopefully 
-    # solution that will be implemented in base View.
-    new_params['url_name'] = "sponsor"
     new_params['module_name'] = "sponsor"
 
     params = dicts.merge(params, new_params)
--- a/app/soc/views/models/timeline.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/timeline.py	Sat Jan 10 18:17:16 2009 +0000
@@ -48,10 +48,6 @@
     new_params['logic'] = soc.logic.models.timeline.logic
 
     new_params['name'] = "Timeline"
-    new_params['name_short'] = "Timeline"
-    new_params['name_plural'] = "Timelines"
-    new_params['url_name'] = "timeline"
-    new_params['module_name'] = "timeline"
 
     patterns = [(r'^%(url_name)s/(?P<access_type>edit)/%(key_fields)s$',
                   'soc.views.models.%(module_name)s.edit', "Edit %(name_short)s")]
--- a/app/soc/views/models/user.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/user.py	Sat Jan 10 18:17:16 2009 +0000
@@ -125,10 +125,6 @@
     new_params['logic'] = soc.logic.models.user.logic
 
     new_params['name'] = "User"
-    new_params['name_short'] = "User"
-    new_params['name_plural'] = "Users"
-    new_params['url_name'] = "user"
-    new_params['module_name'] = "user"
 
     new_params['edit_form'] = EditForm
     new_params['create_form'] = CreateForm
--- a/app/soc/views/models/user_self.py	Sat Jan 10 14:49:45 2009 +0000
+++ b/app/soc/views/models/user_self.py	Sat Jan 10 18:17:16 2009 +0000
@@ -107,11 +107,9 @@
     new_params['logic'] = soc.logic.models.user.logic
 
     new_params['name'] = "User"
-    new_params['name_short'] = "User"
-    new_params['name_plural'] = "Users"
+    new_params['module_name'] = "user_self"
     new_params['url_name'] = "user"
-    new_params['module_name'] = "user_self"
-    
+
     new_params['sidebar_heading'] = 'User (self)'
     new_params['sidebar'] = [
         (users.create_login_url("/user/edit"), 'Sign In', 'signIn'),