def new_page(request, parent_id): """Create a new page. Args: request: The request object parent_id: Page that will be the parent of the new page Returns: A Django HttpResponse object. """ if parent_id: parent_page = models.Page.get_by_id(int(parent_id)) else: parent_page = models.Page.get_root() if parent_page: # there is a root, lets force everything to be a child of the root # and set the parent_id parent_id = parent_page.key().id() else: # TODO(gpennington): Figure out a more intuitive method for site # initialization parent_page = utility.set_up_data_store() return utility.edit_updated_page(parent_page.key().id()) if not parent_page.user_can_write(request.profile): return utility.forbidden(request) return edit_page(request, None, parent_id=parent_id)
def delete_file(request, page_id, file_id): """Removes a specified file from the database. Args: request: The request object page_id: ID of the page the file is attached to. file_id: Id of the file. Returns: A Django HttpResponse object. """ record = models.FileStore.get_by_id(int(file_id)) if record: if not record.user_can_write(request.profile): return utility.forbidden(request) record.delete() return utility.edit_updated_page(page_id, tab_name='files') else: return utility.page_not_found(request)
def edit_acl(request): """Edits the contents of an ACL.""" def grant_access(acl, list_to_edit): """Grants access to a page based on data in the POST. Args: acl: AccessControlList to be manipulated list_to_edit: string representing the list on the ACL to add users or groups to """ if request.POST[list_to_edit]: datastore_object = None if request.POST[list_to_edit].startswith('user'): datastore_object = models.UserProfile.load(request.POST[list_to_edit]) else: datastore_object = models.UserGroup.get_by_id( int(request.POST[list_to_edit])) if datastore_object.key() not in acl.__getattribute__(list_to_edit): acl.__getattribute__(list_to_edit).append(datastore_object.key()) def remove_access(acl, list_to_edit): """Removes access to a page based on data in the POST. Args: acl: AccessControlList to be manipulated list_to_edit: string representing the list on the ACL to remove users or groups from """ post_key = '%s_remove_' % list_to_edit removal_keys = [k for k in request.POST.keys() if k.startswith(post_key)] for key in removal_keys: model_type = models.UserGroup if list_to_edit.startswith('user'): model_type = models.UserProfile key_id = int(key.replace(post_key, '')) datastore_object = model_type.get_by_id(key_id) acl.__getattribute__(list_to_edit).remove(datastore_object.key()) page_id = request.POST['page_id'] page = models.Page.get_by_id(int(page_id)) if not page: return utility.page_not_found(request) if not page.user_can_write(request.profile): return utility.forbidden(request) acl = page.acl if page.inherits_acl(): acl = acl.clone() acl.put() page.acl = acl page.put() acl.global_write = 'global_write' in request.POST acl.global_read = 'global_read' in request.POST for object_list in ['group_write', 'group_read', 'user_write', 'user_read']: grant_access(acl, object_list) remove_access(acl, object_list) acl.put() return utility.edit_updated_page(page_id, tab_name='security', message_id='msgChangesSaved')
if not form.errors: try: page = form.save(commit=False) except ValueError, err: form.errors['__all__'] = unicode(err) if form.errors: return utility.respond(request, 'admin/edit_page', {'form': form, 'page': page, 'files': files}) #page.content = request.POST['editorHtml'] page.content = unicode(request.POST['editorHtml'],'utf-8') if parent_id and not page.parent_page: page.parent_page = models.Page.get_by_id(int(parent_id)) page.put() return utility.edit_updated_page(page.key().id(), message_id='msgChangesSaved') def new_page(request, parent_id): """Create a new page. Args: request: The request object parent_id: Page that will be the parent of the new page Returns: A Django HttpResponse object. """ if parent_id: parent_page = models.Page.get_by_id(int(parent_id))
if not form.errors: try: page = form.save(commit=False) except ValueError, err: form.errors['__all__'] = unicode(err) if form.errors: return utility.respond(request, 'admin/edit_page', {'form': form, 'page': page, 'files': files}) page.content = request.POST['editorHtml'] if parent_id and not page.parent_page: page.parent_page = models.Page.get_by_id(int(parent_id)) page.put() return utility.edit_updated_page(page.key().id(), message_id='msgChangesSaved') def new_page(request, parent_id): """Create a new page. Args: request: The request object parent_id: Page that will be the parent of the new page Returns: A Django HttpResponse object. """ if parent_id: parent_page = models.Page.get_by_id(int(parent_id))
form = forms.PageEditForm(data=request.POST, instance=page) if not form.errors: try: page = form.save(commit=False) except ValueError, err: form.errors["__all__"] = unicode(err) if form.errors: return utility.respond(request, "admin/edit_page", {"form": form, "page": page, "files": files}) page.content = request.POST["editorHtml"] if parent_id and not page.parent_page: page.parent_page = models.Page.get_by_id(int(parent_id)) page.put() return utility.edit_updated_page(page.key().id(), message_id="msgChangesSaved") def new_page(request, parent_id): """Create a new page. Args: request: The request object parent_id: Page that will be the parent of the new page Returns: A Django HttpResponse object. """ if parent_id: parent_page = models.Page.get_by_id(int(parent_id))