1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - MoinShare library 4 5 @copyright: 2011, 2012 by Paul Boddie <paul@boddie.org.uk> 6 @license: GNU GPL (v2 or later), see COPYING.txt for details. 7 """ 8 9 from MoinSupport import * 10 from MoinMoin import wikiutil 11 from DateSupport import getCurrentTime 12 import re 13 14 escape = wikiutil.escape 15 _getFragments = getFragments 16 17 __version__ = "0.1" 18 19 # More Moin 1.9 compatibility functions. 20 21 def has_member(request, groupname, username): 22 if hasattr(request.dicts, "has_member"): 23 return request.dicts.has_member(groupname, username) 24 else: 25 return username in request.dicts.get(groupname, []) 26 27 # Fragments employ a "moinshare" attribute. 28 29 fragment_attribute = "moinshare" 30 31 def getFragments(s): 32 fragments = [] 33 for format, attributes, body in _getFragments(s): 34 if attributes.has_key(fragment_attribute): 35 fragments.append((format, attributes, body)) 36 return fragments 37 38 def getOutputTypes(request, format): 39 40 """ 41 Using the 'request' and the 'format' of a fragment, return the media types 42 available for the fragment. 43 """ 44 45 # This uses an extended parser API method if available. 46 47 parser = getParserClass(request, format) 48 if hasattr(parser, "getOutputTypes"): 49 return parser.getOutputTypes() 50 else: 51 return ["text/html"] 52 53 def getPreferredOutputTypes(request, mimetypes): 54 55 """ 56 Using the 'request', perform content negotiation, obtaining mimetypes common 57 to the fragment (given by 'mimetypes') and the client (found in the Accept 58 header). 59 """ 60 61 accept = getHeader(request, "Accept", "HTTP") 62 if accept: 63 prefs = getContentPreferences(accept) 64 return prefs.get_preferred_types(mimetypes) 65 else: 66 return mimetypes 67 68 def getUpdatedTime(metadata): 69 70 """ 71 Return the last updated time based on the given 'metadata', using the 72 current time if no explicit last modified time is specified. 73 """ 74 75 # NOTE: We could attempt to get the last edit time of a fragment. 76 77 latest_timestamp = metadata.get("last-modified") 78 if latest_timestamp: 79 return latest_timestamp.as_ISO8601_datetime_string() 80 else: 81 return getCurrentTime().as_ISO8601_datetime_string() 82 83 # vim: tabstop=4 expandtab shiftwidth=4