29a30,32 > Frank Steinhauer (FST) 11.2010: > * added approval changes based on Oliver Siemoneit (12.2006) and "lameike" (02.2010) > 205a209,308 > #FST start new methods > def isApprovedPage(self): > """ is this page/document approved? > @rtype: bool > @return: true, if this page has been approved > """ > approvedFile = os.path.join(self.getPagePath(), "approved") > if os.path.isfile(approvedFile): > approvedRevision = {} > for line in open(approvedFile).readlines(): > tmp = line.split("\t") > approvedRevision[tmp[0]] = tmp[1] > currentRevision = "%08d" % self.get_real_rev() > if currentRevision in approvedRevision: > return True > return False > > def getLastApprovedVersion(self): > """ get the last approved version of this page/document > @rtype: int > @return: version number, None if page is not approved (yet) > """ > approvedFile = os.path.join(self.getPagePath(), "approved") > if os.path.isfile(approvedFile): > approvedRevision = [] > for line in open(approvedFile).readlines(): > tmp = line.split("\t") > approvedRevision.append(int(tmp[0])) > if len(approvedRevision) == 0: > return None > else: > return max(approvedRevision) > else: > return None > > def getApprovalMessage(self): > pi = self.parse_processing_instructions() > if pi['review'] == None: > return "" > currentRevision = self.get_real_rev() > approvedFile = os.path.join(self.getPagePath(), "approved") > approvedRevision = [] > approvers = [] > approvedDateTime = [] > approvedURL = [] > boxtype = "warning" > history = "" > if os.path.isfile(approvedFile): > for line in open(approvedFile).readlines(): > tmp = line.split("\t") > approvedRevision.append(int(tmp[0])) > approvers.append(tmp[1]) > #thatTime = datetime.strptime(tmp[2], "%Y/%m/%d %H:%M:S") > #approvedDateTime.append(thatTime.isoformat()) > approvedDateTime.append(tmp[2] if len(tmp) > 2 else ">see Info or last line in revision<" ) > approvedURL.append( '%s/%s?action=show&rev=%d' % ( > self.request.getScriptname(), > wikiutil.quoteWikinameURL(self.page_name), > int(tmp[0])) ) > > history = "" > for i in range(len(approvedRevision)): > history = ("Version %d: approved on %s by %s\n
\n%s
") % (approvedURL[i], approvedRevision[i], approvedDateTime[i], approvers[i], history ) > > if (currentRevision == len(self.getRevList())) and (not currentRevision == max(approvedRevision)): > # most recent version, not yet approved > status = "Draft" > boxtype = "caution" > elif currentRevision == max(approvedRevision): > # latest approved version (could but need not be most recent version of all) > status = "Approved" > boxtype = "important" > elif currentRevision in approvedRevision: > # any approved version (not the latest because of previous block) > status = "Invalid (approved, but outdated)!" > boxtype = "warning" > else: > # some in-between version, never approved > status = "Invalid" > boxtype = "warning" > else: > # no approval history yet, so this is a draft > status = "Draft" > boxtype = "caution" > > return ''' >
>
>
Version: %d Status: %s
> > %s > >
>
>
> ''' % (boxtype, currentRevision, status, history) > > #FST end new methods > > 495c598 < raise --- > raise err 903a1007 > pi['review'] = None #FST added review to pi 958a1063,1067 > #FST > elif verb == "review": > # this page can be reviewed (and approved) > pi['review'] = args # this is most propably "yes" > #FST end 979c1088 < #request.headers['Content-Length'] = len(text) # XXX WRONG! text is unicode obj, but we send utf-8! --- > #request.setHttpHeader("Content-Length: %d" % len(text)) # XXX WRONG! text is unicode obj, but we send utf-8! 985c1094 < request.headers['Content-Disposition'] = dispo_string --- > request.headers.add('Content-Disposition', dispo_string) 1078a1188 > unapproved = 0 # FST 1086a1197,1216 > #FST > # before sending anything check if we need to redirect to the last approved version > if (pi['review'] != None) and (not self.isApprovedPage()) and (not request.user.may.review(self.page_name)): > lastApprovedRevision = self.getLastApprovedVersion() > if (lastApprovedRevision != None): > # redirect to last approved version > rev = int(lastApprovedRevision) > # FST 162: pi['redirect'] = self.page_name > url_str = '%s/%s?action=show&rev=%d' % ( > request.getScriptname(), > wikiutil.quoteWikinameURL(self.page_name), > rev) > request.http_redirect(url_str) > return > # FST 162 without else, just comment below: > # FST 162 # else redirect to "Sorry, page is not yet approved!" page. > else: > # TODO check how to display "You are not allowed to view..." or "Not yet approved" > unapproved = 1 > #FST end 1099c1229 < #request.headers['Last-Modified'] = util.timefuncs.formathttpdate(lastmod) --- > #request.setHttpHeader("Last-Modified: %s" % util.timefuncs.formathttpdate(lastmod)) 1180a1311,1314 > #FST > elif unapproved == 1: > special = 'notapproved' > #FST end 1385a1520,1524 > #FST > elif special_type == 'notapproved': > page = wikiutil.getLocalizedPage(request, 'PermissionDeniedPage') > alternative_text = u"'''%s'''" % _('Sorry, this page has not been approved yet.') > #FST end 1413c1552 < for rev in os.listdir(rev_dir): --- > for rev in os.listdir(rev_dir): # FST 191: filesys.dclistdir(rev_dir): 1834c1973 < for name in os.listdir(path): --- > for name in os.listdir(path): # FST 191: filesys.dclistdir(path):