def expand_macro(self, formatter, names, content): if not content: edit = '' text = "''Gringlet Name Missing''" acl = '' elif not re.match(r'^[a-zA-Z0-9]+$', content): edit = '' text = tag.em("Invalid Gringlet Name - only letters and numbers allowed") acl = '' else: db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute('SELECT text,acl FROM gringotts WHERE name=%s AND version=' '(SELECT MAX(version) FROM gringotts WHERE name=%s)', (content, content)) try: text,acl = cursor.fetchone() key = str(self.config.get('gringotts', 'key')) k = ezPyCrypto.key(key) text = wiki_to_html(k.decStringFromAscii(text), self.env, formatter.req) edit = 'Edit' except: edit = 'Create' text = tag.em("No Gringlet called \"%s\" found" % content) acl = '' if acl: if not validate_acl(formatter.req, acl): text = tag.em("You do not have permission to view the \"%s\" Gringlet." % content) edit = '' control = None if edit: control = tag.div(tag.a(edit, href=(formatter.href.gringotts() + "/" + content + "?action=edit")), class_="gringottcontrol") # Use eight divs for flexible frame styling return tag.div( tag.div( tag.div( tag.div( tag.div( tag.div( tag.div( tag.div( tag.div(text, class_="gringottcontent") + control, class_="gringott"), class_="gringott"), class_="gringott"), class_="gringott"), class_="gringott"), class_="gringott"), class_="gringott"), class_="gringottframe")
def expand_macro(self, formatter, names, content): if not content: edit = '' text = "''Gringlet Name Missing''" acl = '' elif not re.match(r'^[a-zA-Z0-9]+$', content): edit = '' text = tag.em( "Invalid Gringlet Name - only letters and numbers allowed") acl = '' else: db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute( 'SELECT text,acl FROM gringotts WHERE name=%s AND version=' '(SELECT MAX(version) FROM gringotts WHERE name=%s)', (content, content)) try: text, acl = cursor.fetchone() key = str(self.config.get('gringotts', 'key')) k = ezPyCrypto.key(key) text = wiki_to_html(k.decStringFromAscii(text), self.env, formatter.req) edit = 'Edit' except: edit = 'Create' text = tag.em("No Gringlet called \"%s\" found" % content) acl = '' if acl: if not validate_acl(formatter.req, acl): text = tag.em( "You do not have permission to view the \"%s\" Gringlet." % content) edit = '' control = None if edit: control = tag.div(tag.a(edit, href=(formatter.href.gringotts() + "/" + content + "?action=edit")), class_="gringottcontrol") # Use eight divs for flexible frame styling return tag.div(tag.div(tag.div(tag.div(tag.div(tag.div( tag.div(tag.div(tag.div(text, class_="gringottcontent") + control, class_="gringott"), class_="gringott"), class_="gringott"), class_="gringott"), class_="gringott"), class_="gringott"), class_="gringott"), class_="gringottframe")
def render_macro(self, req, name, content): # args will be null if the macro is called without parenthesis. if not content: edit = '' text = "''Gringlet Name Missing''" acl = '' elif not re.match(r'^[a-zA-Z0-9]+$', content): edit = '' text = "<em>Invalid Gringlet Name - only letters and numbers allowed</em>" acl = '' else: db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute('SELECT text,acl FROM gringotts WHERE name=%s AND version=' '(SELECT MAX(version) FROM gringotts WHERE name=%s)', (content, content)) try: text,acl = cursor.fetchone() key = str(self.config.get('gringotts', 'key')) k = ezPyCrypto.key(key) text = wiki_to_html(k.decStringFromAscii(text), self.env, req) edit = 'Edit' except: edit = 'Create' text = "<em>No Gringlet called "%s" found</em>" % content acl = '' if acl: if not validate_acl(req, acl): text = "<em>You do not have permission to view the "%s" Gringlet.</em>" % content edit = '' control = '' if edit: control = ('<div class="gringottcontrol">' + \ '<a href="%s/%s">' + edit + '</a>' + \ '</div>') % (req.href.gringotts(), content) # Use eight divs for flexible frame styling html = '<div class="gringottframe"><div class="gringott">' + \ '<div class="gringott"><div class="gringott">' + \ '<div class="gringott"><div class="gringott">' + \ '<div class="gringott"><div class="gringott">' + \ '<div class="gringottcontent">' + \ text + \ '</div>' + \ control + \ '</div></div></div></div></div></div></div></div>' return html
def process_request(self, req): gringlet = req.args.get('gringlet') db = self.env.get_db_cnx() cursor = db.cursor() # Do we want an edit page? if gringlet: req.hdf['wiki.edit_rows'] = 20 cursor.execute('SELECT MAX(version) FROM gringotts WHERE name=%s', (gringlet,)) try: version = int(cursor.fetchone()[0]) except: version = 0 if req.method == 'POST' and req.args.has_key('save'): if int(req.args['version']) != version: # Collision req.hdf['messages'] = [ 'Someone else has editted this Gringlet and your changes have been lost!' ] else: if not validate_acl(req, req.args['acl']): messages = [] messages.append('Your change to the ACL would have locked you out.') messages.append('Please change it accordingly and try again.') req.hdf['messages'] = messages req.hdf['gringlet.version'] = version req.hdf['gringlet.source'] = req.args['text'] req.hdf['gringlet.acl'] = req.args['acl'] add_stylesheet(req, 'common/css/wiki.css') return 'gringlet.cs', None # Save the update key = str(self.config.get('gringotts', 'key')) k = ezPyCrypto.key(key) text = k.encStringToAscii(str(req.args['text'])) cursor.execute('INSERT INTO gringotts (name, version, time, text, acl) ' 'VALUES (%s, %s, %s, %s, %s)', (gringlet, (version+1), int(time()), text, req.args['acl'])) db.commit() version += 1 req.hdf['messages'] = [ 'Gringlet saved successfully.' ] if version > 0: cursor.execute('SELECT text, acl FROM gringotts WHERE name=%s AND version=%s', (gringlet,version)) source,acl = cursor.fetchone() key = str(self.config.get('gringotts', 'key')) k = ezPyCrypto.key(key) source = k.decStringFromAscii(source) else: source = 'Enter the text for your Gringlet here' if req.authname == 'anonymous': acl = '' else: acl = req.authname # If we are allowed, then show the edit page, otherwise just show the listing if validate_acl(req, acl): req.hdf['gringlet.version'] = version req.hdf['gringlet.source'] = source req.hdf['gringlet.acl'] = acl add_stylesheet(req, 'common/css/wiki.css') return 'gringlet.cs', None # Listing page cursor.execute('SELECT name,acl FROM gringotts g1 WHERE version=' '(SELECT MAX(version) FROM gringotts g2 WHERE g1.name=g2.name) ' 'ORDER BY name') names = [] for name,acl in cursor: names.append({'name': name, 'permitted': validate_acl(req, acl)}) req.hdf['gringlets.list'] = names req.hdf['gringotts_href'] = req.href.gringotts() return 'gringotts.cs', None
def process_request(self, req): gringlet = req.args.get('gringlet') db = self.env.get_db_cnx() cursor = db.cursor() # Do we want an edit page? if gringlet: cursor.execute('SELECT MAX(version) FROM gringotts WHERE name=%s', (gringlet,)) try: version = int(cursor.fetchone()[0]) except: version = 0 messages = [] action = 'edit' if req.method == 'POST' and req.args.has_key('save'): if int(req.args['version']) != version: # Collision messages.append('Someone else has editted this Gringlet and your changes have been lost!') else: if not validate_acl(req, req.args['acl']): messages.append('Your change to the ACL would have locked you out.') messages.append('Please change it accordingly and try again.') data = { 'action': 'edit', 'edit_rows': '20', 'messages': messages, 'gringlet': { 'name': gringlet, 'version': version, 'source': req.args['text'], 'acl': req.args['acl'] } } add_stylesheet(req, 'common/css/wiki.css') return 'gringlet.html', data, None # Save the update key = str(self.config.get('gringotts', 'key')) k = ezPyCrypto.key(key) text = k.encStringToAscii(str(req.args['text'])) cursor.execute('INSERT INTO gringotts (name, version, time, text, acl) ' 'VALUES (%s, %s, %s, %s, %s)', (gringlet, (version+1), int(time()), text, req.args['acl'])) db.commit() version += 1 messages.append('Gringlet saved successfully.') action = 'view' if version > 0: cursor.execute('SELECT text, acl FROM gringotts WHERE name=%s AND version=%s', (gringlet,version)) source,acl = cursor.fetchone() key = str(self.config.get('gringotts', 'key')) k = ezPyCrypto.key(key) source = k.decStringFromAscii(source) else: source = 'Enter the text for your Gringlet here' if req.authname == 'anonymous': acl = '' else: acl = req.authname # If we are allowed, then show the edit page, otherwise just show the listing if validate_acl(req, acl): if not req.args.has_key('action') or req.args['action'] != 'edit': action = 'view' data = { 'action': action, 'edit_rows': '20', 'messages': messages, 'gringlet': { 'name': gringlet, 'version': version, 'source': source, 'acl': acl } } else: messages.append("You do not have the necessary permission to see this Gringlett") data = { 'action': 'view', 'messages': messages } add_stylesheet(req, 'common/css/wiki.css') return 'gringlet.html', data, None # Listing page cursor.execute('SELECT name,acl FROM gringotts g1 WHERE version=' '(SELECT MAX(version) FROM gringotts g2 WHERE g1.name=g2.name) ' 'ORDER BY name') names = [] for name,acl in cursor: names.append({'name': name, 'permitted': validate_acl(req, acl)}) data = { 'gringlets' : { 'list': names } } return 'gringotts.html', data, None