コード例 #1
0
ファイル: views.py プロジェクト: bodleian/datafinder
def sourceinfo(request, source):
        # A user needs to be authenticated and authorized  to be able to administer the DataFinder                          
        # Test if the user is now a university authenticated user
        if 'DF_USER_SSO_ID' not in request.session:                          
            return redirect("/login?redirectPath=admin")
            # Test if the user is Data Finder authorised user
        if  request.session['DF_USER_ROLE'] != "admin" :
            return redirect("/")
        
        context = { 
        #'DF_VERSION':settings.DF_VERSION,
        #'STATIC_URL': settings.STATIC_URL,
        'silo_name':"",
        'ident' : "",
        'id':"",
        'path' :"",
        'q':"",
        'src':settings.get("main:granary.uri_root"),
        'host':settings.get("main:granary.host"),
        'typ':"",
        'message':"",
        'silo':"",
        'source_infos':{},
        'header':"",
        'activate':"",
        'unregistered_sources':[],
        'kw':{},
        'sourceinfo':SourceInfo(),
        'roles':[],
        'source':""
        }    
    
#        if not request.environ.get('repoze.who.identity'):
#            abort(401, "Not Authorised")
#        if not ag.granary.issilo(silo):
#            abort(404)
#        ident = request.environ.get('repoze.who.identity')
#        c.ident = ident
#        c.silo = silo
#        silos = ag.authz(ident, permission=['administrator', 'manager'])
#        if not silo in silos:
#            abort(403, "Do not have administrator or manager credentials for silo %s"%silo)
#        user_groups = list_user_groups(ident['user'].user_name)
#        if ('*', 'administrator') in user_groups:
#            #User is super user
#            c.roles = ["admin", "manager", "user"]
#        elif (silo, 'administrator') in user_groups:
#            c.roles = ["admin", "manager", "user"]
#        elif (silo, 'manager') in user_groups:
#            c.roles = ["manager", "user"]
#        else:
#            abort(403, "Do not have administrator or manager credentials for silo %s"%silo)
        http_method = request.environ['REQUEST_METHOD']
        ## hardcoded for now
        context['roles'] = ["admin", "manager", "user"]
        ##c.kw = ag.granary.describe_silo(source)
        user_name = 'admin'
        password = '******'
        datastore = HTTPRequest(endpointhost=context['host'])
        datastore.setRequestUserPass(endpointuser=user_name, endpointpass=password)
        context['source'] = source
        state_info = None     

#        try:
#            c.kw = {    'silo':src.silo, 
#                        'title':src.title,                       
#                        'description':src.description,
#                        'notes':src.notes,
#                        'users':src.users,
#                        'disk_allocation':src.disk_allocation,
#                        'activate':src.activate
#                    }    
#            s_q= meta.Session.query(SourceInfo).filter(SourceInfo.silo == c.source).filter(SourceInfo.activate == False)  
#            s_q.one()
#            return render("/admin_sourceview.html") 
#        except orm.exc.NoResultFound:
#            sourceinfo.activate =  False
#            meta.Session.add(sourceinfo)
#            meta.Session.commit()
#            pass      
#        except IntegrityError:
#            meta.Session.rollback()
#            return False     
            
            ## If the source is not activated only then get the source information from the registered information area
        (resp, respdata) = datastore.doHTTP_GET(resource='/' + source + '/states', expect_type="application/JSON")
        state_info =  json.loads(respdata)
        ##print json.loads(respdata)
        context['kw']=state_info
        
        print "http_method = "
        print http_method
        if http_method == "GET":
            return render_to_response('admin_sourceinfo.html', context, context_instance=RequestContext(request))
        elif http_method == "POST":
            ##silo = request.REQUEST.get('silo', None)
            title = request.REQUEST.get('title', '')
            description = request.REQUEST.get('description', '')
            notes = request.REQUEST.get('notes', '')
            administrators = request.REQUEST.get('administrators', '')
            managers = request.REQUEST.get('managers', '')
            users = request.REQUEST.get('users', '')
            disk_allocation = request.REQUEST.get('disk_allocation', 0)
            fields = \
                [ ("silo", source),
                  ("title", title),
                  ("description", description),
                  ("notes", notes),
                  ("administrators", administrators),
                  ("managers", managers),
                  ("users", users),
                  ("disk_allocation", disk_allocation)
                ]
            print fields
            files =[]
            (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files)
            (resp,respdata) = datastore.doHTTP_POST(reqdata, reqtype, resource='/' + source + "/admin", expect_type="application/JSON")
            resource ='/' + source + "/admin"
            print 'respdata', respdata
            print 'msg', resp.msg
            print 'reason', resp.reason
            print 'status',resp.status
            print resp.read()
##            print "response data for update metadata"
            if  resp.status== 204  :
                context['source'] = source
                context['message'] = "Metadata updated"
                (resp, respdata) = datastore.doHTTP_GET(resource='/' + source + '/states', expect_type="application/JSON")
                state_info =  json.loads(respdata)       
                context['kw']=state_info
                print "before reloading"
                print state_info
                return render_to_response('admin_sourceinfo.html', context, context_instance=RequestContext(request))
            else:
                context['source'] = source
                context['message'] = "Metadata not updated: " + str(resp.status)
                print "metadata not updated: " + str(resp.status)
                #abort(resp.status, respdata )
                return render_to_response('admin_sourceinfo.html', context, context_instance=RequestContext(request))

                
        elif http_method == "DELETE":
            ##fields = [("silo", source)]
            ##print fields
            ##files =[]
            ##(reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files)
            ##(resp,respdata) = datastore.doHTTP_DELETE(reqdata, reqtype, resource='/' + source + "/admin", expect_type="application/JSON")
          
            (resp,respdata) = datastore.doHTTP_DELETE(resource='/' + source + "/admin")
            resource ='/' + source + "/admin"
            print resp.read()
 
            print "Response Status = "
            print resp.status 

            if  resp.status== 200:
                #Modify the source entry in the sqllite database in the data finder. Change activate = False.
                try:
                    s_q = SourceInfo.objects.filter(silo = source)                                        
                    for src in s_q:
                        src.activate = False
                        src.save()
                        print "after save"
                    context['message'] = "Metadata deleted"
                except Exception, e:
                    print "Exception" +  str(e)
                    context['message'] = str(e)
            else:
                context['message'] = "Metadata could not be deleted"
                abort(resp.status, respdata )
            
            return render_to_response('list_of_sources.html', context, context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: bodleian/datafinder
        password = settings.get("main:granary.uri_root_pass") 
        datastore = HTTPRequest(endpointhost=settings.get("main:granary.host"))       
        datastore.setRequestUserPass(endpointuser=user_name, endpointpass=password)
        fields = \
            [ ("silo", context["source"]),
              ("title", context["title"]),
              ("description", context["description"]),
              ("notes", context["notes"]),
              ("uri", context["uri"]),
              ("administrators", settings.get("main:granary.uri_root_name") ),
              ("managers", settings.get("main:granary.uri_root_name") ),
              ("users",settings.get("main:granary.uri_root_name") ),
              #("disk_allocation", "disk_allocation")
            ]
        files =[]
        (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files)
        
        (resp,respdata) = datastore.doHTTP_POST(reqdata, reqtype, resource="/admin", expect_type="application/JSON")

        if  resp.status== 204 or resp.status==201:
            context['message']="Thanks, "+ context["source"] +" has been successfully approved."
            context['status']="success"     
            return redirect("/admin?message="+context['message']+"&status="+context['status'])
        else:
                sourceinfo.activate = False
                sourceinfo.save()
                context['message']="Oops, an error occurred, sorry..." 
                context['status']="error"
                return redirect("/admin?"+"message="+context['message']+"&status="+context['status'])          
        
  
コード例 #3
0
    def sourceinfo(self, source):
        c.silo_name = ''
        c.ident = ''
        c.id =""
        c.path =""
        c.user_logged_in_name=""
        c.q=""
        c.typ=""
        c.src = ag.root
#        if not request.environ.get('repoze.who.identity'):
#            abort(401, "Not Authorised")
#        if not ag.granary.issilo(silo):
#            abort(404)
#        ident = request.environ.get('repoze.who.identity')
#        c.ident = ident
#        c.silo = silo
#        silos = ag.authz(ident, permission=['administrator', 'manager'])
#        if not silo in silos:
#            abort(403, "Do not have administrator or manager credentials for silo %s"%silo)
#        user_groups = list_user_groups(ident['user'].user_name)
#        if ('*', 'administrator') in user_groups:
#            #User is super user
#            c.roles = ["admin", "manager", "user"]
#        elif (silo, 'administrator') in user_groups:
#            c.roles = ["admin", "manager", "user"]
#        elif (silo, 'manager') in user_groups:
#            c.roles = ["manager", "user"]
#        else:
#            abort(403, "Do not have administrator or manager credentials for silo %s"%silo)
        http_method = request.environ['REQUEST_METHOD']
        ## hardcoded for now
        c.roles = ["admin", "manager", "user"]
        ##c.kw = ag.granary.describe_silo(source)
        c.host = ag.host
        c.silo=""
        
        
        user_name = 'admin'
        password = '******'
        datastore = HTTPRequest(endpointhost=c.host)
        datastore.setRequestUserPass(endpointuser=user_name, endpointpass=password)
        c.source = source
        c.message =""
        state_info = None     
        print "source requested: "
        print c.source 
        c.kw={}
#        try:
#            c.kw = {    'silo':src.silo, 
#                        'title':src.title,                       
#                        'description':src.description,
#                        'notes':src.notes,
#                        'users':src.users,
#                        'disk_allocation':src.disk_allocation,
#                        'activate':src.activate
#                    }    
#            s_q= meta.Session.query(SourceInfo).filter(SourceInfo.silo == c.source).filter(SourceInfo.activate == False)  
#            s_q.one()
#            return render("/admin_sourceview.html") 
#        except orm.exc.NoResultFound:
#            sourceinfo.activate =  False
#            meta.Session.add(sourceinfo)
#            meta.Session.commit()
#            pass      
#        except IntegrityError:
#            meta.Session.rollback()
#            return False     
            
            ## If the source is not activated only then get the source information from the registered information area
        (resp, respdata) = datastore.doHTTP_GET(resource='/' + c.source + '/states', expect_type="application/JSON")
        state_info =  json.loads(respdata)       
        ##print json.loads(respdata)
        c.kw=state_info
        
        print "http_method = "
        print http_method
        if http_method == "GET":
            return render("/admin_sourceinfo.html")
        elif http_method == "POST":
            ##silo = request.params.get('silo', None)
            title = request.params.get('title', '')
            description = request.params.get('description', '')
            notes = request.params.get('notes', '')
            administrators = request.params.get('administrators', '')
            managers = request.params.get('managers', '')
            users = request.params.get('users', '')
            disk_allocation = request.params.get('disk_allocation', '')
            fields = \
                [ ("silo", source),
                  ("title", title),
                  ("description", description),
                  ("notes", notes),
                  ("administrators", administrators),
                  ("managers", managers),
                  ("users", users),
                  ("disk_allocation", disk_allocation)
                ]
            print fields
            files =[]
            (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files)
            (resp,respdata) = datastore.doHTTP_POST(reqdata, reqtype, resource='/' + source + "/admin", expect_type="application/JSON")
            resource ='/' + source + "/admin"
            print 'respdata', respdata
            print 'msg', resp.msg
            print 'reason', resp.reason
            print 'status',resp.status
            print resp.read()
##            print "response data for update metadata"
            if  resp.status== 204:
                c.message = "Metadata updated"
                return render("/admin_sourceinfo.html")
            else:
                abort(resp.status, respdata )
                
        elif http_method == "DELETE":
            ##fields = [("silo", source)]
            ##print fields
            ##files =[]
            (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files)
            ##(resp,respdata) = datastore.doHTTP_DELETE(reqdata, reqtype, resource='/' + source + "/admin", expect_type="application/JSON")
          
            (resp,respdata) = datastore.doHTTP_DELETE(resource='/' + source + "/admin")
            resource ='/' + source + "/admin"
            print resp.read()
 
            print "Response Status = "
            print resp.status 

            if  resp.status== 200:
                #Modify the source entry in the sqllite database in the data finder. Change activate = False.
                try:
                    s_q= meta.Session.query(SourceInfo).filter(SourceInfo.silo == source)
                    s_q.one()
                    s_q.update({
                                   'title':title,
                                   'description':description,
                                   'notes':notes,
                                   'administrators':administrators,
                                   'managers':managers,
                                   'users':users,
                                   'disk_allocation':disk_allocation,
                                   'activate':False
                                })     
                    meta.Session.commit()
                except orm.exc.NoResultFound:
                    sourceinfo.activate =  False
                    meta.Session.add(sourceinfo)
                    meta.Session.commit()
                    pass
                except IntegrityError:
                    #log.error('Error adding user %s'%user_details['username'])
                    #print traceback.format_exc()
                    meta.Session.rollback()
                    return False
                c.message = "Metadata deleted"
                return True 
            else:
                print "Failure"
                abort(resp.status, respdata )
コード例 #4
0
    def index(self):
        c.silo_name = ''
        c.ident = ''
        c.id =""
        c.path =""
        c.user_logged_in_name=""
        c.q=""
        c.typ=""
        c.host=ag.host
        print "endpointhost"
        print c.host
        srcurl = ag.root +'/admin'
        silo = request.params.get('silo', "")
        title = request.params.get('title', "")
        description = request.params.get('description', "")
        notes = request.params.get('notes', "")
        administrators = request.params.get('administrators', "")
        managers = request.params.get('managers', "")
        users = request.params.get('users', "")
        disk_allocation = request.params.get('disk_allocation', "")

        user_name = 'admin'
        password = '******'
        datastore = HTTPRequest(endpointhost=c.host)
        
        datastore.setRequestUserPass(endpointuser=user_name, endpointpass=password)
        fields = \
            [ ("silo", silo),
              ("title", title),
              ("description", description),
              ("notes", notes),
              ("administrators", administrators),
              ("managers", managers),
              ("users", users),
              ("disk_allocation", disk_allocation)
            ]
        print fields
        files =[]
        (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files)
        
        (resp,respdata) = datastore.doHTTP_POST(reqdata, reqtype, resource="/admin", expect_type="application/JSON")
        print 'respdata', respdata
        print 'msg', resp.msg
        print 'reason', resp.reason
        print 'status',resp.status
        print resp.read()
##            print "response data for update metadata"
        if  resp.status== 204 or resp.status==201:
            c.message = "Source successfully created."
            
            #Modify the source entry in the sqllite database in the data finder. Change activate = True.
            try:
                s_q= meta.Session.query(SourceInfo).filter(SourceInfo.silo == silo)
                s_q.one()
                s_q.update({
                               'title':title,
                               'description':description,
                               'notes':notes,
                               'administrators':administrators,
                               'managers':managers,
                               'users':users,
                               'disk_allocation':disk_allocation,
                               'activate':True
                            })     
                meta.Session.commit()
            except orm.exc.NoResultFound:
                sourceinfo.activate =  True
                meta.Session.add(sourceinfo)
                meta.Session.commit()
                pass
            except IntegrityError:
                #log.error('Error adding user %s'%user_details['username'])
                #print traceback.format_exc()
                meta.Session.rollback()
                return False
            return redirect(url(controller='list_sources', action='index')) 
        else:
            c.message = "Source could not be successfully activated"
            c.message = c.message + " status: " + repr(resp.status) + " " + resp.reason
            c.kw = {    'silo':silo, 
                        'title':title,                       
                        'description':description,
                        'notes':notes,
                        'administrators': administrators,
                        'managers':managers,
                        'users':users,
                        'disk_allocation':disk_allocation
                       }
            c.header="approve"
            c.activate=None    
            return render("/create_new_source.html")    
コード例 #5
0
ファイル: views.py プロジェクト: bodleian/datafinder
def contribute(request):
   try:
        # A user needs to be authenticated  to be able to contribute a record  the DataFinder                          
        # Test if the user is now a university authenticated user
        if 'DF_USER_SSO_ID' not in request.session:                          
            return redirect("/login?redirectPath=contribute")    
                
        context = {}
        literals = {}
        resources = {}
        project = {}
        person = {}
                
        if request.GET.has_key('message'):    
            context["message"]=request.GET['message']
        if request.GET.has_key('status'):    
            context["status"]=request.GET['status']

        http_method = request.environ['REQUEST_METHOD'] 
        referrer = request.environ['HTTP_REFERER']

    
        if http_method == "GET":     
            if request.GET.has_key('id'):     
                context['id'] = request.GET['id']
                context['referrer'] = referrer
                query = 'id:"' + request.GET['id'] + '"'
                solr_query = SolrQuery(q=query)    
                context['solr_response'] = solr_query.get_solrresponse()  
                #context['docs'] = context['solr_response'].get('docs',None)
            return render_to_response('contribute.html', context, context_instance=RequestContext(request))  
        
        elif http_method == "POST":             
            if request.POST.has_key('record_title'):
                BASE = settings.get("main:manifest.about")
                identifier = request.POST['record_title']    
                subject = URIRef(BASE+identifier)     
                literals[DCTERMS['title']]=request.POST['record_title']
                literals[DCTERMS['alternative']]=request.POST['alt_title']
                literals[DCTERMS['description']]=request.POST['data_description']
                
                project[DCTERMS['title']]=request.POST['project_name']
                project[DCTERMS['description']]=request.POST['project_desc']
                project[DCTERMS['URI']]=request.POST['project_website']
                
                subjects = request.POST.getlist('subject_area')
                #for subj in subjects:
                literals[DCTERMS['subject']]= subjects
                    
                keywords = request.POST.getlist('record_keyword')                
                #for keyword in keywords:
                literals[DCTERMS['keywords']]=keywords
                    
                literals[DCTERMS['language']]=request.POST['main_language']  
                
                if request.POST.has_key('ChangeRecordStatus'):
                        literals[DCTERMS['status']]=request.POST['ChangeRecordStatus'] 
                else: 
                    literals[DCTERMS['status']]='AwaitingReview'
                    
                literals[OXDS['depositor']] = request.session['DF_USER_SSO_ID']
                
                i = 1
                while True:
                     if request.GET.has_key('author_firstname_' + str(i)):                
                            person_title = request.POST['author_firstname_' + str(i)] + '-' +request.POST['author_middlename_' + str(i)] + '-' +request.POST['author_lastname_' + str(i)] 
                                              
                            person[FOAF["givenName"]]=request.POST['author_firstname_' + str(i)]
                            person[FOAF["middleName"]]=request.POST['author_middlename_' + str(i)]   
                            person[OXDS["DisplayEmail"]]=request.POST['author_middlename_check_' +  str(i)]
                            person[FOAF["familyName"]]=request.POST['author_lastname_' + str(i)]    
                            person[FOAF["mbox"]]=request.POST['author_email_' + str(i)]     
                            person[OXDS['role']]=request.POST['author_role_' + str(i)]             

                            author_member_of_oxford = request.POST['author_mof_' + str(i)]    
                            person[FOAF["Organization"]]=request.POST['author_institution_' + str(i)] 
                            if author_member_of_oxford == True:             
                                    person[OXDS["Faculty"]]=request.POST['author_faculty_' + str(i)]                     
                                    person[OXDS["OxfordCollege"]]=request.POST['author_oxfordcollege_'+ str(i)]  
                                    person[OXDS["scheme"]]=request.POST['author_scheme_' + str(i)]  
                                    person[OXDS["AUTHOR_ID"]]=request.POST['author_id_' + str(i)]                                              
                            else:
                                person[OXDS["Faculty"]]=request.POST['author_faculty_text_' + str(i)]
                            
                            people_path = settings.get("main:granary.people_path")        
                            people_manifest_filename = os.path.join(people_path, 'people.rdf')
                            people_manifest = bind_namespaces(rdflib.ConjunctiveGraph())
                            
                            try:
                                with open(people_manifest_filename, 'r') as f:
                                    people_manifest.parse(f, base=people_manifest_filename)
                            except IOError, e:
                                pass
                            
                            if people_manifest.value(FOAF[person_title], None, None) == None:
                                    people_manifest.add((FOAF[person_title], RDF.type, FOAF.Person))
                                    for key, value in person.items():
                                            people_manifest.add((FOAF[person_title], key, Literal(value)))
                                                         
                            
                            with open(people_manifest_filename, 'w') as f:
                                people_manifest.serialize(f, 'better-pretty-xml', base=people_manifest_filename)
                            os.chown(people_manifest_filename,  getpwnam('www-data').pw_uid, getpwnam('www-data').pw_gid)
                            i = i + 1
                     else:
                         break
                        
                
                #literals[OXDS['contact']] = request.POST['record_contact']
                #Save the contact details       
                person_or_role = request.POST['person_or_role'] 
                person_title=""
                if person_or_role == "is_role":
                    person_title = request.POST['record_title']
                else: 
                    person_title = request.POST['contact_firstname'] + '-' +request.POST['contact_middlename'] + '-' +request.POST['contact_lastname'] 
                    person[FOAF["givenName"]]=request.POST['contact_firstname']
                    person[FOAF["middleName"]]=request.POST['contact_middlename']   
                    if request.GET.has_key('contact_middlename_check'):
                     person[OXDS["DisplayEmail"]]=request.POST['contact_middlename_check']
                    person[FOAF["familyName"]]=request.POST['contact_lastname'] 
                       
                person[FOAF["mbox"]]=request.POST['contact_email']     
                person[OXDS['role']]=request.POST['contact_role']   
                
                member_of_oxford = request.POST['contact_mof'] 
                person[FOAF["Organization"]]=request.POST['contact_institution']
                if member_of_oxford == True:                            
                        person[OXDS["Faculty"]]=request.POST['contact_faculty']
                        person[OXDS["OxfordCollege"]]=request.POST['contact_oxfordcollege']
                        person[OXDS["scheme"]]=request.POST['contact_scheme']  
                        person[OXDS["AUTHOR_ID"]]=request.POST['contact_id']  
                else:
                    person[OXDS["Faculty"]]=request.POST['contact_faculty_text']
                                   
                             
                people_path = settings.get("main:granary.people_path")        
                people_manifest_filename = os.path.join(people_path, 'people.rdf')
                people_manifest = bind_namespaces(rdflib.ConjunctiveGraph())
                            
                try:
                    with open(people_manifest_filename, 'r') as f:
                        people_manifest.parse(f, base=people_manifest_filename)
                except IOError, e:
                    pass
                            
                if people_manifest.value(FOAF[person_title], None, None) == None:
                        people_manifest.add((FOAF[person_title], RDF.type, FOAF.Person))
                        for key, value in person.items():
                                people_manifest.add((FOAF[person_title], key, Literal(value)))
                                                         
                            
                with open(people_manifest_filename, 'w') as f:
                    people_manifest.serialize(f, 'better-pretty-xml', base=people_manifest_filename)
                os.chown(people_manifest_filename,  getpwnam('www-data').pw_uid, getpwnam('www-data').pw_gid)      
                
                #end of saving contact details
                
                          
                #literals[OXDS['isEmbargoed']] = 'False'
                if request.POST.has_key('data-format'):
                    literals[OXDS['isDigital']]=request.POST['data-format']               
                
                literals[OXDS['loc-format']]=request.POST['loc-format']
                
                if request.POST['loc-format'] =="URL":
                    resources[OXDS['DataLocation']]=request.POST['data_location']
                else:
                    literals[OXDS['DataLocation']]=request.POST['data_location']
                    
                if request.POST['doc-format'] =="URL":
                    resources[OXDS['methodology']]=request.POST['digital_publisher_doc']
                else:
                    literals[OXDS['methodology']]=request.POST['digital_publisher_doc']          

                literals[DCTERMS['publisher']]=request.POST['publisher']
                literals[DCTERMS['issued']]=request.POST['publication_year']          
                literals[OXDS['temporal_choice']]=request.POST['temporal_choice']    
                 
                if request.POST['temporal_choice'] == 'single_date':
                    literals[OXDS['dataTemporalCoverage']]=request.POST['single_temporal_date']
                if request.POST['temporal_choice'] == 'date_range':
                    literals[OXDS['dataCoverageStart']]=request.POST['start_date_range']
                    literals[OXDS['dataCoverageEnd']]=request.POST['end_date_range']
                
                literals[OXDS['data_collected_temporal_choice']]=request.POST['data_collected_temporal_choice']
                
                if request.POST['data_collected_temporal_choice'] == 'data_collected_single_date':
                    literals[OXDS['dataCollectedCoverage']]=request.POST['data_collected_single_temporal_date']
                if request.POST['data_collected_temporal_choice'] == 'data_collected_date_range':
                    literals[OXDS['dataCollectedStart']]=request.POST['data_collected_start_date_range']
                    literals[OXDS['dataCollectedEnd']]=request.POST['data_collected_end_date_range']
                
                literals[DCTERMS['Location']]=request.POST['geo_location']
                literals[GEO['lat']]=request.POST['lat']
                literals[GEO['lng']]=request.POST['lng']
 
               
                if literals[OXDS['isDigital']] == "yes":
                    literals[BIBO['doi']]=request.POST['digital_object_identifier']  
                    literals[DCTERMS['type']]=request.POST['digital_resource_type']      
                    literals[OXDS['Filesize']]=request.POST['digital_filesize']
                    literals[DCTERMS['format']]=request.POST['digital_format']
                    literals[OXDS['currentVersion']]=request.POST['digital_version']
                                       
                                       
                funded_research = request.POST['funded_research']
                literals[OXDS['funded_research']]=request.POST['funded_research']
                if funded_research == "yes":
                    funding_agencies = request.POST.getlist('funding_agency')                
                    literals[FUND['FundingBody']]=funding_agencies
                        
                    grant_numbers = request.POST.getlist('grant_number')                
                    literals[FUND['grantNumber']]=grant_numbers
                
                #    
                #if request.POST['dmp_loc'] =="URL":
                #    resources[OXDS['data_management_plan_location']]=request.POST['data_management_plan_location']
                #else:
                #    literals[OXDS['data_management_plan_location']]=request.POST['data_management_plan_location']     
 
                
                #context["publication_relationship_of_data_1"]=request.GET['publication_relationship_of_data_1']
                #context["related_publication_url_1"]=request.GET['related_publication_url_1']
                #context["dataset_relationship_of_data_1"]=request.GET['dataset_relationship_of_data_1']
                #context["dataset_related_url_1"]=request.GET['dataset_related_url_1']
                #context["deposit_data_file_upload"]=request.POST['deposit_data_file_upload']
                #context["deposit_data_embargo_options"]=request.POST['deposit_data_embargo_options']
                #context["deposit_data_embrago_release_date"]=request.POST['deposit_data_embrago_release_date']
                #context["deposit_data_embargo_options_type"]=request.POST['deposit_data_embargo_options_type']
                #context["deposit_data_embargo_reason"]=request.POST['deposit_data_embargo_reason']
                
                literals[DCTERMS['rights']]=request.POST['terms_and_conditions']
                #resources[OXDS['DataLocation']]=request.POST['data_location']
                
                            #prepared_licence - urls to licenses stored elsewhere
                            #select_a_licence - urls of licens selted fromt he select dropdown
                            #bespoke_licence - license pasted in as free text
                            #other_licence - eg: none ie. when not associated with any license               
                license = request.POST['license_radio']
                literals[OXDS['license_radio']]=license
                if license =="prepared_licence" or license == 'select_a_licence':
                    resources[DCTERMS['license']]=request.POST['data_standard_licence_URI']
                else :
                    literals[DCTERMS['license']]=request.POST['data_standard_licence_text']
                    
                if request.POST.has_key('embargo_options'): 
                    embargo_options = request.POST['embargo_options']
                # embargo_options_list = ['embargo_status_unknown','embargoed_indefinitely']
                
                
                literals[OXDS['embargoedUntil']]=request.POST['embargo_end_date']
                
                
                #context["embargo-options"]=request.GET['embargo-options']
                #context["subject_specific_metadata_file"]=request.GET['subject_specific_metadata_file']
                #context["xml_schema_type"]=request.GET['xml_schema_type']
                
                # Project RDF
                #projects_package = rdflib.URIRef(projects_path)
                                
                projects_path = settings.get("main:granary.projects_path")        
                projects_manifest_filename = os.path.join(projects_path, 'projects.rdf')
                projects_manifest = bind_namespaces(rdflib.ConjunctiveGraph())
#              
                try:
                    with open(projects_manifest_filename, 'r') as f:
                        projects_manifest.parse(f, base=projects_manifest_filename)
                except IOError, e:
                    pass
                
                
                for key, value in project.items():
                    # Will raise UniquenessError if >1 value returned, must be one or None
                    if projects_manifest.value(None, DCTERMS['title'], Literal(value)) == None:                        
                        projects_manifest.add((FUND[project[DCTERMS['title']]], key, Literal(value)))
                    
                with open(projects_manifest_filename, 'w') as f:
                    projects_manifest.serialize(f, 'better-pretty-xml', base=projects_manifest_filename)
                os.chown(projects_manifest_filename,  getpwnam('www-data').pw_uid, getpwnam('www-data').pw_gid)
                resources[FUND['project']] = FUND[project[DCTERMS['title']]]
                
                # Record Manifest RDF
                records_path = settings.get("main:granary.records_path")
                records_package = rdflib.URIRef(records_path)
                #manifest_name = 'df_manifest_'+literals[DCTERMS['title']] +'.rdf'
                df_manifest_name = 'df_manifest.rdf'
                manifest_filename = os.path.join(records_path, df_manifest_name)
                main_manifest_filename = os.path.join(records_path, 'manifest.rdf')
                manifest = bind_namespaces(rdflib.ConjunctiveGraph())
                #try:
                #    with open(manifest_filename, 'w') as f:
                #        manifest.parse(f, base=manifest_filename)
                #except IOError, e:
                #    pass
                
                #for x in list(literals.keys()):
                #    if literals[x] == "":
                #        del literals[x]
                
                keys_with_valuelist = [ DCTERMS['subject'],DCTERMS['keywords'], FUND['FundingBody'],FUND['grantNumber'] ]
                for key, values in literals.items():                    
                    if key in keys_with_valuelist:
                        for value in values:
                            manifest.add((subject, key, Literal(value)))
                    else:
                        manifest.add((subject, key, Literal(values)))
                        
                for key, res_uri in resources.items():
                    manifest.add((subject, key, res_uri))
                    
                with open(manifest_filename, 'w') as f:
                    manifest.serialize(f, 'better-pretty-xml', base=manifest_filename)
                                 
#                try:
#                    with open(main_manifest_filename, 'w') as f:
#                        manifest.parse(f, base=main_manifest_filename)
               
#                except IOError, e:
#                    pass
                                
                user_name = settings.get("main:granary.uri_root_name") 
                password = settings.get("main:granary.uri_root_pass") 
                datastore = HTTPRequest(endpointhost=settings.get("main:granary.host"))       
                datastore.setRequestUserPass(endpointuser=user_name, endpointpass=password)
             
                #(reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata([], [])
                # Create a dataset
                #(resp,respdata) = datastore.doHTTP_POST(reqdata, reqtype, resource="/DataFinder/datasets/" + identifier)

                #Submit the df_manefest as a file
                fields=[]
                df_manifest = open(manifest_filename).read()               
                files =  [("file", df_manifest_name, df_manifest, "application/rdf+xml")]            
                (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files)                
                (resp,respdata) = datastore.doHTTP_POST(reqdata, reqtype, resource="/DataFinder/datasets/" + identifier +"/")
                
                silo = settings.get("main:mainsilo")
                #solr_conn, b = settings.getSolrConnection()
                b = BroadcastToRedis('localhost', 'silochanges')
                b.creation(silo, identifier, ident=request.session['DF_USER_SSO_ID'])
                
                #Submit the main manifest file which as the see also
                fields=[]       

                main_manifest = open(main_manifest_filename).read()
                files =  [("file", "manifest.rdf", main_manifest, "application/rdf+xml")]            
                (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files)                
                (resp,respdata) = datastore.doHTTP_POST(reqdata, reqtype, resource="/DataFinder/datasets/" + identifier +"/")

                os.chown(manifest_filename, getpwnam('www-data').pw_uid, getpwnam('www-data').pw_gid)
                return render_to_response('contribute.html', context, context_instance=RequestContext(request))