app/soc/views/site/docs/edit.py
changeset 272 00cea07656c0
parent 271 01e90bb21b7e
child 274 56e1c1721299
equal deleted inserted replaced
271:01e90bb21b7e 272:00cea07656c0
    32 from soc.logic import out_of_band
    32 from soc.logic import out_of_band
    33 from soc.logic import path_linkname
    33 from soc.logic import path_linkname
    34 from soc.logic.site import id_user
    34 from soc.logic.site import id_user
    35 from soc.views import helper
    35 from soc.views import helper
    36 import soc.views.helper.requests
    36 import soc.views.helper.requests
       
    37 import soc.views.helper.responses
    37 import soc.views.helper.widgets
    38 import soc.views.helper.widgets
    38 from soc.views import simple
    39 from soc.views import simple
    39 from soc.views.helpers import forms_helpers
    40 from soc.views.helpers import forms_helpers
    40 from soc.views.helpers import response_helpers
       
    41 from soc.views.user import profile
    41 from soc.views.user import profile
    42 
    42 
    43 import soc.models.document
    43 import soc.models.document
    44 
    44 
    45 
    45 
    87   Returns:
    87   Returns:
    88     A subclass of django.http.HttpResponse which either contains the form to
    88     A subclass of django.http.HttpResponse which either contains the form to
    89     be filled out, or a redirect to the correct view in the interface.
    89     be filled out, or a redirect to the correct view in the interface.
    90   """
    90   """
    91   # create default template context for use with any templates
    91   # create default template context for use with any templates
    92   context = response_helpers.getUniversalContext(request)
    92   context = helper.responses.getUniversalContext(request)
    93 
    93 
    94   logged_in_id = users.get_current_user()
    94   logged_in_id = users.get_current_user()
    95   
    95   
    96   alt_response = simple.getAltResponseIfNotDeveloper(request, context, 
    96   alt_response = simple.getAltResponseIfNotDeveloper(request, context, 
    97                                                      id=logged_in_id)
    97                                                      id=logged_in_id)
   151 
   151 
   152       new_path = path_linkname.combinePath([new_partial_path, new_linkname])
   152       new_path = path_linkname.combinePath([new_partial_path, new_linkname])
   153         
   153         
   154       # redirect to new /site/docs/edit/new_path?s=0
   154       # redirect to new /site/docs/edit/new_path?s=0
   155       # (causes 'Profile saved' message to be displayed)
   155       # (causes 'Profile saved' message to be displayed)
   156       return response_helpers.redirectToChangedSuffix(
   156       return helper.responses.redirectToChangedSuffix(
   157           request, path, new_path,
   157           request, path, new_path,
   158           params=profile.SUBMIT_PROFILE_SAVED_PARAMS)
   158           params=profile.SUBMIT_PROFILE_SAVED_PARAMS)
   159   else: # method == 'GET':
   159   else: # method == 'GET':
   160     # try to fetch Document entity corresponding to path if one exists
   160     # try to fetch Document entity corresponding to path if one exists
   161     if path:
   161     if path:
   197       form = EditForm()
   197       form = EditForm()
   198 
   198 
   199   context.update({'form': form,
   199   context.update({'form': form,
   200                   'existing_doc': doc})
   200                   'existing_doc': doc})
   201 
   201 
   202   return response_helpers.respond(request, template, context)
   202   return helper.responses.respond(request, template, context)
   203 
   203 
   204 
   204 
   205 class CreateForm(forms_helpers.DbModelForm):
   205 class CreateForm(forms_helpers.DbModelForm):
   206   """Django form displayed when Developer creates a Document.
   206   """Django form displayed when Developer creates a Document.
   207   """
   207   """
   238   Returns:
   238   Returns:
   239     A subclass of django.http.HttpResponse which either contains the form to
   239     A subclass of django.http.HttpResponse which either contains the form to
   240     be filled out, or a redirect to the correct view in the interface.
   240     be filled out, or a redirect to the correct view in the interface.
   241   """
   241   """
   242   # create default template context for use with any templates
   242   # create default template context for use with any templates
   243   context = response_helpers.getUniversalContext(request)
   243   context = helper.responses.getUniversalContext(request)
   244 
   244 
   245   alt_response = simple.getAltResponseIfNotDeveloper(request,
   245   alt_response = simple.getAltResponseIfNotDeveloper(request,
   246                                                      context=context)
   246                                                      context=context)
   247   if alt_response:
   247   if alt_response:
   248     return alt_response
   248     return alt_response
   269 
   269 
   270       new_path = path_linkname.combinePath([new_partial_path, new_linkname])
   270       new_path = path_linkname.combinePath([new_partial_path, new_linkname])
   271         
   271         
   272       # redirect to new /site/docs/edit/new_path?s=0
   272       # redirect to new /site/docs/edit/new_path?s=0
   273       # (causes 'Profile saved' message to be displayed)
   273       # (causes 'Profile saved' message to be displayed)
   274       return response_helpers.redirectToChangedSuffix(
   274       return helper.responses.redirectToChangedSuffix(
   275           request, None, new_path,
   275           request, None, new_path,
   276           params=profile.SUBMIT_PROFILE_SAVED_PARAMS)
   276           params=profile.SUBMIT_PROFILE_SAVED_PARAMS)
   277   else: # method == 'GET':
   277   else: # method == 'GET':
   278     # no link name specified, so start with an empty form
   278     # no link name specified, so start with an empty form
   279     form = CreateForm()
   279     form = CreateForm()
   280 
   280 
   281   context.update({'form': form})
   281   context.update({'form': form})
   282 
   282 
   283   return response_helpers.respond(request, template, context)
   283   return helper.responses.respond(request, template, context)