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