Ejemplo n.º 1
0
    def list(self, filetype='html'):
        redirect = request.params.get('redirect', False)
        limit = request.params.get('limit', None)
        idea_q = Session.query(Idea)
        c.query = ''
        c.sep = ''

        #c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
        if request.params.get('sep_filter'):
            idea_q = idea_q.filter(Idea.sep_dir != '')
        
        # Check for query
        if request.params.get('q'):
            q = request.params['q']
            c.query = q
            o = or_(Idea.label.like(q+'%'), Idea.label.like('% '+q+'%'))
            idea_q = idea_q.filter(o).order_by(Idea.entropy.desc())
            # if only 1 result, go ahead and view that idea
            if redirect and idea_q.count() == 1:
                h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype))
            else:
                c.ideas = idea_q.limit(limit)
                return render('idea/idea-list.' + filetype)
        
        #TODO: Error handling - we shouldn't have multiple results
        if request.params.get('sep'):
            idea_q = idea_q.filter(Idea.sep_dir == request.params['sep'])
            c.sep = request.params['sep']
            # if only 1 result, go ahead and view that idea
            if redirect and idea_q.count() == 1:
                h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype))
            elif idea_q.count() == 0:
                h.redirect(h.url(controller='entity', action='list', filetype=filetype, sep=request.params['sep'], redirect=redirect))
            else:
                c.ideas = idea_q.limit(limit)
                return render('idea/idea-list.' + filetype)
        
        all_param = request.params.get('all', False)
        node_param = request.params.get('nodes', True)
        instance_param = request.params.get('instances', True)
        
        node_q = idea_q.join((Node,Node.concept_id==Idea.ID))
        instance_q = idea_q.join(Instance.idea)

        if all_param:
            idea_q = idea_q
            if not node_param:
                idea_q = idea_q.except_(node_q)
            if not instance_param:
                idea_q = idea_q.except_(instance_q)
        elif node_param:
            idea_q = node_q
            if instance_param:
                idea_q = idea_q.union(instance_q)
        elif instance_param:
            idea_q = instance_q

        c.ideas = idea_q.limit(limit)
        return render('idea/idea-list.' + filetype)
Ejemplo n.º 2
0
    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = ["sep_dir", "wiki"]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'name' in params:
            name = params['name']
            del params['name']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        thinker = Thinker(name, **params)
        Session.add(thinker)
        Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='thinker',
                                             action='view',
                                             id=thinker.ID)
        return "Moved temporarily"
Ejemplo n.º 3
0
    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = ["sep_dir", "wiki"]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'label' in params:
            label = params['label']
            del params['label']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        school_of_thought = SchoolOfThought(name, **params)
        Session.add(school_of_thought)
        Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='school_of_thought',
                                                 action='view', id=school_of_thought.ID)
        return "Moved temporarily"
Ejemplo n.º 4
0
    def list(self, filetype='html'):
        c.nodes = Session.query(Node).all()
        
        entity_q = Session.query(Node)
        entity_q = entity_q.limit(request.params.get('limit', None))
        
        c.query = request.params.get('q', '')
        c.sep = request.params.get('sep', '')

        if request.params.get('sep_filter', False):
            entity_q = entity_q.filter(Entity.sep_dir != '')
        
        if c.sep:
            entity_q = entity_q.filter(Entity.sep_dir == c.sep) 

        if c.query:
            o = or_(Entity.label.like(c.query+'%'), Entity.label.like('% '+c.query+'%'))
            entity_q = entity_q.filter(o).order_by(func.length(Entity.label))
        
        if filetype=='json':
            response.content_type = 'application/json'
        response.headers['Access-Control-Allow-Origin'] = '*' 

        c.entities = entity_q.all()
        if request.params.get('redirect', False) and len(c.entities) == 1: 
            h.redirect(h.url(controller=self._controller, action='view', 
                             filetype=filetype, id=c.entities[0].ID), 
                       code=302)
        else:
            return render('{type}/{type}-list.'.format(type=self._controller) 
                          + filetype)
Ejemplo n.º 5
0
    def submit_changes(self):
        ''' 
        This function validates the submitted profile edit form and commits the 
        changes. Restricted to ``POST`` requests. If successful, redirects to 
        the result action to prevent resubmission.
        ''' 
        if not h.auth.is_logged_in():
            abort(401)

        c.user = h.get_user(request.environ['REMOTE_USER'])
       
        if self.form_result['password'] != '':
            c.user.set_password(self.form_result['password'])

        # TODO: Enable area editing
        #c.user.first_area_id=self.form_result['first_area'],
        #user.first_area_level=self.form_result['first_area_level'],
        #if self.form_result['second_area']:
        #    c.user.second_area_id=self.form_result['second_area'],
        #    c.user.second_area_level=self.form_result['second_area_level']
        c.user.fullname = self.form_result['fullname']

        Session.flush()

        Session.commit()

        h.redirect(h.url(controller='account', action='profile', message='edited'))
Ejemplo n.º 6
0
    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = ["ISSN", "noesisInclude", "URL", "source", 
                        "abbr", "language", "student", "active"]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'name' in params:
            name = params['name']
            del params['name']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        journal = Journal(name, **params)
        Session.add(journal)
        Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='journal',
                                                 action='view', id=journal.ID)
        return "Moved temporarily"
Ejemplo n.º 7
0
    def submit(self):
        ''' 
        This function validates the submitted registration form and creates a
        new user. Restricted to ``POST`` requests. If successful, redirects to 
        the result action to prevent resubmission.
        '''

        user = User(self.form_result['username'],
                    self.form_result['password'],
                    email=self.form_result['email'],
                    first_area_id=self.form_result['first_area'],
                    first_area_level=self.form_result['first_area_level'],
                    second_area_id=self.form_result['second_area'],
                    second_area_level=self.form_result['second_area_level'])

        Session.add(user)
        Session.commit()

        msg = Message("*****@*****.**", self.form_result['email'],
                      "InPhO registration")
        msg.plain = """%s, thank you for registering with the Indiana Philosophy
                        Ontology Project (InPhO). You can access your """ % self.form_result[
            'username']
        msg.send()

        h.redirect(h.url(controller='account', action='result'))
Ejemplo n.º 8
0
    def _reset(self, username=None):
        username = username or request.environ.get('REMOTE_USER', False)
        if not username:
            abort(401)

        try:
            user = h.get_user(username)
        except:
            abort(400)
            
        new_password = user.reset_password()


        msg = Message("*****@*****.**", user.email,
                      "InPhO password reset")
        msg.plain = """
%(name)s, your password at the Indiana Philosophy Ontology (InPhO) has been changed to:
Username: %(uname)s
Password: %(passwd)s

The Indiana Philosophy Ontology (InPhO) Team
[email protected]
                       """ % {'passwd' : new_password,
                              'uname' : user.username,
                              'name' : user.fullname or user.username or ''}
        msg.send()

        Session.commit()

        h.redirect(h.url(controller='account', action='reset_result'))
Ejemplo n.º 9
0
    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = ["sep_dir", "searchstring", "searchpattern"]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'label' in params:
            label = params['label']
            del params['label']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        idea = Idea(label)
        Session.add(idea)
        Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='idea',
                                                 action='view', id=idea.ID)
        return "Moved temporarily"
Ejemplo n.º 10
0
    def submit_changes(self):
        ''' 
        This function validates the submitted profile edit form and commits the 
        changes. Restricted to ``POST`` requests. If successful, redirects to 
        the result action to prevent resubmission.
        ''' 
        if not h.auth.is_logged_in():
            abort(401)

        c.user = h.get_user(request.environ['REMOTE_USER'])
       
        if self.form_result['password'] != '':
            c.user.set_password(self.form_result['password'])

        # TODO: Enable area editing
        #c.user.first_area_id=self.form_result['first_area'],
        #user.first_area_level=self.form_result['first_area_level'],
        #if self.form_result['second_area']:
        #    c.user.second_area_id=self.form_result['second_area'],
        #    c.user.second_area_level=self.form_result['second_area_level']
        c.user.fullname = self.form_result['fullname']

        Session.flush()

        Session.commit()

        h.redirect(h.url(controller='account', action='profile', message='edited'))
Ejemplo n.º 11
0
    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = [
            "ISSN", "noesisInclude", "URL", "source", "abbr", "language",
            "student", "active"
        ]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'name' in params:
            name = params['name']
            del params['name']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        journal = Journal(name, **params)
        Session.add(journal)
        Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='journal',
                                             action='view',
                                             id=journal.ID)
        return "Moved temporarily"
Ejemplo n.º 12
0
    def _reset(self, username=None):
        username = username or request.environ.get('REMOTE_USER', False)
        if not username:
            abort(401)

        try:
            user = h.get_user(username)
        except:
            abort(400)
            
        new_password = user.reset_password()


        msg = Message("*****@*****.**", user.email,
                      "InPhO password reset")
        msg.plain = """
%(name)s, your password at the Indiana Philosophy Ontology (InPhO) has been changed to:
Username: %(uname)s
Password: %(passwd)s

The Indiana Philosophy Ontology (InPhO) Team
[email protected]
                       """ % {'passwd' : new_password,
                              'uname' : user.username,
                              'name' : user.fullname or user.username or ''}
        msg.send()

        Session.commit()

        h.redirect(h.url(controller='account', action='reset_result'))
Ejemplo n.º 13
0
    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = ["sep_dir", "searchstring", "searchpattern"]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'label' in params:
            label = params['label']
            del params['label']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        idea = Idea(label)
        Session.add(idea)
        Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='idea',
                                                 action='view', id=idea.ID)
        return "Moved temporarily"
Ejemplo n.º 14
0
    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = ["sep_dir", "wiki"]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'name' in params:
            name = params['name']
            del params['name']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        thinker = Thinker(name, **params)
        Session.add(thinker)
        Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='thinker',
                                                 action='view', id=thinker.ID)
        return "Moved temporarily"
Ejemplo n.º 15
0
    def list_new(self):
        if not h.auth.is_logged_in():
            response.status_int = 401
            return "Unauthorized"
        if not h.auth.is_admin():
            response.status_int = 403
            return "Forbidden"

        addlist = sep.new_entries()
        titles = sep.get_titles()

        c.entries = []

        #perform a fuzzy match for each page and construct an appropriate link
        for sep_dir in addlist:
            #create a link for each entry in addlist()
            link = h.url(controller='entity',
                         action='new',
                         label=titles[sep_dir],
                         sep_dir=sep_dir)
            c.entries.append({
                'sep_dir': sep_dir,
                'title': titles[sep_dir],
                'link': link,
                'published': sep.published(sep_dir)
            })

        return render('admin/newentries.html')
Ejemplo n.º 16
0
    def list(self, filetype="html"):
        c.nodes = Session.query(Node).all()

        entity_q = Session.query(Node)
        entity_q = entity_q.limit(request.params.get("limit", None))

        c.query = request.params.get("q", "")
        c.sep = request.params.get("sep", "")

        if request.params.get("sep_filter", False):
            entity_q = entity_q.filter(Entity.sep_dir != "")

        if c.sep:
            entity_q = entity_q.filter(Entity.sep_dir == c.sep)

        if c.query:
            o = or_(Entity.label.like(c.query + "%"), Entity.label.like("% " + c.query + "%"))
            entity_q = entity_q.filter(o).order_by(func.length(Entity.label))

        if filetype == "json":
            response.content_type = "application/json"
        response.headers["Access-Control-Allow-Origin"] = "*"

        c.entities = entity_q.all()
        if request.params.get("redirect", False) and len(c.entities) == 1:
            h.redirect(
                h.url(controller=self._controller, action="view", filetype=filetype, id=c.entities[0].ID), code=302
            )
        else:
            return render("{type}/{type}-list.".format(type=self._controller) + filetype)
Ejemplo n.º 17
0
    def submit(self):
        ''' 
        This function validates the submitted registration form and creates a
        new user. Restricted to ``POST`` requests. If successful, redirects to 
        the result action to prevent resubmission.
        ''' 
        
        user = User(
            self.form_result['username'],
            self.form_result['password'],
            email=self.form_result['email'],
            first_area_id=self.form_result['first_area'],
            first_area_level=self.form_result['first_area_level'],
            second_area_id=self.form_result['second_area'],
            second_area_level=self.form_result['second_area_level']
        )


        Session.add(user) 
        Session.commit()

        msg = Message("*****@*****.**", self.form_result['email'], 
                      "InPhO registration")
        msg.plain = """%s, thank you for registering with the Indiana Philosophy
                        Ontology Project (InPhO). You can access your """ % self.form_result['username'] 
        msg.send()

        h.redirect(h.url(controller='account', action='result'))
Ejemplo n.º 18
0
    def create(self):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        valid_params = ["sep_dir", "wiki"]
        params = request.params.mixed()

        if '_method' in params:
            del params['_method']
        if 'label' in params:
            label = params['label']
            del params['label']
        else:
            abort(400)
        for k in params.keys():
            if k not in valid_params:
                abort(400)

        school_of_thought = model.SchoolOfThought(name, **params)
        meta.Session.add(school_of_thought)
        meta.Session.flush()

        # Issue an HTTP success
        response.status_int = 302
        response.headers['location'] = h.url(controller='school_of_thought',
                                             action='view',
                                             id=school_of_thought.ID)
        return "Moved temporarily"
Ejemplo n.º 19
0
    def list(self, filetype='html'):
        entity_q = Session.query(self._type)
        #TODO: Remove the following line when Nodes are eliminated
        entity_q = entity_q.filter(Entity.typeID != 2)

        c.missing_entity = 0
        # get the list of entities
        #c.entities = entity_q.all()

        c.nodes = Session.query(Node).filter(Node.parent_id == None)
        c.nodes = c.nodes.order_by("name").all()

        c.query = request.params.get('q', '')
        c.query = c.query.strip()

        c.sep = request.params.get('sep', '')

        c.wiki = request.params.get('wiki', '')

        if request.params.get('sep_filter', False):
            entity_q = entity_q.filter(Entity.sep_dir != '')

        if c.sep:
            entity_q = entity_q.filter(Entity.sep_dir == c.sep)

        if c.wiki:
            entity_q = entity_q.filter(Entity.wiki == c.wiki)

        if c.query:
            o = or_(Entity.label.like(c.query + '%'),
                    Entity.label.like('% ' + c.query + '%'),
                    Entity.label.like('%-' + c.query + '%'))
            entity_q = entity_q.filter(o).order_by(func.length(Entity.label))

        c.total = entity_q.count()
        # limit must be the last thing applied to the query
        entity_q = entity_q.limit(request.params.get('limit', None))
        c.entities = entity_q.all()

        if filetype == 'json':
            response.content_type = 'application/json'

        if request.params.get('redirect', False) and len(c.entities) == 1:
            h.redirect(h.url(controller=self._controller,
                             action='view',
                             filetype=filetype,
                             id=c.entities[0].ID),
                       code=302)
        else:
            #if there are no results, show the related SEP results
            if not c.entities:
                c.entities = self.missing_entity_search(c.query)
                if c.entities:
                    c.missing_entity = 1
        #raise Exception
        #render the page
        return render('{type}/{type}-list.'.format(type=self._controller) +
                      filetype)
Ejemplo n.º 20
0
    def list(self, filetype="html"):
        entity_q = Session.query(self._type)
        # TODO: Remove the following line when Nodes are eliminated
        entity_q = entity_q.filter(Entity.typeID != 2)

        c.missing_entity = 0
        # get the list of entities
        # c.entities = entity_q.all()

        c.nodes = Session.query(Node).filter(Node.parent_id == None)
        c.nodes = c.nodes.order_by("name").all()

        c.query = request.params.get("q", "")
        c.query = c.query.strip()

        c.sep = request.params.get("sep", "")

        c.wiki = request.params.get("wiki", "")

        if request.params.get("sep_filter", False):
            entity_q = entity_q.filter(Entity.sep_dir != "")

        if c.sep:
            entity_q = entity_q.filter(Entity.sep_dir == c.sep)

        if c.wiki:
            entity_q = entity_q.filter(Entity.wiki == c.wiki)

        if c.query:
            o = or_(
                Entity.label.like(c.query + "%"),
                Entity.label.like("% " + c.query + "%"),
                Entity.label.like("%-" + c.query + "%"),
            )
            entity_q = entity_q.filter(o).order_by(func.length(Entity.label))

        c.total = entity_q.count()
        # limit must be the last thing applied to the query
        entity_q = entity_q.limit(request.params.get("limit", None))
        c.entities = entity_q.all()

        if filetype == "json":
            response.content_type = "application/json"

        if request.params.get("redirect", False) and len(c.entities) == 1:
            h.redirect(
                h.url(controller=self._controller, action="view", filetype=filetype, id=c.entities[0].ID), code=302
            )
        else:
            # if there are no results, show the related SEP results
            if not c.entities:
                c.entities = self.missing_entity_search(c.query)
                if c.entities:
                    c.missing_entity = 1
        # raise Exception
        # render the page
        return render("{type}/{type}-list.".format(type=self._controller) + filetype)
Ejemplo n.º 21
0
    def list(self, filetype="html", redirect=False):
        node_q = Session.query(Node)

        # check for query
        if request.params.get("q"):
            node_q = node_q.filter(Node.name.like(u"%" + request.params["q"] + "%"))
            # if only 1 result, go ahead and view that node
            if redirect and node_q.count() == 1:
                h.redirect(h.url(controller="taxonomy", action="view", id=node_q.first().ID, filetype=filetype))

        if filetype == "html":
            c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
            return render("taxonomy/node-list.html")
        else:
            c.nodes = node_q.all()
            return render("taxonomy/node-list.%s" % filetype)
Ejemplo n.º 22
0
    def list(self, filetype='html'):
        redirect = request.params.get('redirect', False)
        limit = request.params.get('limit', None)
        entity_q = model.meta.Session.query(model.Entity)
        entity_q = entity_q.filter(model.Entity.typeID != 2)

        c.nodes = model.meta.Session.query(model.Node).filter(
            model.Node.parent_id == None).order_by("name").all()
        c.query = ''
        c.sep = ''

        if filetype == 'json':
            response.content_type = 'application/json'

        if request.params.get('sep_filter'):
            entity_q = entity_q.filter(model.Entity.sep_dir != '')

        if request.params.get('sep'):
            entity_q = entity_q.filter(
                model.Entity.sep_dir == request.params['sep'])
            c.sep = request.params['sep']
            # if only 1 result, go ahead and view that entity
            if redirect and entity_q.count() == 1:
                h.redirect(h.url(controller='entity',
                                 action='view',
                                 filetype=filetype,
                                 id=entity_q.first().ID),
                           code=302)

        # Check for query
        if request.params.get('q'):
            q = request.params['q']
            c.query = q
            o = or_(model.Entity.label.like(q + '%'),
                    model.Entity.label.like('% ' + q + '%'))
            entity_q = entity_q.filter(o).order_by(
                func.length(model.Entity.label))
            # if only 1 result, go ahead and view that idea
            if redirect and entity_q.count() == 1:
                return self.view(entity_q.first().ID, filetype)
            else:
                c.entities = entity_q.limit(limit)
                return render('entity/entity-list.' + filetype)

        c.entities = entity_q.limit(limit)
        return render('entity/entity-list.' + filetype)
Ejemplo n.º 23
0
    def load_check(self, filetype="html", redirect=False):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        entity_q = Session.query(Entity)
        c.entities = list(entity_q)

        c.load_error = []

        for entity in c.entities:
            try:
                urlopen(h.url('https://www.inphoproject.org', getattr(entity, 'url')))
            except Exception as e:
                c.load_error.append(entity)

        return render('entity/load_check.' + filetype)
Ejemplo n.º 24
0
    def load_check(self, filetype="html", redirect=False):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        entity_q = Session.query(Entity)
        c.entities = list(entity_q)

        c.load_error = []

        for entity in c.entities:
            try:
                urlopen(h.url('https://www.inphoproject.org', getattr(entity, 'url')))
            except Exception as e:
                c.load_error.append(entity)

        return render('entity/load_check.' + filetype)
Ejemplo n.º 25
0
    def view(self, id=None, filetype='html'):
        if filetype == 'html':
            redirect = request.params.get('redirect', True)
        else:
            redirect = request.params.get('redirect', False)

        sep_filter = request.params.get('sep_filter', False) 
        c.sep_filter = sep_filter

        c.idea = h.fetch_obj(Idea, id, new_id=True)

        c.count = len(c.idea.nodes) + len(c.idea.instance_of) + len(c.idea.links_to)
        if len(c.idea.nodes) > 0:
            c.node = c.idea.nodes[0]
        elif len(c.idea.instance_of) > 0:
            c.node = c.idea.instance_of[0]
        else:
            c.node = None
        
        c.evaluations = defaultdict(lambda: (-1, -1))
        identity = request.environ.get('repoze.who.identity')
        if identity:
            c.uid = identity['user'].ID
            #c.evaluations = Session.query(IdeaEvaluation).filter_by(ante_id=c.idea.ID, uid=uid).all()
            eval_q = Session.query(IdeaEvaluation.cons_id, 
                                   IdeaEvaluation.generality, 
                                   IdeaEvaluation.relatedness)
            eval_q = eval_q.filter_by(uid=c.uid, ante_id=c.idea.ID)
            evals = eval_q.all()
            evals = map(lambda x: (x[0], (x[1], x[2])), evals)
            c.evaluations.update(dict(evals))

        else:
            c.uid = None


        if redirect and len(c.idea.nodes) == 1:
            h.redirect(h.url(controller='taxonomy', action='view',
                             id=c.idea.nodes[0].ID,filetype=filetype), code=303)

        if filetype=='json':
            response.content_type = 'application/json'

        return render('idea/idea.' + filetype)
Ejemplo n.º 26
0
    def submit(self):
        ''' 
        This function validates the submitted registration form and creates a
        new user. Restricted to ``POST`` requests. If successful, redirects to 
        the result action to prevent resubmission.
        ''' 
        
        user = User(
            self.form_result['username'],
            fullname=self.form_result['fullname'],
            email=self.form_result['email'],
            first_area_id=self.form_result['first_area'],
            first_area_level=self.form_result['first_area_level'],
            second_area_id=self.form_result['second_area'],
            second_area_level=self.form_result['second_area_level']
        )


        Session.add(user) 
        password = user.reset_password()
        Session.commit()

        msg = Message("*****@*****.**", self.form_result['email'], 
                      "InPhO registration")
        msg.plain = """Dear %(name)s, 
Thank you for registering with the Indiana Philosophy Ontology Project (InPhO).

You can sign in at https://inpho.cogs.indiana.edu/signin with the following
information:

Username: %(uname)s
Password: %(passwd)s

You may change your password at https://inpho.cogs.indiana.edu/account/edit .

The Indiana Philosophy Ontology Project (InPhO) Team
[email protected]
                       """ % {'passwd' : password,
                              'uname' : user.username,
                              'name' : user.fullname or user.username or ''}
        msg.send()

        h.redirect(h.url(controller='account', action='result'))
Ejemplo n.º 27
0
    def submit(self):
        ''' 
        This function validates the submitted registration form and creates a
        new user. Restricted to ``POST`` requests. If successful, redirects to 
        the result action to prevent resubmission.
        ''' 
        
        user = User(
            self.form_result['username'],
            fullname=self.form_result['fullname'],
            email=self.form_result['email'],
            first_area_id=self.form_result['first_area'],
            first_area_level=self.form_result['first_area_level'],
            second_area_id=self.form_result['second_area'],
            second_area_level=self.form_result['second_area_level']
        )


        Session.add(user) 
        password = user.reset_password()
        Session.commit()

        msg = Message("*****@*****.**", self.form_result['email'], 
                      "InPhO registration")
        msg.plain = """Dear %(name)s, 
Thank you for registering with the Indiana Philosophy Ontology Project (InPhO).

You can sign in at https://inpho.cogs.indiana.edu/signin with the following
information:

Username: %(uname)s
Password: %(passwd)s

You may change your password at https://inpho.cogs.indiana.edu/account/edit .

The Indiana Philosophy Ontology Project (InPhO) Team
[email protected]
                       """ % {'passwd' : password,
                              'uname' : user.username,
                              'name' : user.fullname or user.username or ''}
        msg.send()

        h.redirect(h.url(controller='account', action='result'))
Ejemplo n.º 28
0
 def addlist(self):
     #functionality for parsing through the list of entries which need to be added in light of additions to SEP
     #first step; run the genetries function to refresh the sepentries table from SEPMirror
     
     #uncomment the next line to refresh entries -- need to figure out how to coordinate with doing fuzzymatches ahead of time...maybe just look for new entries and add them?
     #sep.getentries()
     
     
     #second, get the list of entries to be added in a context objects
     addlist = sep.addlist()
     c.entries = []
     
     #perform a fuzzy match for each page and construct an appropriate link
     for entry in addlist:
         #create a link for each entry in addlist()
         entry.link = h.url(controller='admin', action='addentry', title=entry.title, sep_dir = entry.sep_dir)
         c.entries.append(entry)
     
     c.message = "Below is a list of SEP entries lacking a corresponding entry in the entity table.  Please click on the link to edit the page for that idea.\n Note that clicking on one of these can take 2-5 minutes to fuzzymatch existing entity entries."
     return render ('admin/newentries.html')
Ejemplo n.º 29
0
    def update(self, id, terms=None):
        if not h.auth.is_logged_in():
            response.status_int = 401
            return "Unauthorized"
        if not h.auth.is_admin():
            response.status_int = 403
            return "Forbidden"

        # if no whitelist is passed in, go with default
        if terms is None:
            terms = ["sep_dir", "searchstring", "label"]

        entity = h.fetch_obj(self._type, id)
        h.update_obj(entity, terms, request.params)

        # Check for redirect
        if request.params.get("redirect", False):
            h.redirect(h.url(controller=self._controller, action="view", id=entity.ID))
        else:
            # Issue an HTTP success
            response.status_int = 200
            return "OK"
Ejemplo n.º 30
0
    def list_new(self):
        if not h.auth.is_logged_in():
            response.status_int = 401
            return "Unauthorized"
        if not h.auth.is_admin():
            response.status_int = 403
            return "Forbidden"

        addlist = sep.new_entries()
        titles = sep.get_titles()

        c.entries = []

        # perform a fuzzy match for each page and construct an appropriate link
        for sep_dir in addlist:
            # create a link for each entry in addlist()
            link = h.url(controller="entity", action="new", label=titles[sep_dir], sep_dir=sep_dir)
            c.entries.append(
                {"sep_dir": sep_dir, "title": titles[sep_dir], "link": link, "published": sep.published(sep_dir)}
            )

        return render("admin/newentries.html")
Ejemplo n.º 31
0
    def addlist(self):
        #functionality for parsing through the list of entries which need to be added in light of additions to SEP
        #first step; run the genetries function to refresh the sepentries table from SEPMirror

        #uncomment the next line to refresh entries -- need to figure out how to coordinate with doing fuzzymatches ahead of time...maybe just look for new entries and add them?
        #sep.getentries()

        #second, get the list of entries to be added in a context objects
        addlist = sep.addlist()
        c.entries = []

        #perform a fuzzy match for each page and construct an appropriate link
        for entry in addlist:
            #create a link for each entry in addlist()
            entry.link = h.url(controller='admin',
                               action='addentry',
                               title=entry.title,
                               sep_dir=entry.sep_dir)
            c.entries.append(entry)

        c.message = "Below is a list of SEP entries lacking a corresponding entry in the entity table.  Please click on the link to edit the page for that idea.\n Note that clicking on one of these can take 2-5 minutes to fuzzymatch existing entity entries."
        return render('admin/newentries.html')
Ejemplo n.º 32
0
    def list(self, filetype='html'):
        redirect = request.params.get('redirect', False)
        limit = request.params.get('limit', None)
        entity_q = model.meta.Session.query(model.Entity)
        entity_q = entity_q.filter(model.Entity.typeID != 2)
        
        c.nodes = model.meta.Session.query(model.Node).filter(model.Node.parent_id == None).order_by("name").all()
        c.query = '' 
        c.sep = ''

        if filetype=='json':
            response.content_type = 'application/json'

        if request.params.get('sep_filter'):
            entity_q = entity_q.filter(model.Entity.sep_dir != '')
        
        if request.params.get('sep'):
            entity_q = entity_q.filter(model.Entity.sep_dir == request.params['sep'])
            c.sep = request.params['sep']
            # if only 1 result, go ahead and view that entity
            if redirect and entity_q.count() == 1:
                h.redirect(h.url(controller='entity', action='view',
                filetype=filetype, id=entity_q.first().ID), code=302)

        # Check for query
        if request.params.get('q'):
            q = request.params['q']
            c.query = q
            o = or_(model.Entity.label.like(q+'%'), model.Entity.label.like('% '+q+'%'))
            entity_q = entity_q.filter(o).order_by(func.length(model.Entity.label))
            # if only 1 result, go ahead and view that idea
            if redirect and entity_q.count() == 1:
                return self.view(entity_q.first().ID, filetype)
            else:
                c.entities = entity_q.limit(limit)
                return render('entity/entity-list.' + filetype)

        c.entities = entity_q.limit(limit)
        return render('entity/entity-list.' + filetype)
Ejemplo n.º 33
0
    def list(self, filetype='html', redirect=False):
        node_q = Session.query(Node)

        # check for query
        if request.params.get('q'):
            node_q = node_q.filter(
                Node.name.like(u'%' + request.params['q'] + '%'))
            # if only 1 result, go ahead and view that node
            if redirect and node_q.count() == 1:
                h.redirect(
                    h.url(controller='taxonomy',
                          action='view',
                          id=node_q.first().ID,
                          filetype=filetype))

        if filetype == 'html':
            c.nodes = Session.query(Node).filter(
                Node.parent_id == None).order_by("name").all()
            return render('taxonomy/node-list.html')
        else:
            c.nodes = node_q.all()
            return render('taxonomy/node-list.%s' % filetype)
Ejemplo n.º 34
0
    def update(self, id, terms=None):
        if not h.auth.is_logged_in():
            response.status_int = 401
            return "Unauthorized"
        if not h.auth.is_admin():
            response.status_int = 403
            return "Forbidden"

        #if no whitelist is passed in, go with default
        if terms is None:
            terms = ['sep_dir', 'searchstring', 'label']

        entity = h.fetch_obj(self._type, id)
        h.update_obj(entity, terms, request.params)

        # Check for redirect
        if request.params.get('redirect', False):
            h.redirect(
                h.url(controller=self._controller, action='view', id=entity.ID))
        else:
            # Issue an HTTP success
            response.status_int = 200
            return "OK"
Ejemplo n.º 35
0
    def view(self, id=None, filetype='html'):
        if filetype == 'html':
            redirect = request.params.get('redirect', True)
        else:
            redirect = request.params.get('redirect', False)

        sep_filter = request.params.get('sep_filter', False) 
        c.sep_filter = sep_filter

        # IDEA GETTIN'
        c.entity = h.fetch_obj(Idea, id, new_id=True)

        if filetype=='json':
            response.content_type = 'application/json'
            return c.entity.json()

        c.count = len(c.entity.nodes) + len(c.entity.instance_of) + len(c.entity.links_to)
        c.nodes = list()
        if c.entity.nodes:
            c.nodes.extend(c.entity.nodes[:])
        for idea in c.entity.instance_of:
            for node in idea.nodes:
                c.nodes.append(node)
        for idea in c.entity.links_to:
            for node in idea.nodes:
                c.nodes.append(node)

        if c.entity.nodes:
            c.node = c.entity.nodes[0]
        elif c.entity.instance_of:
            c.node = c.entity.instance_of[0]
            # just in case of data corruption
            # instance_of points to idea, need node
            if c.node.nodes:
                c.node = c.node.nodes[0]
        elif c.entity.links_to:
            c.node = c.entity.links_to[0]
            # just in case of data corruption
            # links_to point to idea, need node
            if c.node.nodes:
                c.node = c.node.nodes[0]
        else:
            c.node = None
        
        # EVALUATION PROCESSING
        c.evaluations = defaultdict(lambda: (-1, -1))
        identity = request.environ.get('repoze.who.identity')
        if identity:
            c.uid = identity['user'].ID
            #c.evaluations = Session.query(IdeaEvaluation).filter_by(ante_id=c.entity.ID, uid=uid).all()
            eval_q = Session.query(IdeaEvaluation.cons_id, 
                                   IdeaEvaluation.generality, 
                                   IdeaEvaluation.relatedness)
            eval_q = eval_q.filter_by(uid=c.uid, ante_id=c.entity.ID)
            evals = eval_q.all()
            evals = map(lambda x: (x[0], (x[1], x[2])), evals)
            c.evaluations.update(dict(evals))

        else:
            c.uid = None

        # REDIRECTING
        if redirect and len(c.entity.nodes) == 1:
            h.redirect(h.url(controller='taxonomy', action='view',
                             id=c.entity.nodes[0].ID,filetype=filetype), code=303)

        return render('idea/idea.' + filetype)
Ejemplo n.º 36
0
    def list(self, filetype='html'):
        redirect = request.params.get('redirect', False)
        limit = request.params.get('limit', None)
        idea_q = Session.query(Idea)
        c.query = ''
        c.sep = ''

        #c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
        if request.params.get('sep_filter'):
            idea_q = idea_q.filter(Idea.sep_dir != '')
        
        if filetype=='json':
            response.content_type = 'application/json'

        # Check for query
        if request.params.get('q'):
            q = request.params['q']
            c.query = q
            o = or_(Idea.label.like(q+'%'), Idea.label.like('% '+q+'%'))
            idea_q = idea_q.filter(o).order_by(Idea.entropy.desc())
            # if only 1 result, go ahead and view that idea
            if redirect and idea_q.count() == 1:
                h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype))
        
        #TODO: Error handling - we shouldn't have multiple results
        if request.params.get('sep'):
            idea_q = idea_q.filter(Idea.sep_dir == request.params['sep'])
            c.sep = request.params['sep']
            # if only 1 result, go ahead and view that idea
            if redirect and idea_q.count() == 1:
                h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype))
            elif idea_q.count() == 0:
                h.redirect(h.url(controller='entity', action='list', filetype=filetype, sep=request.params['sep'], redirect=redirect))
        
        '''
        ### This block of code filters out nodes and instances, reduces occurances of 'ism's
        ### It is not currently necessary and causes an error in the middle 'elif' block.
        all_param = request.params.get('all', False)
        node_param = request.params.get('nodes', True)
        instance_param = request.params.get('instances', True)
        
        node_q = idea_q.join((Node,Node.concept_id==Idea.ID))
        instance_q = idea_q.join(Instance.idea)
        
        if all_param:
            idea_q = idea_q
            if not node_param:
                idea_q = idea_q.except_(node_q)
            if not instance_param:
                idea_q = idea_q.except_(instance_q)
        elif node_param:
            idea_q = node_q
            if instance_param:
                # ISSUE!!! This union causes an error when executing the query!... why?
                idea_q = idea_q.union(instance_q)
        elif instance_param:
            idea_q = instance_q
        '''
        
        c.total = idea_q.count()
        c.entities = idea_q.limit(limit)

        return render('idea/idea-list.' + filetype)
Ejemplo n.º 37
0
    def list(self, filetype='html'):
        redirect = request.params.get('redirect', False)
        limit = request.params.get('limit', None)
        idea_q = Session.query(Idea)
        c.query = ''
        c.sep = ''

        #c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
        if request.params.get('sep_filter'):
            idea_q = idea_q.filter(Idea.sep_dir != '')
        
        if filetype=='json':
            response.content_type = 'application/json'

        # Check for query
        if request.params.get('q'):
            q = request.params['q']
            c.query = q
            o = or_(Idea.label.like(q+'%'), Idea.label.like('% '+q+'%'))
            idea_q = idea_q.filter(o).order_by(Idea.entropy.desc())
            # if only 1 result, go ahead and view that idea
            if redirect and idea_q.count() == 1:
                h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype))
            else:
                c.ideas = idea_q.limit(limit)
                return render('idea/idea-list.' + filetype)
        
        #TODO: Error handling - we shouldn't have multiple results
        if request.params.get('sep'):
            idea_q = idea_q.filter(Idea.sep_dir == request.params['sep'])
            c.sep = request.params['sep']
            # if only 1 result, go ahead and view that idea
            if redirect and idea_q.count() == 1:
                h.redirect(h.url(controller='idea', action='view', id=idea_q.first().ID,filetype=filetype))
            elif idea_q.count() == 0:
                h.redirect(h.url(controller='entity', action='list', filetype=filetype, sep=request.params['sep'], redirect=redirect))
            else:
                c.ideas = idea_q.limit(limit)
                return render('idea/idea-list.' + filetype)
        
        all_param = request.params.get('all', False)
        node_param = request.params.get('nodes', True)
        instance_param = request.params.get('instances', True)
        
        node_q = idea_q.join((Node,Node.concept_id==Idea.ID))
        instance_q = idea_q.join(Instance.idea)

        if all_param:
            idea_q = idea_q
            if not node_param:
                idea_q = idea_q.except_(node_q)
            if not instance_param:
                idea_q = idea_q.except_(instance_q)
        elif node_param:
            idea_q = node_q
            if instance_param:
                idea_q = idea_q.union(instance_q)
        elif instance_param:
            idea_q = instance_q

        c.ideas = idea_q.limit(limit)
        return render('idea/idea-list.' + filetype)
Ejemplo n.º 38
0
    def view(self, id=None, filetype='html'):
        if filetype == 'html':
            redirect = request.params.get('redirect', True)
        else:
            redirect = request.params.get('redirect', False)

        sep_filter = request.params.get('sep_filter', False)
        c.sep_filter = sep_filter

        # IDEA GETTIN'
        c.entity = h.fetch_obj(Idea, id, new_id=True)

        if filetype == 'json':
            response.content_type = 'application/json'
            return c.entity.json()

        c.count = len(c.entity.nodes) + len(c.entity.instance_of) + len(
            c.entity.links_to)
        c.nodes = list()
        if c.entity.nodes:
            c.nodes.extend(c.entity.nodes[:])
        for idea in c.entity.instance_of:
            for node in idea.nodes:
                c.nodes.append(node)
        for idea in c.entity.links_to:
            for node in idea.nodes:
                c.nodes.append(node)

        if c.entity.nodes:
            c.node = c.entity.nodes[0]
        elif c.entity.instance_of:
            c.node = c.entity.instance_of[0]
            # just in case of data corruption
            # instance_of points to idea, need node
            if c.node.nodes:
                c.node = c.node.nodes[0]
        elif c.entity.links_to:
            c.node = c.entity.links_to[0]
            # just in case of data corruption
            # links_to point to idea, need node
            if c.node.nodes:
                c.node = c.node.nodes[0]
        else:
            c.node = None

        # EVALUATION PROCESSING
        c.evaluations = defaultdict(lambda: (-1, -1))
        identity = request.environ.get('repoze.who.identity')
        if identity:
            c.uid = identity['user'].ID
            #c.evaluations = Session.query(IdeaEvaluation).filter_by(ante_id=c.entity.ID, uid=uid).all()
            eval_q = Session.query(IdeaEvaluation.cons_id,
                                   IdeaEvaluation.generality,
                                   IdeaEvaluation.relatedness)
            eval_q = eval_q.filter_by(uid=c.uid, ante_id=c.entity.ID)
            evals = eval_q.all()
            evals = map(lambda x: (x[0], (x[1], x[2])), evals)
            c.evaluations.update(dict(evals))

        else:
            c.uid = None

        # REDIRECTING
        if redirect and len(c.entity.nodes) == 1:
            h.redirect(h.url(controller='taxonomy',
                             action='view',
                             id=c.entity.nodes[0].ID,
                             filetype=filetype),
                       code=303)

        return render('idea/idea.' + filetype)
Ejemplo n.º 39
0
    def list(self, filetype='html'):
        redirect = request.params.get('redirect', False)
        limit = request.params.get('limit', None)
        idea_q = Session.query(Idea)
        c.query = ''
        c.sep = ''

        #c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
        if request.params.get('sep_filter'):
            idea_q = idea_q.filter(Idea.sep_dir != '')

        if filetype == 'json':
            response.content_type = 'application/json'

        # Check for query
        if request.params.get('q'):
            q = request.params['q']
            c.query = q
            o = or_(Idea.label.like(q + '%'), Idea.label.like('% ' + q + '%'))
            idea_q = idea_q.filter(o).order_by(Idea.entropy.desc())
            # if only 1 result, go ahead and view that idea
            if redirect and idea_q.count() == 1:
                h.redirect(
                    h.url(controller='idea',
                          action='view',
                          id=idea_q.first().ID,
                          filetype=filetype))

        #TODO: Error handling - we shouldn't have multiple results
        if request.params.get('sep'):
            idea_q = idea_q.filter(Idea.sep_dir == request.params['sep'])
            c.sep = request.params['sep']
            # if only 1 result, go ahead and view that idea
            if redirect and idea_q.count() == 1:
                h.redirect(
                    h.url(controller='idea',
                          action='view',
                          id=idea_q.first().ID,
                          filetype=filetype))
            elif idea_q.count() == 0:
                h.redirect(
                    h.url(controller='entity',
                          action='list',
                          filetype=filetype,
                          sep=request.params['sep'],
                          redirect=redirect))
        '''
        ### This block of code filters out nodes and instances, reduces occurances of 'ism's
        ### It is not currently necessary and causes an error in the middle 'elif' block.
        all_param = request.params.get('all', False)
        node_param = request.params.get('nodes', True)
        instance_param = request.params.get('instances', True)
        
        node_q = idea_q.join((Node,Node.concept_id==Idea.ID))
        instance_q = idea_q.join(Instance.idea)
        
        if all_param:
            idea_q = idea_q
            if not node_param:
                idea_q = idea_q.except_(node_q)
            if not instance_param:
                idea_q = idea_q.except_(instance_q)
        elif node_param:
            idea_q = node_q
            if instance_param:
                # ISSUE!!! This union causes an error when executing the query!... why?
                idea_q = idea_q.union(instance_q)
        elif instance_param:
            idea_q = instance_q
        '''

        c.total = idea_q.count()
        c.entities = idea_q.limit(limit)

        return render('idea/idea-list.' + filetype)