コード例 #1
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
 def index(self):
     """Generates the list of vocabs in the browse page."""
     vocabs = os.listdir(ag.vocabulariesdir)
     c.ox_vocab_list = {}
     c.ref_vocab_list = {}
     mediators_dir_name = ag.mediatorsdir.strip('/').split('/')[-1]
     reference_vocabs = get_ref_vocabs().keys()
     for v in vocabs:
         vocab_dict = {}
         if v.startswith(
                 '.') or v == mediators_dir_name or v == os.path.split(
                     ag.vocabulariesref)[1]:
             continue
         #Get the list of files
         files = get_vocab_files(v)
         if not files:
             continue
         description = {}
         for f, vals in files.iteritems():
             if vals['format'] == 'application/rdf+xml':
                 description = get_vocab_description(vals['path'], v)
         vocab_dict = description
         vocab_dict['files'] = files
         vocab_dict['mediators'] = get_vocab_mediator(v)
         properties = get_vocab_properties(v)
         vocab_dict['uri'] = properties['uri']
         vocab_dict['pref_uri'] = properties['preferredNamespaceUri']
         vocab_dict['pref_prefix'] = properties['preferredNamespacePrefix']
         if str(properties['uri']) in reference_vocabs:
             c.ref_vocab_list[v] = vocab_dict
         else:
             c.ox_vocab_list[v] = vocab_dict
     return render('/browse.html')
コード例 #2
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
    def publish(self):
        identity = request.environ.get("repoze.who.identity")
        if identity:
            #Get list of vocabularies created by userid
            c.userid = identity['repoze.who.userid']
            c.user_det = get_mediator_details(c.userid)
            vocabs = get_mediator_vocabs(c.userid)
            #Get status of vocab - is rdf, ready to convert to html, new rdf check, convert to html, html check
            c.vocab_list = {}

            for k, v in vocabs.iteritems():
                files = get_vocab_files(k)
                description = {}
                for f, vals in files.iteritems():
                    if vals['format'] == 'application/rdf+xml':
                        description = get_vocab_description(vals['path'], k)
                msgs = get_vocab_editorial_note(k)
                c.vocab_list[k] = description
                c.vocab_list[k]['files'] = files
                c.vocab_list[k]['uri'] = v[0]
                c.vocab_list[k]['svn'] = v[1]
                c.vocab_list[k]['note'] = msgs
            return render('/publish.html')
        else:
            session[
                'login_flash'] = "Please login to view vocabularies published and managed by you and to upload new vocabularies"
            session.save()
            destination = "/login?came_from=publish"
            return redirect(destination, code=303)
コード例 #3
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
    def publish(self):
        identity = request.environ.get("repoze.who.identity")
        if identity:
            #Get list of vocabularies created by userid
            c.userid = identity['repoze.who.userid']
            c.user_det = get_mediator_details(c.userid)
            vocabs = get_mediator_vocabs(c.userid)
            #Get status of vocab - is rdf, ready to convert to html, new rdf check, convert to html, html check
            c.vocab_list = {}

            for k, v in vocabs.iteritems():
                files = get_vocab_files(k)
                description = {}
                for f, vals in files.iteritems():
                    if vals['format'] == 'application/rdf+xml':
                        description = get_vocab_description(vals['path'], k)
                msgs = get_vocab_editorial_note(k)
                c.vocab_list[k] = description
                c.vocab_list[k]['files'] = files
                c.vocab_list[k]['uri'] = v[0]
                c.vocab_list[k]['svn'] = v[1]
                c.vocab_list[k]['note'] = msgs
            return render('/publish.html')
        else:
            session['login_flash'] = "Please login to view vocabularies published and managed by you and to upload new vocabularies"
            session.save()
            destination = "/login?came_from=publish"
            return redirect(destination, code=303)
コード例 #4
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
 def index(self):
     """Generates the list of vocabs in the browse page."""
     vocabs =  os.listdir(ag.vocabulariesdir)
     c.ox_vocab_list = {}
     c.ref_vocab_list = {}
     mediators_dir_name = ag.mediatorsdir.strip('/').split('/')[-1]
     reference_vocabs = get_ref_vocabs().keys()
     for v in vocabs:
         vocab_dict = {}
         if v.startswith('.') or v == mediators_dir_name or v == os.path.split(ag.vocabulariesref)[1]:
             continue
         #Get the list of files
         files = get_vocab_files(v)
         if not files:
             continue
         description = {}
         for f, vals in files.iteritems():
             if vals['format'] == 'application/rdf+xml':
                 description = get_vocab_description(vals['path'], v)
         vocab_dict = description
         vocab_dict['files'] = files
         vocab_dict['mediators'] = get_vocab_mediator(v)
         properties = get_vocab_properties(v)
         vocab_dict['uri'] = properties['uri']
         vocab_dict['pref_uri'] = properties['preferredNamespaceUri']
         vocab_dict['pref_prefix'] = properties['preferredNamespacePrefix']
         if str(properties['uri']) in reference_vocabs:
             c.ref_vocab_list[v] = vocab_dict
         else:
             c.ox_vocab_list[v] = vocab_dict
     return render('/browse.html')
コード例 #5
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
 def render_vocab_file(self, vocab, filename):
     """Render the file for vocab"""
     files = get_vocab_files(vocab)
     if not files:
         abort(404)
     for f, v in files.iteritems():
         if v['name'] == filename or f == 'http://vocab.ox.ac.uk/%s/%s'%(vocab, filename):
             if v['format'].lower() == 'text/html':
                 c.format = v['format']
                 c.vocabfile = v['path'].replace('/opt', '')
                 return render('/vocab.html')
             elif v['format'].lower() in ['application/rdf+xml', 'text/xml', "text/rdf+n3", "application/x-turtle", \
                                          "text/rdf+ntriples", "text/rdf+nt", "text/plain"]:
                 response.content_type = '%s; charset="UTF-8"'%str(v['format'])
                 response.status_int = 200
                 response.status = "200 OK"
                 f = codecs.open(v['path'], 'r', 'utf-8')
                 return_str = f.read()
                 f.close()
                 return return_str
             else:
                 response.content_type = '%s; charset="utf-8"'%str(v['format'])
                 response.status_int = 200
                 response.status = "200 OK"
                 if os.path.isfile(v['path']):
                     fileserve_app = FileApp(v['path'])
                     return fileserve_app(request.environ, self.start_response)
                 else:
                     session['browse_flash'] = "Could not find the file %s for %s"%(filename, vocab)
                     session.save()
                     return redirect(url(controller='vocabs', action='index'), code=303)
     session['browse_flash'] = "Could not find the file %s for %s"%(filename, vocab)
     session.save()
     return redirect(url(controller='vocabs', action='index'), code=303)
コード例 #6
0
ファイル: account.py プロジェクト: anusharanganathan/Vocab-ox
 def login(self):
     c.userid = None
     c.login_counter = request.environ['repoze.who.logins']
     if c.login_counter > 0:
         session['login_flash'] = """Wrong credentials. Have you registered? <a href="register">Register</a>"""
         session.save()
     c.came_from = request.params.get("came_from") or "/"
     return render('/login.html')
コード例 #7
0
ファイル: account.py プロジェクト: anusharanganathan/Vocab-ox
 def login(self):
     c.userid = None
     c.login_counter = request.environ['repoze.who.logins']
     if c.login_counter > 0:
         session[
             'login_flash'] = """Wrong credentials. Have you registered? <a href="register">Register</a>"""
         session.save()
     c.came_from = request.params.get("came_from") or "/"
     return render('/login.html')
コード例 #8
0
ファイル: account.py プロジェクト: anusharanganathan/Vocab-ox
 def register(self):
     params = request.POST
     if 'firstname' in params and params['firstname'] and \
         'lastname' in params and params['lastname'] and \
         'email' in params and params['email'] and \
         'username' in params and params['username'] and \
         'password' in params and params['password']:
         # Check if user id exists. Write new user into passwd file
         for entry in ag.passwdfile.entries:
             if entry[0] == params['username']:
                 c.message= "This userid exists"
                 return render('/register.html')
         ag.passwdfile.update(params['username'], params['password'])
         ag.passwdfile.save()
         #Write user metadata and save the rdf file
         add_mediator(params)
         session['login_flash'] = "%s you have been registered!"%params['username']
         session.save()  
         return redirect('login', code=303)
     return render('/register.html')
コード例 #9
0
 def document(self):
     """Render the error document"""
     request = self._py_object.request
     resp = request.environ.get('pylons.original_response')
     content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
     page = error_document_template % \
         dict(prefix=request.environ.get('SCRIPT_NAME', ''),
              code=cgi.escape(request.GET.get('code', str(resp.status_int))),
              message=content)
     #return page
     return render('/404.html')
コード例 #10
0
ファイル: account.py プロジェクト: anusharanganathan/Vocab-ox
 def register(self):
     params = request.POST
     if 'firstname' in params and params['firstname'] and \
         'lastname' in params and params['lastname'] and \
         'email' in params and params['email'] and \
         'username' in params and params['username'] and \
         'password' in params and params['password']:
         # Check if user id exists. Write new user into passwd file
         for entry in ag.passwdfile.entries:
             if entry[0] == params['username']:
                 c.message = "This userid exists"
                 return render('/register.html')
         ag.passwdfile.update(params['username'], params['password'])
         ag.passwdfile.save()
         #Write user metadata and save the rdf file
         add_mediator(params)
         session['login_flash'] = "%s you have been registered!" % params[
             'username']
         session.save()
         return redirect('login', code=303)
     return render('/register.html')
コード例 #11
0
ファイル: account.py プロジェクト: anusharanganathan/Vocab-ox
 def update(self):
     identity = request.environ.get("repoze.who.identity")
     if not identity:
         came_from = "/update"
         session['login_flash'] = "Please login to update your details"
         session.save()
         destination = "/login?came_from=%s" % came_from
         return redirect(destination, code=303)
     userid = identity['repoze.who.userid']
     #if not (identity['repoze.who.userid'] == userid):
     #    session['browse_flash'] = "You are not authorized to change the registration details for %s"%userid
     #    session.save()
     #    return redirect(url(controller='vocabs', action='index'), code=303)
     params = request.POST
     if not ('firstname' in params and params['firstname']) and \
        not ('lastname' in params and params['lastname']) and \
        not ('email' in params and params['email']) and \
        not ('dept' in params and params['dept']) and \
        not ('password' in params and params['password']):
         c.userid = userid
         c.user_det = get_mediator_details(c.userid)
         return render('/update.html')
     if not ('username' in params
             and params['username']) or not (params['username'] == userid):
         c.message = "The userid on record did not match the one sent"
         c.userid = userid
         c.user_det = get_mediator_details(c.userid)
         return render('/update.html')
     if 'username' in params and params['username'] and \
        'password' in params and params['password']:
         ag.passwdfile.update(params['username'], params['password'])
         ag.passwdfile.save()
     #Write user metadata and save the rdf file
     update_mediator(params)
     c.message = "Your details have been updated!"
     c.userid = userid
     c.user_det = get_mediator_details(c.userid)
     return render('/update.html')
コード例 #12
0
ファイル: account.py プロジェクト: anusharanganathan/Vocab-ox
 def update(self):
     identity = request.environ.get("repoze.who.identity")
     if not identity:
         came_from = "/update"
         session['login_flash'] = "Please login to update your details"
         session.save()
         destination = "/login?came_from=%s"%came_from
         return redirect(destination, code=303)
     userid = identity['repoze.who.userid']
     #if not (identity['repoze.who.userid'] == userid):
     #    session['browse_flash'] = "You are not authorized to change the registration details for %s"%userid
     #    session.save()
     #    return redirect(url(controller='vocabs', action='index'), code=303)
     params = request.POST
     if not ('firstname' in params and params['firstname']) and \
        not ('lastname' in params and params['lastname']) and \
        not ('email' in params and params['email']) and \
        not ('dept' in params and params['dept']) and \
        not ('password' in params and params['password']):
        c.userid = userid
        c.user_det = get_mediator_details(c.userid)
        return render('/update.html')
     if not ('username' in params and params['username']) or not (params['username'] == userid):
        c.message = "The userid on record did not match the one sent"
        c.userid = userid
        c.user_det = get_mediator_details(c.userid)
        return render('/update.html')
     if 'username' in params and params['username'] and \
        'password' in params and params['password']:
         ag.passwdfile.update(params['username'], params['password'])
         ag.passwdfile.save()
     #Write user metadata and save the rdf file
     update_mediator(params)
     c.message = "Your details have been updated!"
     c.userid = userid
     c.user_det = get_mediator_details(c.userid)
     return render('/update.html')
コード例 #13
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
 def owner(self, owner_uuid):
     c.user_det = get_mediator_details(owner_uuid)
     c.vocab_list = {}
     if 'userid' in c.user_det and c.user_det['userid']:
         c.userid = c.user_det['userid']
         vocabs = get_mediator_vocabs(c.userid)
         #Get status of vocab - is rdf, ready to convert to html, new rdf check, convert to html, html check
         for k, v in vocabs.iteritems():
             files = get_vocab_files(k)
             description = {}
             for f, vals in files.iteritems():
                 if vals['format'] == 'application/rdf+xml':
                     description = get_vocab_description(vals['path'], k)
             c.vocab_list[k] = description
             c.vocab_list[k]['files'] = files
     return render ('/owner.html')
コード例 #14
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
 def owner(self, owner_uuid):
     c.user_det = get_mediator_details(owner_uuid)
     c.vocab_list = {}
     if 'userid' in c.user_det and c.user_det['userid']:
         c.userid = c.user_det['userid']
         vocabs = get_mediator_vocabs(c.userid)
         #Get status of vocab - is rdf, ready to convert to html, new rdf check, convert to html, html check
         for k, v in vocabs.iteritems():
             files = get_vocab_files(k)
             description = {}
             for f, vals in files.iteritems():
                 if vals['format'] == 'application/rdf+xml':
                     description = get_vocab_description(vals['path'], k)
             c.vocab_list[k] = description
             c.vocab_list[k]['files'] = files
     return render('/owner.html')
コード例 #15
0
ファイル: account.py プロジェクト: anusharanganathan/Vocab-ox
 def logout(self):
     c.userid = None
     c.message = "We hope to see you soon!"
     #display_message("We hope to see you soon!", status="success")
     came_from = request.params.get('came_from', '') or "/"
     if session.has_key('user_name'):
         del session['user_name']
     if session.has_key('user_uri'):
         del session['user_uri']
     if session.has_key('user_id'):
         del session['user_id']
     if session.has_key('user_dept'):
         del session['user_dept']
     if session.has_key('user_email'):
         del session['user_email']
     session.save()
     #return redirect(came_from, code=303)
     return render('/logout.html')
コード例 #16
0
ファイル: account.py プロジェクト: anusharanganathan/Vocab-ox
 def logout(self):
     c.userid = None
     c.message = "We hope to see you soon!"
     #display_message("We hope to see you soon!", status="success")
     came_from = request.params.get('came_from', '') or "/"
     if session.has_key('user_name'):
         del session['user_name']
     if session.has_key('user_uri'):
         del session['user_uri']
     if session.has_key('user_id'):
         del session['user_id']
     if session.has_key('user_dept'):
         del session['user_dept']
     if session.has_key('user_email'):
         del session['user_email']
     session.save()
     #return redirect(came_from, code=303)
     return render('/logout.html')
コード例 #17
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
 def render_vocab_file(self, vocab, filename):
     """Render the file for vocab"""
     files = get_vocab_files(vocab)
     if not files:
         abort(404)
     for f, v in files.iteritems():
         if v['name'] == filename or f == 'http://vocab.ox.ac.uk/%s/%s' % (
                 vocab, filename):
             if v['format'].lower() == 'text/html':
                 c.format = v['format']
                 c.vocabfile = v['path'].replace('/opt', '')
                 return render('/vocab.html')
             elif v['format'].lower() in ['application/rdf+xml', 'text/xml', "text/rdf+n3", "application/x-turtle", \
                                          "text/rdf+ntriples", "text/rdf+nt", "text/plain"]:
                 response.content_type = '%s; charset="UTF-8"' % str(
                     v['format'])
                 response.status_int = 200
                 response.status = "200 OK"
                 f = codecs.open(v['path'], 'r', 'utf-8')
                 return_str = f.read()
                 f.close()
                 return return_str
             else:
                 response.content_type = '%s; charset="utf-8"' % str(
                     v['format'])
                 response.status_int = 200
                 response.status = "200 OK"
                 if os.path.isfile(v['path']):
                     fileserve_app = FileApp(v['path'])
                     return fileserve_app(request.environ,
                                          self.start_response)
                 else:
                     session[
                         'browse_flash'] = "Could not find the file %s for %s" % (
                             filename, vocab)
                     session.save()
                     return redirect(url(controller='vocabs',
                                         action='index'),
                                     code=303)
     session['browse_flash'] = "Could not find the file %s for %s" % (
         filename, vocab)
     session.save()
     return redirect(url(controller='vocabs', action='index'), code=303)
コード例 #18
0
ファイル: admin.py プロジェクト: anusharanganathan/Vocab-ox
        else:
            message = []

        #Create the rdf status file for the vocab and add the vocab in the mediators rdf file
        create_vocab_statusfile(userid, c.vocabprefix, vocabfile, c.base_URI, using_uuid=using_uuid, refvocab=refvocab)

        #Commit svn changes
        (status1, msg1) = svn_add(vocabdir, "New vocabulary added by user %s"%userid)
        if not status1:
            message.append("""Error committing to SVN: %s"""%msg1)

        (status2, msg2) = svn_commit([vocabdir, mediatorfile], "New vocabulary %s added by user %s"%(c.vocabprefix, userid))
        if not status2:
            message.append("""Error committing to SVN: %s"""%msg2)
        c.message = "<br />".join(message)
        return render('rename.html')

    def rename(self, prefix):
        identity = request.environ.get("repoze.who.identity")
        if not identity:
            session['login_flash'] = "Please login to modify vocabularies published and managed by you"
            session.save()
            destination = "/login?came_from=rename/%s"%prefix
            return redirect(destination, code=303)
        
        #Check if userid has permissions for this vocab
        userid = identity['repoze.who.userid']
        mediatorfile = os.path.join(ag.mediatorsdir, '%s.rdf'%userid)
        vocablist = get_mediator_vocabs(userid)
        if vocablist and not prefix in vocablist.keys():
            session['welcome_flash'] = "You are not authorized to make any changes to %s"%prefix
コード例 #19
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
 def render_external_vocab(self, vocab_name):
     """Render the page for each vocab"""
     #redirect(url(controller='vocabs', action='index'), code=303)
     return render('/vocab.html')
コード例 #20
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
 def render_vocab(self, vocab):
     """Render the page for each vocab"""
     c.vocab = vocab
     files = get_vocab_files(vocab)
     if not files:
         session['browse_flash'] = "Could not find any file for %s"%vocab
         session.save()
         return redirect(url(controller='vocabs', action='index'), code=303)
     formats = []
     for f, v in files.iteritems():
         if not v['format'].lower() in formats:
             formats.append(v['format'].lower())
     # conneg return
     accept_list = None
     if 'HTTP_ACCEPT' in request.environ:
         try:
             accept_list = conneg_parse(request.environ['HTTP_ACCEPT'])
         except:
             accept_list= [MT("text", "html")]
     if not accept_list:
         accept_list= [MT("text", "html")]
     mimetype = accept_list.pop()
     while(mimetype):
         if str(mimetype).lower() in formats:
             if str(mimetype).lower() in ['text/html', "text/xhtml"]:
                 for f, v in files.iteritems():
                     if v['format'].lower() == 'text/html':
                         c.format = v['format']
                         c.vocabfile = v['path'].replace('/opt', '')
                         return render('/vocab.html')
             elif str(mimetype).lower() in ['application/rdf+xml', "text/xml", "text/rdf+n3", "application/x-turtle", \
             "text/rdf+ntriples", "text/rdf+nt", "text/plain"]:
                 for f, v in files.iteritems():
                     if v['format'].lower() in ['application/rdf+xml', 'text/xml', "text/rdf+n3", "application/x-turtle", \
                     "text/rdf+ntriples", "text/rdf+nt", "text/plain"]:
                         response.content_type = '%s; charset="UTF-8"'%str(mimetype)
                         response.status_int = 200
                         response.status = "200 OK"
                         f = codecs.open(v['path'], 'r', 'utf-8')
                         return_str = f.read()
                         f.close()
                         return return_str
             else:
                 response.content_type = '%s; charset="UTF-8"'%str(mimetype)
                 response.status_int = 200
                 response.status = "200 OK"
                 for f, v in files.iteritems():
                     if v['format'].lower() == str(mimetype).lower() and os.path.isfile(v['path']):
                         fileserve_app = FileApp(v['path'])
                         return fileserve_app(request.environ, self.start_response)
         try:
             mimetype = accept_list.pop()
         except IndexError:
             mimetype = None
     #Whoops nothing satisfies - return one of the formats available - 1. text/html, 2. other
     if 'text/html' in formats:
         for f, v in files.iteritems():
             if v['format'].lower() == 'text/html':
                 c.format = v['format']
                 c.vocabfile = v['path'].replace('/opt', '')
                 return render('/vocab.html')
     elif 'application/rdf+xml' in formats or "text/xml" in formats or "text/rdf+n3" in formats or "text/plain" in formats or \
          "application/x-turtle" in formats or "text/rdf+ntriples" in formats or "text/rdf+nt" in formats:
         for f, v in files.iteritems():
             if v['format'].lower() in ['application/rdf+xml', "text/xml", "text/rdf+n3", "application/x-turtle", \
                                     "text/rdf+ntriples", "text/rdf+nt", "text/plain"]:
                 response.content_type = '%s; charset="UTF-8"'%str(v['format'])
                 response.status_int = 200
                 response.status = "200 OK"
                 f = codecs.open(v['path'], 'r', 'utf-8')
                 return_str = f.read()
                 f.close()
                 return return_str
     else:
         for format in formats:
             response.content_type = '%s; charset="UTF-8"'%str(format)
             response.status_int = 200
             response.status = "200 OK"
             for f, v in files.iteritems():
                 if v['format'].lower() == format and os.path.isfile(v['path']):
                     fileserve_app = FileApp(v['path'])
                     return fileserve_app(request.environ, self.start_response)
     session['browse_flash'] = "Could not find any file for %s"%vocab
     session.save()
     return redirect(url(controller='vocabs', action='index'), code=303)
コード例 #21
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
 def render_external_vocab(self, vocab_name):
     """Render the page for each vocab"""
     #redirect(url(controller='vocabs', action='index'), code=303)
     return render('/vocab.html')
コード例 #22
0
 def about(self):
     """Render the about page"""
     return render('/about.html')
コード例 #23
0
 def index(self):
     """Render the index page"""
     return render('/index.html')
コード例 #24
0
 def privacy(self):
     """Render the privacy page"""
     return render('/privacy.html')
コード例 #25
0
    def rename(self, prefix):
        identity = request.environ.get("repoze.who.identity")
        if not identity:
            session[
                'login_flash'] = "Please login to modify vocabularies published and managed by you"
            session.save()
            destination = "/login?came_from=rename/%s" % prefix
            return redirect(destination, code=303)

        #Check if userid has permissions for this vocab
        userid = identity['repoze.who.userid']
        mediatorfile = os.path.join(ag.mediatorsdir, '%s.rdf' % userid)
        vocablist = get_mediator_vocabs(userid)
        if vocablist and not prefix in vocablist.keys():
            session[
                'welcome_flash'] = "You are not authorized to make any changes to %s" % prefix
            session.save()
            return redirect(url(controller='vocabs', action='publish'),
                            code=303)

        vocabs = os.listdir(ag.vocabulariesdir)
        mediators_dir_name = ag.mediatorsdir.strip('/').split('/')[-1]
        if not prefix in vocabs:
            session['welcome_flash'] = "Vocab %s does not exist" % prefix
            session.save()
            return redirect(url(controller='vocabs', action='publish'),
                            code=303)

        params = request.params
        c.vocabprefix = None
        c.base_URI = None
        if params.has_key('ns_prefix') and params['ns_prefix']:
            c.vocabprefix = params['ns_prefix']
        if params.has_key('base_URI') and params['base_URI']:
            c.base_URI = params['base_URI']
            if c.base_URI:
                c.base_URI = c.base_URI.strip()
                if (c.base_URI[-1] != "/" and c.base_URI[-1] != "#"):
                    c.base_URI += "#"
        if not c.vocabprefix or not c.base_URI:
            c.message = 'Enter the preferred namespace prefix and namespace URI for the vocab'
            properties = get_vocab_properties(prefix)
            c.base_URI = properties['preferredNamespaceUri']
            c.vocabprefix = prefix
            return render('rename.html')
        vocabdir = "%s/%s" % (ag.vocabulariesdir, prefix)
        newvocabdir = "%s/%s" % (ag.vocabulariesdir, c.vocabprefix)
        if c.vocabprefix != prefix:
            if os.path.isdir(newvocabdir):
                message = []
                message.append(
                    """A vocabulary already exists with the namespace prefix <a href="http://vocab.ox.ac.uk/%s">%s</a>"""
                    % (c.vocabprefix, c.vocabprefix))
                message.append(
                    "Please select another preferred namespace prefix")
                c.message = "<br />".join(message)
                properties = get_vocab_properties(prefix)
                c.base_URI = properties['preferredNamespaceUri']
                c.vocabprefix = prefix
                return render('rename.html')

            os.rename(vocabdir, newvocabdir)

            #Change the rdf status file for the vocab and the mediator file
            update_vocab_uri_in_statusfile(userid, prefix, c.vocabprefix,
                                           vocabdir, newvocabdir)
        vocab_uri = "http://vocab.ox.ac.uk/%s" % c.vocabprefix
        del_status(c.vocabprefix, vocab_uri, 'skos:editorialNote',
                   vocab_editorial_descriptions[0])
        del_status(c.vocabprefix, vocab_uri, 'vann:preferredNamespaceUri',
                   None)
        del_status(c.vocabprefix, vocab_uri, 'vann:preferredNamespacePrefix',
                   None)
        add_status(c.vocabprefix, vocab_uri, 'vann:preferredNamespaceUri',
                   c.base_URI)
        add_status(c.vocabprefix, vocab_uri, 'vann:preferredNamespacePrefix',
                   c.vocabprefix)

        message = [
            "Successfully added the properties and changed the preferred namespace prefix from %s to %s"
            % (prefix, c.vocabprefix)
        ]

        #Commit svn changes
        (status1,
         msg1) = svn_add(newvocabdir,
                         "Renamed vocabulary. Added %s" % c.vocabprefix)
        if not status1:
            message.append("""Error committing to SVN: %s""" % msg1)

        #(status2, msg2) = svn_remove(vocabdir, "Removed vocabulary. removed %s"%prefix)
        #if not status2:
        #    message.append("""Error committing to SVN: %s"""%msg2)

        (status2, msg2) = svn_commit([newvocabdir, mediatorfile],
                                     "New vocabulary %s added by user %s" %
                                     (c.vocabprefix, userid))
        if not status2:
            message.append("""Error committing to SVN: %s""" % msg2)

        session['welcome_flash'] = "<br />".join(message)
        session.save()
        return redirect(url(controller='vocabs', action='publish'), code=303)
コード例 #26
0
ファイル: admin.py プロジェクト: anusharanganathan/Vocab-ox
    def rename(self, prefix):
        identity = request.environ.get("repoze.who.identity")
        if not identity:
            session['login_flash'] = "Please login to modify vocabularies published and managed by you"
            session.save()
            destination = "/login?came_from=rename/%s"%prefix
            return redirect(destination, code=303)
        
        #Check if userid has permissions for this vocab
        userid = identity['repoze.who.userid']
        mediatorfile = os.path.join(ag.mediatorsdir, '%s.rdf'%userid)
        vocablist = get_mediator_vocabs(userid)
        if vocablist and not prefix in vocablist.keys():
            session['welcome_flash'] = "You are not authorized to make any changes to %s"%prefix
            session.save()
            return redirect(url(controller='vocabs', action='publish'), code=303)

        vocabs =  os.listdir(ag.vocabulariesdir)
        mediators_dir_name = ag.mediatorsdir.strip('/').split('/')[-1]
        if not prefix in vocabs:
            session['welcome_flash'] = "Vocab %s does not exist"%prefix
            session.save()
            return redirect(url(controller='vocabs', action='publish'), code=303)
        
        params = request.params
        c.vocabprefix = None
        c.base_URI = None
        if params.has_key('ns_prefix') and params['ns_prefix']:
            c.vocabprefix = params['ns_prefix']
        if params.has_key('base_URI') and params['base_URI']:
            c.base_URI = params['base_URI']
            if c.base_URI:
                c.base_URI = c.base_URI.strip()
                if (c.base_URI[-1]!="/" and c.base_URI[-1]!="#"):
                    c.base_URI += "#"
        if not c.vocabprefix or not c.base_URI:    
            c.message = 'Enter the preferred namespace prefix and namespace URI for the vocab'
            properties = get_vocab_properties(prefix)
            c.base_URI = properties['preferredNamespaceUri']
            c.vocabprefix = prefix
            return render('rename.html')
        vocabdir = "%s/%s"%(ag.vocabulariesdir, prefix)
        newvocabdir = "%s/%s"%(ag.vocabulariesdir, c.vocabprefix)
        if c.vocabprefix != prefix:
            if os.path.isdir(newvocabdir):
                message = []
                message.append("""A vocabulary already exists with the namespace prefix <a href="http://vocab.ox.ac.uk/%s">%s</a>"""%(c.vocabprefix, c.vocabprefix))
                message.append("Please select another preferred namespace prefix")
                c.message = "<br />".join(message)
                properties = get_vocab_properties(prefix)
                c.base_URI = properties['preferredNamespaceUri']
                c.vocabprefix = prefix
                return render('rename.html')
        
            os.rename(vocabdir, newvocabdir)

            #Change the rdf status file for the vocab and the mediator file
            update_vocab_uri_in_statusfile(userid, prefix, c.vocabprefix, vocabdir, newvocabdir)
        vocab_uri = "http://vocab.ox.ac.uk/%s"%c.vocabprefix
        del_status(c.vocabprefix, vocab_uri, 'skos:editorialNote', vocab_editorial_descriptions[0])
        del_status(c.vocabprefix, vocab_uri, 'vann:preferredNamespaceUri', None)
        del_status(c.vocabprefix, vocab_uri, 'vann:preferredNamespacePrefix', None)
        add_status(c.vocabprefix, vocab_uri, 'vann:preferredNamespaceUri', c.base_URI)
        add_status(c.vocabprefix, vocab_uri, 'vann:preferredNamespacePrefix', c.vocabprefix)
 
        message = ["Successfully added the properties and changed the preferred namespace prefix from %s to %s"%(prefix, c.vocabprefix)] 

        #Commit svn changes
        (status1, msg1) = svn_add(newvocabdir, "Renamed vocabulary. Added %s"%c.vocabprefix)
        if not status1:
            message.append("""Error committing to SVN: %s"""%msg1)

        #(status2, msg2) = svn_remove(vocabdir, "Removed vocabulary. removed %s"%prefix)
        #if not status2:
        #    message.append("""Error committing to SVN: %s"""%msg2)
       
        (status2, msg2) = svn_commit([newvocabdir, mediatorfile], "New vocabulary %s added by user %s"%(c.vocabprefix, userid))
        if not status2:
            message.append("""Error committing to SVN: %s"""%msg2)

        session['welcome_flash'] = "<br />".join(message)
        session.save()
        return redirect(url(controller='vocabs', action='publish'), code=303)
コード例 #27
0
 def help(self):
     """Render the help (guidelines + faq) page"""
     return render('/help.html')
コード例 #28
0
 def contact(self):
     """Render the contact page"""
     return render('/contact.html')
コード例 #29
0
ファイル: vocabs.py プロジェクト: anusharanganathan/Vocab-ox
 def render_vocab(self, vocab):
     """Render the page for each vocab"""
     c.vocab = vocab
     files = get_vocab_files(vocab)
     if not files:
         session['browse_flash'] = "Could not find any file for %s" % vocab
         session.save()
         return redirect(url(controller='vocabs', action='index'), code=303)
     formats = []
     for f, v in files.iteritems():
         if not v['format'].lower() in formats:
             formats.append(v['format'].lower())
     # conneg return
     accept_list = None
     if 'HTTP_ACCEPT' in request.environ:
         try:
             accept_list = conneg_parse(request.environ['HTTP_ACCEPT'])
         except:
             accept_list = [MT("text", "html")]
     if not accept_list:
         accept_list = [MT("text", "html")]
     mimetype = accept_list.pop()
     while (mimetype):
         if str(mimetype).lower() in formats:
             if str(mimetype).lower() in ['text/html', "text/xhtml"]:
                 for f, v in files.iteritems():
                     if v['format'].lower() == 'text/html':
                         c.format = v['format']
                         c.vocabfile = v['path'].replace('/opt', '')
                         return render('/vocab.html')
             elif str(mimetype).lower() in ['application/rdf+xml', "text/xml", "text/rdf+n3", "application/x-turtle", \
             "text/rdf+ntriples", "text/rdf+nt", "text/plain"]:
                 for f, v in files.iteritems():
                     if v['format'].lower() in ['application/rdf+xml', 'text/xml', "text/rdf+n3", "application/x-turtle", \
                     "text/rdf+ntriples", "text/rdf+nt", "text/plain"]:
                         response.content_type = '%s; charset="UTF-8"' % str(
                             mimetype)
                         response.status_int = 200
                         response.status = "200 OK"
                         f = codecs.open(v['path'], 'r', 'utf-8')
                         return_str = f.read()
                         f.close()
                         return return_str
             else:
                 response.content_type = '%s; charset="UTF-8"' % str(
                     mimetype)
                 response.status_int = 200
                 response.status = "200 OK"
                 for f, v in files.iteritems():
                     if v['format'].lower() == str(mimetype).lower(
                     ) and os.path.isfile(v['path']):
                         fileserve_app = FileApp(v['path'])
                         return fileserve_app(request.environ,
                                              self.start_response)
         try:
             mimetype = accept_list.pop()
         except IndexError:
             mimetype = None
     #Whoops nothing satisfies - return one of the formats available - 1. text/html, 2. other
     if 'text/html' in formats:
         for f, v in files.iteritems():
             if v['format'].lower() == 'text/html':
                 c.format = v['format']
                 c.vocabfile = v['path'].replace('/opt', '')
                 return render('/vocab.html')
     elif 'application/rdf+xml' in formats or "text/xml" in formats or "text/rdf+n3" in formats or "text/plain" in formats or \
          "application/x-turtle" in formats or "text/rdf+ntriples" in formats or "text/rdf+nt" in formats:
         for f, v in files.iteritems():
             if v['format'].lower() in ['application/rdf+xml', "text/xml", "text/rdf+n3", "application/x-turtle", \
                                     "text/rdf+ntriples", "text/rdf+nt", "text/plain"]:
                 response.content_type = '%s; charset="UTF-8"' % str(
                     v['format'])
                 response.status_int = 200
                 response.status = "200 OK"
                 f = codecs.open(v['path'], 'r', 'utf-8')
                 return_str = f.read()
                 f.close()
                 return return_str
     else:
         for format in formats:
             response.content_type = '%s; charset="UTF-8"' % str(format)
             response.status_int = 200
             response.status = "200 OK"
             for f, v in files.iteritems():
                 if v['format'].lower() == format and os.path.isfile(
                         v['path']):
                     fileserve_app = FileApp(v['path'])
                     return fileserve_app(request.environ,
                                          self.start_response)
     session['browse_flash'] = "Could not find any file for %s" % vocab
     session.save()
     return redirect(url(controller='vocabs', action='index'), code=303)
コード例 #30
0
                                using_uuid=using_uuid,
                                refvocab=refvocab)

        #Commit svn changes
        (status1, msg1) = svn_add(vocabdir,
                                  "New vocabulary added by user %s" % userid)
        if not status1:
            message.append("""Error committing to SVN: %s""" % msg1)

        (status2, msg2) = svn_commit([vocabdir, mediatorfile],
                                     "New vocabulary %s added by user %s" %
                                     (c.vocabprefix, userid))
        if not status2:
            message.append("""Error committing to SVN: %s""" % msg2)
        c.message = "<br />".join(message)
        return render('rename.html')

    def rename(self, prefix):
        identity = request.environ.get("repoze.who.identity")
        if not identity:
            session[
                'login_flash'] = "Please login to modify vocabularies published and managed by you"
            session.save()
            destination = "/login?came_from=rename/%s" % prefix
            return redirect(destination, code=303)

        #Check if userid has permissions for this vocab
        userid = identity['repoze.who.userid']
        mediatorfile = os.path.join(ag.mediatorsdir, '%s.rdf' % userid)
        vocablist = get_mediator_vocabs(userid)
        if vocablist and not prefix in vocablist.keys():