[cc-commits] [CC SVN] r12156 - scicom/mta/branches/nyergler-mta2-branch/scicom/mta_web
webmaster at creativecommons.org
webmaster at creativecommons.org
Tue Apr 14 17:31:16 EDT 2009
Author: nyergler
Date: 2009-04-14 21:31:16 +0000 (Tue, 14 Apr 2009)
New Revision: 12156
Added:
scicom/mta/branches/nyergler-mta2-branch/scicom/mta_web/one.py
Modified:
scicom/mta/branches/nyergler-mta2-branch/scicom/mta_web/app.py
Log:
Split actual dispatch out by version.
Modified: scicom/mta/branches/nyergler-mta2-branch/scicom/mta_web/app.py
===================================================================
--- scicom/mta/branches/nyergler-mta2-branch/scicom/mta_web/app.py 2009-04-14 21:30:49 UTC (rev 12155)
+++ scicom/mta/branches/nyergler-mta2-branch/scicom/mta_web/app.py 2009-04-14 21:31:16 UTC (rev 12156)
@@ -8,21 +8,16 @@
import simplejson
import genshi.template
-
import scicom.mta
import scicom.mta.mesh
-# import mthack
import letters.letter
+import one
+import two
+from const import STATIC_DIR, TEMPLATE_DIR, MESH_SOURCE
-STATIC_DIR = os.path.abspath(
- os.path.join(os.path.dirname(__file__), 'static',)
- )
-TEMPLATE_DIR = os.path.abspath(
- os.path.join(os.path.dirname(__file__), 'templates',)
- )
-MESH_SOURCE = os.path.join(STATIC_DIR, 'mesh_2007_trees')
+from materials import MtaMaterial
class Mesh(object):
"""Serve MeSH information as part of a CherryPy web application."""
@@ -39,51 +34,6 @@
return simplejson.dumps({'Result':mesh_tree.query(query)},
cls=scicom.mta.mesh.MeshEntryJsonEncoder)
-class MtaMaterial(object):
-
- def __init__(self, loader):
-
- # get a handle to the database session
- self.session = scicom.mta.connect_session()
- self.__loader = loader
-
- @cherrypy.expose
- def add(self, description, provider, provider_url=None, more_info=None):
- # create the new material
- new_material = scicom.mta.material.Material(
- description, provider, provider_url, more_info)
-
- # store the material
- self.session.save(new_material)
- self.session.flush()
-
- # return the stable URI
- return new_material.view_uri()
-
- @cherrypy.expose
- def view(self, id):
-
- # get the Material
- query = self.session.query(scicom.mta.material.Material)
- material = query.select_by(material_id=id)
-
- # pass the Material off to a template
- template = self.__loader.load('material.html')
- stream = template.generate(material=material[0])
-
- return stream.render('xhtml')
-
- # a crude index page of known materials
- # todo: same thing with search, sort, grid view
- @cherrypy.expose
- def index(self):
-
- query = self.session.query(scicom.mta.material.Material)
- materials = query.select()
- template = self.__loader.load('material-index.html')
- stream = template.generate(materials=materials)
- return stream.render('xhtml')
-
class MtaAgreements(object):
"""Serve the agreements and related documents"""
@@ -91,7 +41,9 @@
def __init__(self, loader):
self.__loader = loader
-
+ self.__one = one.Mta(loader)
+ self.__two = two.Mta(loader)
+
@cherrypy.expose
def default(self, code=None, version="1.0", *args, **kwargs):
@@ -104,146 +56,13 @@
if args.__len__() > 0:
doctype = args[0]
else:
- return self.deed(code, version, kwargs)
+ doctype = 'deed'
- if doctype == 'legalcode':
- return self.legalcode(code, version, kwargs)
+ if version == '1.0':
+ return self.__one.dispatch(basecode, code, doctype, **kwargs)
+ elif version == '2.0':
+ return self.__two.dispatch(basecode, code, doctype, **kwargs)
- if doctype == 'legaltext':
- return self.legaltext(code, version)
-
- if doctype == 'icon':
- return self.icon(basecode, version)
-
- # might use basecode here
- if doctype == 'letter':
- return self.letter(basecode, version, kwargs)
-
- raise cherrypy.HTTPError(404)
-
- def deed(self, code, version, kwargs):
- template = self.__loader.load("deed.html")
- basecode = self.basecode(code)
-
- # same for all deeds
- permissions = [
- {'long': 'Use the materials for research that you supervise',
- 'uri': 'sc:YourResearch'},
- {'long': 'Allow others under your supervision to use the materials',
- 'uri': 'sc:OthersResearch'},
- {'long':'Publish the results of your research',
- 'uri': 'sc:Publish'}]
-
- # default
- footer = 'You will acknowledge provider in publications reporting use of the materials.'
- legalurl = '/agreements/' + code + "/" + version + '/legalcode'
-
- if code == 'ubmta':
- longname = 'Uniform Biological Material Transfer Agreement'
- conditions = [
- {'long': 'You may not use the materials for clinical purposes.',
- 'code': 'no-clinical',
- 'uri': 'sc:Clinical' },
- {'long': 'You may only use the materials for teaching and academic research.',
- 'code': 'nc',
- 'uri': 'cc:CommercialUse'},
- {'long': 'You may not transfer or distribute the materials, except only Modifications to non-profit organizations under the UBMTA. ',
- 'code': 'no-distribution',
- 'uri': 'sc:Transfer'},
- {'long': 'You will return or destroy materials upon completion of research or expiration of the implementing letter.',
- 'uri': 'sc:Retention',
- 'code': 'return'}]
-
- if code == 'sla':
- longname = 'Simple Letter Agreement'
- conditions = [
- {'long': 'You may not use the materials for clinical purposes.',
- 'code': 'no-clinical',
- 'uri': 'sc:Clinical'},
- {'long': 'You may only use the materials for teaching and academic research.',
- 'code': 'nc',
- 'uri': 'cc:CommercialUse'},
- {'long': 'You may not transfer or distribute the materials without permission.',
- 'code': 'no-distribution',
- 'uri': 'sc:Transfer'}]
-
- # must be sc
- splits = code.split('-')
-
- if splits[0] == 'sc':
- longname = 'Science Commons Material Transfer Agreement'
-
- fieldStr = 'Limited to %s' % kwargs['fieldSpec'] if kwargs.__contains__('fieldSpec') else None;
-
- footer = ''
- conditions = [
- {'long': 'You may not use the materials for clinical purposes.',
- 'code': 'no-clinical',
- 'uri': 'sc:Clinical'},
- {'long': 'You may not use the materials in connection with the sale of a product or service.',
- 'code': 'nc',
- 'uri': 'cc:CommercialUse'},
- {'long': 'You may not transfer or distribute the materials. ',
- 'code': 'no-distribution',
- 'uri': 'sc:Transfer'}]
-
- if splits.__contains__('rp'):
- conditions.insert(0, {'long': 'Your use of the materials is restricted to a specific research protocol.',
- 'code': 'restricted-field',
- 'extra': fieldStr})
- if splits.__contains__('df'):
- conditions.insert(0, {'long': 'Your use of the materials is restricted by fields of use.',
- 'code': 'restricted-field',
- 'extra': fieldStr
- })
- if splits.__contains__('ns'):
- conditions.append({'long': 'You may not produce additional quantities of the materials.',
- 'code': 'no-scaling',
- 'uri': 'sc:ScalingUp'})
- if splits.__contains__('rd'):
- conditions.append({'long': 'You will return or destroy the materials upon completion of research or the termination of the agreement.',
- 'uri': 'sc:Retention',
- 'code': 'return'})
-
- if kwargs.__contains__('endDate'):
- conditions.append({'long': 'This agreement terminates on %s' % kwargs['endDate'],
- 'code': 'end-date'})
-
- stream = template.generate(code=code, version=version, permissions=permissions, conditions=conditions, footer=footer, legalurl=legalurl, longname=longname)
- return stream.render("xhtml")
-
- def letter(self, code, version, kwargs):
- if code == 'ubmta':
- l = letters.letter.UBMTALetter()
- elif code == 'sla':
- l = letters.letter.SLALetter()
- elif code == 'sc':
- l = letters.letter.SCLetter()
- else:
- raise cherrypy.HTTPError(404, 'Unknown license %s' % code)
- # do this first to catch errors before declaring it a pdf
- result = l(**kwargs)
- l.pdf_prepare_response('implementing-letter')
- return result
-
- def icon(self, code, version):
- filename = STATIC_DIR + '/images/mta/' + code + '.png'
- string = open(filename).read()
- cherrypy.response.headers['Content-Type'] = 'image/png'
- return string
-
- # MTA legal code
- def legalcode(self, code, version, kwargs):
-
- template = self.__loader.load("legal.html")
- stream = template.generate(agreementType=code, version=version, agreementText=self.legaltext(code, version), **kwargs)
- return stream.render("xhtml")
-
- def legaltext(self, code, version):
- filename = STATIC_DIR + '/legal/' + version + '/' + code + '.txt'
- string = open(filename).read()
- return string
-
# return the base code, or error out
def basecode(self, code):
if ['ubmta', 'sla'].__contains__(code):
@@ -253,7 +72,6 @@
return 'sc'
raise cherrypy.HTTPError(404, 'Unknown license %s' % code)
-
class MtaWeb(object):
def __init__(self):
Added: scicom/mta/branches/nyergler-mta2-branch/scicom/mta_web/one.py
===================================================================
--- scicom/mta/branches/nyergler-mta2-branch/scicom/mta_web/one.py (rev 0)
+++ scicom/mta/branches/nyergler-mta2-branch/scicom/mta_web/one.py 2009-04-14 21:31:16 UTC (rev 12156)
@@ -0,0 +1,161 @@
+# MTA 1.0 support
+import cherrypy
+from const import STATIC_DIR, TEMPLATE_DIR, MESH_SOURCE
+
+class Mta(object):
+
+ """Serve the MTA 1.0 agreements and related documents"""
+
+ VERSION = '1.0'
+
+ def __init__(self, loader):
+
+ self.__loader = loader
+
+ def dispatch(self, basecode, code, doctype, **kwargs):
+
+ if doctype == 'deed':
+ return self.deed(code, kwargs)
+
+ if doctype == 'legalcode':
+ return self.legalcode(code, kwargs)
+
+ if doctype == 'legaltext':
+ return self.legaltext(code)
+
+ if doctype == 'icon':
+ return self.icon(basecode)
+
+ # might use basecode here
+ if doctype == 'letter':
+ return self.letter(basecode, kwargs)
+
+ raise cherrypy.HTTPError(404)
+
+ def deed(self, code, kwargs):
+ template = self.__loader.load("deed.html")
+
+ # same for all deeds
+ permissions = [
+ {'long': 'Use the materials for research that you supervise',
+ 'uri': 'sc:YourResearch'},
+ {'long': 'Allow others under your supervision to use the materials',
+ 'uri': 'sc:OthersResearch'},
+ {'long':'Publish the results of your research',
+ 'uri': 'sc:Publish'}]
+
+ # default
+ footer = 'You will acknowledge provider in publications reporting use of the materials.'
+ legalurl = '/agreements/' + code + "/" + self.VERSION + '/legalcode'
+
+ if code == 'ubmta':
+ longname = 'Uniform Biological Material Transfer Agreement'
+ conditions = [
+ {'long': 'You may not use the materials for clinical purposes.',
+ 'code': 'no-clinical',
+ 'uri': 'sc:Clinical' },
+ {'long': 'You may only use the materials for teaching and academic research.',
+ 'code': 'nc',
+ 'uri': 'cc:CommercialUse'},
+ {'long': 'You may not transfer or distribute the materials, except only Modifications to non-profit organizations under the UBMTA. ',
+ 'code': 'no-distribution',
+ 'uri': 'sc:Transfer'},
+ {'long': 'You will return or destroy materials upon completion of research or expiration of the implementing letter.',
+ 'uri': 'sc:Retention',
+ 'code': 'return'}]
+
+ if code == 'sla':
+ longname = 'Simple Letter Agreement'
+ conditions = [
+ {'long': 'You may not use the materials for clinical purposes.',
+ 'code': 'no-clinical',
+ 'uri': 'sc:Clinical'},
+ {'long': 'You may only use the materials for teaching and academic research.',
+ 'code': 'nc',
+ 'uri': 'cc:CommercialUse'},
+ {'long': 'You may not transfer or distribute the materials without permission.',
+ 'code': 'no-distribution',
+ 'uri': 'sc:Transfer'}]
+
+ # must be sc
+ splits = code.split('-')
+
+ if splits[0] == 'sc':
+ longname = 'Science Commons Material Transfer Agreement'
+
+ fieldStr = 'Limited to %s' % kwargs['fieldSpec'] if kwargs.__contains__('fieldSpec') else None;
+
+ footer = ''
+ conditions = [
+ {'long': 'You may not use the materials for clinical purposes.',
+ 'code': 'no-clinical',
+ 'uri': 'sc:Clinical'},
+ {'long': 'You may not use the materials in connection with the sale of a product or service.',
+ 'code': 'nc',
+ 'uri': 'cc:CommercialUse'},
+ {'long': 'You may not transfer or distribute the materials. ',
+ 'code': 'no-distribution',
+ 'uri': 'sc:Transfer'}]
+
+ if splits.__contains__('rp'):
+ conditions.insert(0, {'long': 'Your use of the materials is restricted to a specific research protocol.',
+ 'code': 'restricted-field',
+ 'extra': fieldStr})
+ if splits.__contains__('df'):
+ conditions.insert(0, {'long': 'Your use of the materials is restricted by fields of use.',
+ 'code': 'restricted-field',
+ 'extra': fieldStr
+ })
+ if splits.__contains__('ns'):
+ conditions.append({'long': 'You may not produce additional quantities of the materials.',
+ 'code': 'no-scaling',
+ 'uri': 'sc:ScalingUp'})
+ if splits.__contains__('rd'):
+ conditions.append({'long': 'You will return or destroy the materials upon completion of research or the termination of the agreement.',
+ 'uri': 'sc:Retention',
+ 'code': 'return'})
+
+ if kwargs.__contains__('endDate'):
+ conditions.append({'long': 'This agreement terminates on %s' % kwargs['endDate'],
+ 'code': 'end-date'})
+
+ stream = template.generate(code=code, version=self.VERSION, permissions=permissions, conditions=conditions, footer=footer, legalurl=legalurl, longname=longname)
+ return stream.render("xhtml")
+
+ def letter(self, code, kwargs):
+ if code == 'ubmta':
+ l = letters.letter.UBMTALetter()
+ elif code == 'sla':
+ l = letters.letter.SLALetter()
+ elif code == 'sc':
+ l = letters.letter.SCLetter()
+ else:
+ raise cherrypy.HTTPError(404, 'Unknown license %s' % code)
+ # do this first to catch errors before declaring it a pdf
+ result = l(**kwargs)
+ l.pdf_prepare_response('implementing-letter')
+ return result
+
+ def icon(self, code):
+ filename = STATIC_DIR + '/images/mta/' + code + '.png'
+ string = open(filename).read()
+ cherrypy.response.headers['Content-Type'] = 'image/png'
+ return string
+
+ # MTA legal code
+ def legalcode(self, code, kwargs):
+
+ template = self.__loader.load("legal.html")
+ #stream = template.generate(agreementType=code, version=self.VERSION, agreementText=self.legaltext(code), **kwargs)
+ stream = template.generate(agreementType=code, version=self.VERSION,
+ **kwargs)
+ return stream.render("xhtml")
+
+ def legaltext(self, code):
+ filename = STATIC_DIR + '/legal/' + self.VERSION + '/' + code + '.txt'
+ string = open(filename).read()
+ cherrypy.response.headers['Content-Type'] = 'text/plain'
+ return string
+
+
+
More information about the cc-commits
mailing list