app/soc/views/site/docs/edit.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 12 Oct 2008 15:52:19 +0000
changeset 305 972d28056d9d
parent 303 4f1bb54ddae5
child 309 7190b224c701
permissions -rw-r--r--
Minor style and import fixes Incorperated changes as suggested by Todd and Pawel. Patch by: Sverre Rabbelier Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Developer views for editing and examining Documents.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Todd Larsen" <tlarsen@google.com>',
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
  ]
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
from google.appengine.api import users
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
from django import http
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
from django import newforms as forms
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
from django.utils.translation import ugettext_lazy
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    31
import soc.logic
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
from soc.logic import out_of_band
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 294
diff changeset
    33
from soc.logic import path_link_name
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
from soc.logic.site import id_user
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
    35
import soc.models.document
269
0f1acc4c3e1e Move helpers/request.py to helper/requests.py to avoid conflict with common
Todd Larsen <tlarsen@google.com>
parents: 267
diff changeset
    36
from soc.views import helper
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
    37
from soc.views.helper import access
274
56e1c1721299 Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents: 272
diff changeset
    38
import soc.views.helper.forms
269
0f1acc4c3e1e Move helpers/request.py to helper/requests.py to avoid conflict with common
Todd Larsen <tlarsen@google.com>
parents: 267
diff changeset
    39
import soc.views.helper.requests
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 271
diff changeset
    40
import soc.views.helper.responses
271
01e90bb21b7e Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents: 269
diff changeset
    41
import soc.views.helper.widgets
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
from soc.views import simple
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
from soc.views.user import profile
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
    44
import soc.views.out_of_band
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
274
56e1c1721299 Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents: 272
diff changeset
    47
class EditForm(helper.forms.DbModelForm):
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
  """Django form displayed when Developer edits a Document.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
  """
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
  doc_key_name = forms.CharField(widget=forms.HiddenInput)
271
01e90bb21b7e Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents: 269
diff changeset
    51
  content = forms.fields.CharField(widget=helper.widgets.TinyMCE())
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
  
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
  class Meta:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
    model = soc.models.document.Document
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
    
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
    #: list of model fields which will *not* be gathered by the form
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
    exclude = ['inheritance_line', 'user', 'created', 'modified']
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
 
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
  def clean_partial_path(self):
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
    partial_path = self.cleaned_data.get('partial_path')
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
    # TODO(tlarsen): combine path and link_name and check for uniqueness
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
    return partial_path
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
  def clean_link_name(self):
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
    link_name = self.cleaned_data.get('link_name')
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
    # TODO(tlarsen): combine path and link_name and check for uniqueness
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    67
    return link_name
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    68
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    69
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    70
DEF_SITE_DOCS_EDIT_TMPL = 'soc/site/docs/edit.html'
247
4997b54b0400 Fixed typo in DEF_CREATE_NEW_DOC_MSG.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 237
diff changeset
    71
DEF_CREATE_NEW_DOC_MSG = ' You can create a new document by visiting the' \
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    72
                         ' <a href="/site/docs/edit">Create ' \
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    73
                         'a New Document</a> page.'
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    74
290
2a92b866ed40 Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 285
diff changeset
    75
SUBMIT_MESSAGES = (
2a92b866ed40 Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 285
diff changeset
    76
 ugettext_lazy('Document saved.'),
2a92b866ed40 Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 285
diff changeset
    77
)
2a92b866ed40 Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 285
diff changeset
    78
305
972d28056d9d Minor style and import fixes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 303
diff changeset
    79
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    80
def getDocForForm(form):
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    81
  """Extracts doc fields from a form and creates a new doc from it
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    82
  """
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    83
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    84
  user = users.get_current_user()
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    85
  if user:
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    86
    email = user.email()
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    87
  else:
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    88
    email = None
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    89
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    90
  partial_path = form.cleaned_data.get('partial_path')
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    91
  link_name = form.cleaned_data.get('link_name')
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    92
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    93
  properties = {}
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    94
  properties['partial_path'] = partial_path
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    95
  properties['link_name'] = link_name
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    96
  properties['title'] = form.cleaned_data.get('title')
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    97
  properties['short_name'] = form.cleaned_data.get('short_name')
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    98
  properties['abstract'] = form.cleaned_data.get('abstract')
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    99
  properties['content'] = form.cleaned_data.get('content')
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   100
  properties['user'] = soc.logic.user_logic.getFromFields(email=email)
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   101
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   102
  doc = soc.logic.document_logic.updateOrCreateFromFields(properties,
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   103
            partial_path=partial_path, link_name=link_name)
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   104
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   105
  return doc
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   106
305
972d28056d9d Minor style and import fixes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 303
diff changeset
   107
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   108
def edit(request, partial_path=None, link_name=None,
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   109
         template=DEF_SITE_DOCS_EDIT_TMPL):
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   110
  """View for a Developer to modify the properties of a Document Model entity.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   111
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   112
  Args:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   113
    request: the standard django request object
251
8f23804302d0 Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents: 247
diff changeset
   114
    partial_path: the Document's site-unique "path" extracted from the URL,
8f23804302d0 Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents: 247
diff changeset
   115
      minus the trailing link_name
8f23804302d0 Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents: 247
diff changeset
   116
    link_name: the last portion of the Document's site-unique "path"
8f23804302d0 Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents: 247
diff changeset
   117
      extracted from the URL
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   118
    template: the "sibling" template (or a search list of such templates)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   119
      from which to construct the public.html template name (or names)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   120
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   121
  Returns:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   122
    A subclass of django.http.HttpResponse which either contains the form to
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   123
    be filled out, or a redirect to the correct view in the interface.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   124
  """
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   125
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   126
  try:
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   127
    access.checkIsDeveloper(request)
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
   128
  except  soc.views.out_of_band.AccessViolationResponse, alt_response:
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   129
    return alt_response.response()
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   130
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   131
# create default template context for use with any templates
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 271
diff changeset
   132
  context = helper.responses.getUniversalContext(request)
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   133
  logged_in_id = users.get_current_user()
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   134
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   135
  doc = None  # assume that no Document entity will be found
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   136
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 294
diff changeset
   137
  path = path_link_name.combinePath([partial_path, link_name])
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   138
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   139
  # try to fetch Document entity corresponding to path if one exists    
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   140
  try:
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   141
    if path:
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   142
      doc = soc.logic.document_logic.getFromFields(partial_path=partial_path,
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   143
                                                   link_name=link_name)
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   144
  except out_of_band.ErrorResponse, error:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   145
    # show custom 404 page when path doesn't exist in Datastore
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   146
    error.message = error.message + DEF_CREATE_NEW_DOC_MSG
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   147
    return simple.errorResponse(request, error, template, context)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   148
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   149
  if request.method == 'POST':
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   150
    form = EditForm(request.POST)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   151
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   152
    if form.is_valid():
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   153
      doc = getDocForForm(form)
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   154
      
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   155
      if not doc:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   156
        return http.HttpResponseRedirect('/')
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   157
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   158
      new_path = path_link_name.combinePath([doc.partial_path, doc.link_name])
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   159
        
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   160
      # redirect to new /site/docs/edit/new_path?s=0
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   161
      # (causes 'Profile saved' message to be displayed)
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 271
diff changeset
   162
      return helper.responses.redirectToChangedSuffix(
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   163
          request, path, new_path,
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   164
          params=profile.SUBMIT_PROFILE_SAVED_PARAMS)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   165
  else: # method == 'GET':
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   166
    # try to fetch Document entity corresponding to path if one exists
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   167
    if path:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   168
      if doc:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   169
        # is 'Profile saved' parameter present, but referrer was not ourself?
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   170
        # (e.g. someone bookmarked the GET that followed the POST submit) 
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   171
        if (request.GET.get(profile.SUBMIT_MSG_PARAM_NAME)
269
0f1acc4c3e1e Move helpers/request.py to helper/requests.py to avoid conflict with common
Todd Larsen <tlarsen@google.com>
parents: 267
diff changeset
   172
            and (not helper.requests.isReferrerSelf(request, suffix=path))):
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   173
          # redirect to aggressively remove 'Profile saved' query parameter
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   174
          return http.HttpResponseRedirect(request.path)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   175
    
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   176
        # referrer was us, so select which submit message to display
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   177
        # (may display no message if ?s=0 parameter is not present)
290
2a92b866ed40 Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 285
diff changeset
   178
        context['notice'] = (
269
0f1acc4c3e1e Move helpers/request.py to helper/requests.py to avoid conflict with common
Todd Larsen <tlarsen@google.com>
parents: 267
diff changeset
   179
            helper.requests.getSingleIndexedParamValue(
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   180
                request, profile.SUBMIT_MSG_PARAM_NAME,
290
2a92b866ed40 Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 285
diff changeset
   181
                values=SUBMIT_MESSAGES))
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   182
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   183
        # populate form with the existing User entity
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   184
        form = EditForm(initial={'doc_key_name': doc.key().name(),
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   185
            'title': doc.title, 'partial_path': doc.partial_path,
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   186
            'link_name': doc.link_name, 'short_name': doc.short_name,
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   187
            'abstract': doc.abstract, 'content': doc.content,
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   188
            'user': doc.user})       
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   189
      else:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   190
        if request.GET.get(profile.SUBMIT_MSG_PARAM_NAME):
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   191
          # redirect to aggressively remove 'Profile saved' query parameter
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   192
          return http.HttpResponseRedirect(request.path)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   193
          
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   194
        context['lookup_error'] = ugettext_lazy(
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   195
            'Document with that path not found.')
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 294
diff changeset
   196
        form = EditForm(initial={'link_name': link_name})
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   197
    else:  # no link name specified in the URL
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   198
      if request.GET.get(profile.SUBMIT_MSG_PARAM_NAME):
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   199
        # redirect to aggressively remove 'Profile saved' query parameter
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   200
        return http.HttpResponseRedirect(request.path)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   201
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   202
      # no link name specified, so start with an empty form
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   203
      form = EditForm()
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   204
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   205
  context.update({'form': form,
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   206
                  'existing_doc': doc})
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   207
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 271
diff changeset
   208
  return helper.responses.respond(request, template, context)
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   209
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   210
274
56e1c1721299 Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents: 272
diff changeset
   211
class CreateForm(helper.forms.DbModelForm):
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   212
  """Django form displayed when Developer creates a Document.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   213
  """
271
01e90bb21b7e Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents: 269
diff changeset
   214
  content = forms.fields.CharField(widget=helper.widgets.TinyMCE())
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   215
  
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   216
  class Meta:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   217
    model = soc.models.document.Document
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   218
    
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   219
    #: list of model fields which will *not* be gathered by the form
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   220
    exclude = ['inheritance_line', 'user', 'created', 'modified']
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   221
 
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   222
  def clean_partial_path(self):
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   223
    partial_path = self.cleaned_data.get('partial_path')
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   224
    # TODO(tlarsen): combine path and link_name and check for uniqueness
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   225
    return partial_path
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   226
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   227
  def clean_link_name(self):
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   228
    link_name = self.cleaned_data.get('link_name')
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   229
    # TODO(tlarsen): combine path and link_name and check for uniqueness
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   230
    return link_name
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   231
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   232
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   233
DEF_SITE_DOCS_CREATE_TMPL = 'soc/site/docs/edit.html'
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   234
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   235
def create(request, template=DEF_SITE_DOCS_CREATE_TMPL):
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   236
  """View for a Developer to create a new Document entity.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   238
  Args:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   239
    request: the standard django request object
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   240
    template: the "sibling" template (or a search list of such templates)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   241
      from which to construct the public.html template name (or names)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   242
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   243
  Returns:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   244
    A subclass of django.http.HttpResponse which either contains the form to
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   245
    be filled out, or a redirect to the correct view in the interface.
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   246
  """
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   247
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   248
  try:
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   249
    access.checkIsDeveloper(request)
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
   250
  except  soc.views.out_of_band.AccessViolationResponse, alt_response:
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   251
    return alt_response.response()
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 290
diff changeset
   252
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   253
  # create default template context for use with any templates
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 271
diff changeset
   254
  context = helper.responses.getUniversalContext(request)
290
2a92b866ed40 Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 285
diff changeset
   255
  logged_in_id = users.get_current_user()
2a92b866ed40 Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 285
diff changeset
   256
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   257
  if request.method == 'POST':
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   258
    form = CreateForm(request.POST)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   259
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   260
    if form.is_valid():
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   261
      doc = getDocForForm(form)
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   262
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   263
      if not doc:
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   264
        return http.HttpResponseRedirect('/')
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   265
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 294
diff changeset
   266
      new_path = path_link_name.combinePath([doc.partial_path, doc.link_name])
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   267
        
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   268
      # redirect to new /site/docs/edit/new_path?s=0
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   269
      # (causes 'Profile saved' message to be displayed)
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 271
diff changeset
   270
      return helper.responses.redirectToChangedSuffix(
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   271
          request, None, new_path,
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   272
          params=profile.SUBMIT_PROFILE_SAVED_PARAMS)
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   273
  else: # method == 'GET':
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   274
    # no link name specified, so start with an empty form
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   275
    form = CreateForm()
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   276
285
52e206a6a417 Style fix, as requested by Todd to dict usage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 274
diff changeset
   277
  context['form'] = form
237
d360162714b6 Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   278
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 271
diff changeset
   279
  return helper.responses.respond(request, template, context)