Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.action.newpage.NewPage Class Reference

List of all members.

Public Member Functions

def __init__
def checkAndCombineArguments
def checkPermissions
def render

Public Attributes

 request
 referrer
 pagename
 nametemplate

Detailed Description

Open editor for a new page, using template 

Definition at line 16 of file newpage.py.


Constructor & Destructor Documentation

def MoinMoin.action.newpage.NewPage.__init__ (   self,
  request,
  referrer 
)

Definition at line 19 of file newpage.py.

00019 
00020     def __init__(self, request, referrer):
00021         self.request = request
00022         self.referrer = referrer # The page the user came from
00023         self.pagename = self.request.values.get('pagename')
00024         self.nametemplate = self.request.values.get('nametemplate', '%s')
00025         self.nametemplate = self.nametemplate.replace('\x00', '')


Member Function Documentation

Check arguments in form, return error msg

@rtype: unicode
@return: error message

Definition at line 26 of file newpage.py.

00026 
00027     def checkAndCombineArguments(self):
00028         """ Check arguments in form, return error msg
00029 
00030         @rtype: unicode
00031         @return: error message
00032         """
00033         _ = self.request.getText
00034         need_replace = '%s' in self.nametemplate
00035         if not self.pagename and need_replace:
00036             return _("Cannot create a new page without a page name."
00037                      "  Please specify a page name.")
00038         if need_replace:
00039         # generate a string that can be safely used as the pagename
00040         # template variable
00041             repl = 'A@'
00042             i = 0
00043             while repl in self.nametemplate:
00044                 repl += ['#', '&', '$', 'x', 'X', ':', '@'][i]
00045                 i += 1
00046                 i = i % 7
00047             template = self.nametemplate.replace('%s', repl)
00048         else:
00049             template = self.nametemplate
00050         template = template.encode('utf-8')
00051         template = time.strftime(template, self.request.user.getTime(time.time()))
00052         template = template.decode('utf-8')
00053         if need_replace:
00054             self.pagename = template.replace(repl, self.pagename)
00055         else:
00056             self.pagename = template
00057         return ''

Here is the caller graph for this function:

Check write permission in form, return error msg

@rtype: unicode
@return: error message

Definition at line 58 of file newpage.py.

00058 
00059     def checkPermissions(self):
00060         """ Check write permission in form, return error msg
00061 
00062         @rtype: unicode
00063         @return: error message
00064         """
00065         _ = self.request.getText
00066         page = Page(self.request, self.pagename)
00067         if not (page.isWritable() and self.request.user.may.read(self.pagename)):
00068             # Same error as the edit page for localization reasons
00069             return _('You are not allowed to edit this page.')
00070         return ''

Here is the caller graph for this function:

Redirect to the new page, using edit action and template 

Definition at line 71 of file newpage.py.

00071 
00072     def render(self):
00073         """ Redirect to the new page, using edit action and template """
00074         error = self.checkAndCombineArguments() or self.checkPermissions()
00075         if error:
00076             # Send back to the page you came from, with an error msg
00077             page = Page(self.request, self.referrer)
00078             self.request.theme.add_msg(error, "error")
00079             page.send_page()
00080         else:
00081             # Redirect to new page using edit action. No error checking
00082             # is needed because it is done later in new request.
00083             pagename = self.pagename
00084             query = {'action': 'edit', 'backto': self.referrer}
00085 
00086             template = self.request.values.get('template', '')
00087             if template:
00088                 query['template'] = template
00089 
00090             parent = self.request.values.get('parent', '')
00091             if parent:
00092                 pagename = "%s/%s" % (parent, pagename)
00093 
00094             url = Page(self.request, pagename).url(self.request, query)
00095             self.request.http_redirect(url)
00096 
00097         return ''

Here is the call graph for this function:


Member Data Documentation

Definition at line 23 of file newpage.py.

Definition at line 22 of file newpage.py.

Definition at line 21 of file newpage.py.

Definition at line 20 of file newpage.py.


The documentation for this class was generated from the following file: