本文整理汇总了Python中MoinMoin.Page.Page.getPagePath方法的典型用法代码示例。如果您正苦于以下问题:Python Page.getPagePath方法的具体用法?Python Page.getPagePath怎么用?Python Page.getPagePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoinMoin.Page.Page
的用法示例。
在下文中一共展示了Page.getPagePath方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_comment
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def save_comment(self):
_ = self.macro.request.getText
if get_input(self.macro, "do") != u"comment_add":
# This is not a comment post do nothing
return
if get_cfg(self.macro, "comment_recaptcha", False):
import captcha
self.captcha = captcha.submit(
get_input(self.macro, "recaptcha_challenge_field"),
get_input(self.macro, "recaptcha_response_field"),
get_cfg(self.macro, "comment_recaptcha_private_key"),
self.macro.request.remote_addr,
)
self.get_comment()
self.errors = self.errors_check()
if not self.errors: # Save the comment
# Find out where to save the comment:
if get_cfg(self.macro, "comment_moderate", True):
page = Page(self.macro.request, get_cfg(self.macro, "comment_approval_page", "CommentsApproval"))
comment_dir = page.getPagePath("", check_create=0)
else:
page = Page(self.macro.request, self.page_name)
comment_dir = page.getPagePath("comments", check_create=1)
now = datetime.now()
random_str = "".join([choice(letters + digits) for i in range(20)])
comment_file = "%s-%s.txt" % (now.strftime("%s"), random_str)
file_name = os.path.join(comment_dir, comment_file)
comment = self.comment
comment["page"] = self.page_name
comment["time"] = now
if get_cfg(self.macro, "comment_store_addr", False):
comment["remote_addr"] = self.macro.request.remote_addr
write_comment(file_name, comment)
if get_cfg(self.macro, "comment_moderate", True):
self.msg = _("Your comment awaits moderation. Thank you.")
else:
self.msg = _("Your comment has been posted. Thank you.")
# clean up the fields to display
self.comment = {"user_name": "", "comment": "", "email": ""}
示例2: do_replaceunderlay
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def do_replaceunderlay(self, filename, pagename):
"""
Overwrites underlay pages. Implementational detail: This needs to be
kept in sync with the page class.
@param filename: name of the file in the package
@param pagename: page to be overwritten
"""
page = Page(self.request, pagename)
pagedir = page.getPagePath(use_underlay=1, check_create=1)
revdir = os.path.join(pagedir, 'revisions')
cfn = os.path.join(pagedir, 'current')
revstr = '%08d' % 1
if not os.path.exists(revdir):
os.mkdir(revdir)
currentf = open(cfn, 'w')
currentf.write(revstr + "\n")
currentf.close()
pagefile = os.path.join(revdir, revstr)
self._extractToFile(filename, pagefile)
# Clear caches
try:
del self.request.cfg.DICTS_DATA
except AttributeError:
pass
self.request.pages = {}
caching.CacheEntry(self.request, 'wikidicts', 'dicts_groups', scope='wiki').remove()
page.clean_acl_cache()
示例3: getAttachDir
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def getAttachDir(request, pagename, create=0):
""" Get directory where attachments for page `pagename` are stored. """
if request.page and pagename == request.page.page_name:
page = request.page # reusing existing page obj is faster
else:
page = Page(request, pagename)
return page.getPagePath("attachments", check_create=create)
示例4: do_replaceunderlay
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def do_replaceunderlay(self, filename, pagename):
"""
Overwrites underlay pages. Implementational detail: This needs to be
kept in sync with the page class.
@param filename: name of the file in the package
@param pagename: page to be overwritten
"""
page = Page(self.request, pagename)
pagedir = page.getPagePath(use_underlay=1, check_create=1)
revdir = os.path.join(pagedir, 'revisions')
cfn = os.path.join(pagedir, 'current')
revstr = '%08d' % 1
if not os.path.exists(revdir):
os.mkdir(revdir)
currentf = open(cfn, 'w')
currentf.write(revstr + "\n")
currentf.close()
pagefile = os.path.join(revdir, revstr)
self._extractToFile(filename, pagefile)
示例5: approve_comment
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def approve_comment(self):
_ = self.macro.request.getText
# Source
origin = os.path.join(self.approval_dir, self.get_input('file'))
comment = read_comment( origin )
# Destination
page = Page(self.macro.request, comment['page'] )
if not page.exists():
self.msg.append(_('The page this comment was written for don\'t exist any more'))
return
dest_dir = page.getPagePath("comments", check_create=1)
destination = os.path.join(dest_dir,self.get_input('file'))
# Rename the file:
os.rename(origin, destination)
self.msg.append(_('Comment approved'))
示例6: __init__
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def __init__(self, macro):
self.macro = macro
self.page_name = get_cfg(macro, "comment_approval_page", "CommentsApproval")
self.msg = []
if self.page_name != macro.formatter.page.page_name:
# It's mandatory to run the ApproveComments macro from the
# comment_approval_page defined in the configuration
return
page = Page(macro.request, self.page_name)
if not page.exists():
raise ApproveError("You have to create the approval page!")
self.approval_dir = page.getPagePath("", check_create=0)
if macro.request.method == "POST":
if get_input(macro, "do") == u"comment_delete":
self.delete_comment()
if get_input(macro, "do") == u"comment_approve":
self.approve_comment()
示例7: __init__
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def __init__(self, macro ):
self.macro = macro
self.page_name = unicode(self.get_cfg('comment_approval_page',
'CommentsApproval'))
self.msg = []
if self.page_name != macro.formatter.page.page_name:
# It's mandatory to run the ApproveComments macro from the
# comment_approval_page defined in the configuration
return
page = Page(macro.request,self.page_name)
if not page.exists():
raise ApproveError('You have to create the approval page!')
self.approval_dir = page.getPagePath('', check_create=0)
if macro.request.request_method == 'POST':
if self.get_input( 'do' ) == u'comment_delete':
self.delete_comment()
if self.get_input( 'do' ) == u'comment_approve':
self.approve_comment()
示例8: macro_CommentsAdmin
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def macro_CommentsAdmin(macro):
'''
This macro adds an administration functionality to the comments feature.
It can be place anywhere, like for instance the wiki menu, and if the
user is a SuperUser he will see the link to the comments approval page,
with the total of comments waiting for approval.
Usage:
<<CommentsAdmin>>
'''
request = macro.request
formatter = macro.formatter
_ = macro.request.getText
# Configuration:
page_name = unicode(get_cfg(macro, 'comment_approval_page',
'CommentsApproval'))
page = Page(request,page_name)
if not page.exists():
raise ApproveError('You have to create the approval page! (%s)' % (
page_name))
approval_dir = page.getPagePath('', check_create=0)
approval_url = wikiutil.quoteWikinameURL(page_name)
if request.user.isSuperUser():
# Get the number of comments waiting for approval
files = glob.glob('%s/*.txt' % approval_dir)
total_waiting = len(files)
html = u'<a href="%s">%s (%s)</a>' % (
approval_url, _('Pending Comments'), total_waiting)
else:
html = u''
try:
return formatter.rawHTML(html)
except:
return formatter.escapedText('')
示例9: approve_comment
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def approve_comment(self):
_ = self.macro.request.getText
# Source
origin = os.path.join(self.approval_dir, get_input(self.macro, "file"))
comment = read_comment(origin)
# Destination
page = Page(self.macro.request, comment["page"])
if not page.exists():
self.msg.append(_("The page this comment was written for don't exist any more"))
return
dest_dir = page.getPagePath("comments", check_create=1)
destination = os.path.join(dest_dir, get_input(self.macro, "file"))
# Rename the file:
os.rename(origin, destination)
self.msg.append(_("Comment approved"))
# Notify page subscribers:
notify_subscribers(self.macro, comment)
示例10: dictPagePath
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def dictPagePath(self):
page = Page(self.request, self.dictPage)
return page.getPagePath(use_underlay=0, check_create=0)
示例11: macro_Comments
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def macro_Comments(macro, page_name=u''):
'''
Usage:
<<Comments(page_name)>>
Shows the comments of page 'page_name'
or
<<Comments()>>
Shows the page of the current page.
'''
_ = macro.request.getText
request = macro.request
formatter = macro.formatter
# By default show the comments for the current page
if page_name == u'':
page_name = macro.formatter.page.page_name
# Get the configuration:
page = Page(request, page_name )
comments_dir = page.getPagePath("comments", check_create=1)
# Get the page_name comment list
files = glob.glob(os.path.join(comments_dir,'*.txt'))
files.sort()
# Compose the comments markup
html = [u'<a name="comment_section"></a>']
if not files:
html.append(u'<p>%s</p>' % u'コメントはありません')
else:
# Pagination
cmt_per_page = get_cfg_int(macro, 'comment_cmt_per_page',50)
if cmt_per_page:
page_uri = request.url.split('?')[0]
number_messages = len(files)
if number_messages % cmt_per_page:
offset = 1
else:
offset = 0
max_pages = number_messages / cmt_per_page + offset
try:
page_number = get_input_int(macro, 'page_number', 1000 )
except ValueError:
page_number = 1
if page_number > max_pages:
page_number = max_pages
elif page_number < 1:
page_number = 1
first = (page_number - 1) * cmt_per_page
last = first + cmt_per_page
files = files[first:last]
# Get the comments contents
comments = [ read_comment(Xi) for Xi in files]
html.append(u'<ul>')
for comment in comments:
html.append( u"%s" % comment_html(request, comment ) )
if cmt_per_page:
html.append(navbar(request, page_number, max_pages, page_uri))
try:
return formatter.rawHTML('\n'.join(html))
except:
return formatter.escapedText('')
示例12: save_comment
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def save_comment( self ):
_ = self.macro.request.getText
if get_input(self.macro, 'do' ) != u'comment_add':
# This is not a comment post do nothing
return
if get_cfg(self.macro, 'comment_recaptcha', False ) and not self.passpartout:
import captcha
self.captcha = captcha.submit (
get_input(self.macro, 'recaptcha_challenge_field'),
get_input(self.macro, 'recaptcha_response_field'),
get_cfg(self.macro, 'comment_recaptcha_private_key'),
self.macro.request.remote_addr )
self.get_comment()
self.errors = self.errors_check()
if not self.errors: # Save the comment
# Find out where to save the comment:
if self.moderate:
# This commet will be added to the moderation queue
page = Page(self.macro.request,
get_cfg(self.macro, 'comment_approval_page', 'CommentsApproval'))
comment_dir = page.getPagePath('', check_create=0)
else:
# The comment will be immediately posted
page = Page(self.macro.request,self.page_name)
comment_dir = page.getPagePath('comments', check_create=1)
# Compose the comment structure and write it
now = datetime.now()
random_str = ''.join([choice(letters + digits) for i in range(20)])
comment_file = '%s-%s.txt' % (now.strftime("%s"), random_str)
file_name = os.path.join(comment_dir, comment_file)
comment = self.comment
comment['page'] = self.page_name
comment['time'] = now
if get_cfg(self.macro, 'comment_store_addr', False):
comment['remote_addr'] = self.macro.request.remote_addr
if self.moderate:
self.msg = _('Your comment awaits moderation. Thank you.')
else:
self.msg = _('Your comment has been posted. Thank you.')
write_comment( file_name, comment )
if self.moderate:
# If we have defined a list of moderators to notify and this user is
# moderated then a message is sent to the moderator list
moderators = get_cfg(self.macro, 'comment_moderators', None)
if moderators:
sendmail.sendmail( self.macro.request, moderators.split(','),
_('New comment awaits moderation for page %(page)s' % self.comment ),
_('New comment awaits moderation:\n\nPage: %(page)s\nFrom: %(user_name)s\nMessage:\n\n%(comment)s\n\n--' %
self.comment ))
else:
# Send notification to page subscribers if the page
notify_subscribers(self.macro, self.comment)
# clean up the fields to display
self.reset_comment()
示例13: photoupload
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import getPagePath [as 别名]
def photoupload(pagename, request):
_ = request.getText
# if not wikiutil.checkTicket(request, request.form.get('ticket', '')):
# return _('Please use the interactive user interface to use action %(actionname)s!') % {'actionname': 'AttachFile.upload' }
# Currently we only check TextCha for upload (this is what spammers ususally do),
# but it could be extended to more/all attachment write access
# if not TextCha(request).check_answer_from_form():
# return _('TextCha: Wrong answer! Go back and try again...')
form = request.form
file_upload = request.files.get('file')
if not file_upload:
# This might happen when trying to upload file names
# with non-ascii characters on Safari.
return _("No file content. Delete non ASCII characters from the file name and try again.")
try:
overwrite = int(form.get('overwrite', '0'))
except:
overwrite = 0
if not request.user.may.write(pagename):
return _('You are not allowed to attach a file to this page.')
if overwrite and not request.user.may.delete(pagename):
return _('You are not allowed to overwrite a file attachment of this page.')
# target = form.get('target', u'').strip()
# if not target:
# target = file_upload.filename or u''
# target = wikiutil.clean_input(target)
file_upload_ext = os.path.splitext(file_upload.filename)[-1].lower()
if file_upload_ext not in ('.jpg'):
return _('You can upload only following extentions. -- .jpg, but ' + file_upload_ext)
# if not target:
# return _("Filename of attachment not specified!")
if pagename.encode('utf8') == '아메바사진':
path = '/volume1/photo/webpub_amb'#/@eaDir'
elif pagename.encode('utf8') == '사과나무사진관':
path = '/volume1/photo/webpub_apt'#/@eaDir'
else:
path = '/volume1/photo/webpub_tst'
try:
lst = glob.glob(path + '/*.jpg')
lastnumfilepath = sorted(lst)[-1]
lastnumfile = os.path.split(lastnumfilepath)[1]
filenm = os.path.splitext(lastnumfile)[0]
filenum = int(filenm)
filenum += 1
target = "%05d%s" % (filenum, file_upload_ext)
except:
target = "00001" + file_upload_ext
print '-'*100
print path, target
# add the attachment
try:
target, bytes = add_attachment(request, pagename, target, file_upload.stream, overwrite=overwrite)
msg = "Picture '%(target)s' ('%(filename)s',%(bytes)d bytes) have been uploaded." % {
'target': target, 'filename': file_upload.filename, 'bytes': bytes}
except AttachmentAlreadyExists:
msg = _("Attachment '%(target)s' (remote name '%(filename)s') already exists.") % {
'target': target, 'filename': file_upload.filename}
# return attachment list
#upload_form(pagename, request, msg)
# move
# replace illegal chars
target = wikiutil.taintfilename(target)
# get directory, and possibly create it
# attach_dir = getAttachDir(request, pagename, create=1)
if request.page and pagename == request.page.page_name:
page = request.page # reusing existing page obj is faster
else:
page = Page(request, pagename)
attach_dir = page.getPagePath("attachments", check_create=1)
fpath = os.path.join(attach_dir, target).encode(request.cfg.attachment_charset)
os.rename(fpath, path + os.sep + target)
# msg += ' mv %s %s/%s' % (fpath, path, target)
# os.system('synoindex -a ' + path + '/' + target)
# os.system('synoindxe -U photo')
from subprocess import Popen
pid = Popen(["/volume1/photo/create_tn.sh", path, target]).pid
#request.page.send_page()
return msg