Esempio n. 1
0
    def admin(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)
        
        c.sepdirnew = False
        c.alreadysepdir = False

        redirect = request.params.get('redirect', False)
        add = request.params.get('add', False)
        limit = request.params.get('limit', None)
        entity_q = Session.query(Entity)
        c.found = False    
        c.custom = False
        c.new = False

        if request.params.get('q'):
            q = request.params['q']
            o = Entity.label.like(q)
            entity_q = entity_q.filter(o).order_by(func.length(Entity.label))
            # if only 1 result, go ahead and view that idea
            if redirect and entity_q.count() == 1:
                print "have a q, entityq count = 1"
                c.journal = h.fetch_obj(Journal, entity_q.first().ID)
                c.found = True
                id = c.journal.ID
                c.message = 'Entity edit page for journal ' + c.journal.name
                if request.params.get('entry_sep_dir'):
                        entry_sep_dir = request.params['entry_sep_dir']
                        if not (c.journal.sep_dir):
                            c.journal.sep_dir = request.params['entry_sep_dir']
                            c.sepdirnew = True
                        else:
                            c.alreadysepdir = True
                            c.entry_sep_dir = request.params['entry_sep_dir']
                            
                return render('admin/journal-edit.html')
            else: 
                print "That didn't journal."

        if id is None:
            print "I am here"
            c.message = "Please input an entity label using the search bar to the left."
            return render ('admin/idea-edit.html')
        else:
            c.journal = h.fetch_obj(Journal, id)
            c.found = True
            c.message = 'Entity edit page for journal ' + c.journal.name
            if request.params.get('entry_sep_dir'):
                entry_sep_dir = request.params['entry_sep_dir']
                if not (c.journal.sep_dir):
                    c.journal.sep_dir = request.params['entry_sep_dir']
                    c.sepdirnew = True
                else:
                    c.alreadysepdir = True
                    c.entry_sep_dir = request.params['entry_sep_dir']
                    
            return render ('admin/journal-edit.html') 
Esempio n. 2
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)
Esempio n. 3
0
    def admin(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        c.sepdirnew = False
        c.alreadysepdir = False

        redirect = request.params.get('redirect', False)
        add = request.params.get('add', False)
        limit = request.params.get('limit', None)
        entity_q = Session.query(Entity)
        c.found = False
        c.custom = False
        c.new = False

        if request.params.get('q'):
            q = request.params['q']
            o = Entity.label.like(q)
            entity_q = entity_q.filter(o).order_by(func.length(Entity.label))
            # if only 1 result, go ahead and view that idea
            if redirect and entity_q.count() == 1:
                print "have a q, entityq count = 1"
                c.journal = h.fetch_obj(Journal, entity_q.first().ID)
                c.found = True
                id = c.journal.ID
                c.message = 'Entity edit page for journal ' + c.journal.name
                if request.params.get('entry_sep_dir'):
                    entry_sep_dir = request.params['entry_sep_dir']
                    if not (c.journal.sep_dir):
                        c.journal.sep_dir = request.params['entry_sep_dir']
                        c.sepdirnew = True
                    else:
                        c.alreadysepdir = True
                        c.entry_sep_dir = request.params['entry_sep_dir']

                return render('admin/journal-edit.html')
            else:
                print "That didn't journal."

        if id is None:
            print "I am here"
            c.message = "Please input an entity label using the search bar to the left."
            return render('admin/idea-edit.html')
        else:
            c.journal = h.fetch_obj(Journal, id)
            c.found = True
            c.message = 'Entity edit page for journal ' + c.journal.name
            if request.params.get('entry_sep_dir'):
                entry_sep_dir = request.params['entry_sep_dir']
                if not (c.journal.sep_dir):
                    c.journal.sep_dir = request.params['entry_sep_dir']
                    c.sepdirnew = True
                else:
                    c.alreadysepdir = True
                    c.entry_sep_dir = request.params['entry_sep_dir']

            return render('admin/journal-edit.html')
Esempio n. 4
0
    def edit(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)

        c.thinker = h.fetch_obj(Thinker, id)
        
        return render('thinker/thinker-edit.html')
Esempio n. 5
0
    def _list_property(self,
                       property,
                       id,
                       filetype='html',
                       limit=False,
                       sep_filter=False,
                       type='idea'):
        c.idea = h.fetch_obj(Idea, id)

        limit = int(request.params.get('limit', limit))
        start = int(request.params.get('start', 0))
        sep_filter = request.params.get('sep_filter', sep_filter)
        property = getattr(c.idea, property)
        if sep_filter:
            property = property.filter(Entity.sep_dir != '')

        # TODO: Fix hacky workaround for the AppenderQuery vs. Relationship
        # property issue - upgrading SQLAlchemy may fix this by allowing us to
        # use len() in a smart way.
        try:
            c.total = property.count()
        except TypeError:
            c.total = len(property)

        if limit:
            property = property[start:start + limit]

        c.entities = property
        c.nodes = Session.query(Node).filter(
            Node.parent_id == None).order_by("name").all()
        return render('%s/%s-list.%s' % (type, type, filetype))
Esempio n. 6
0
    def list(self, filetype='html', redirect=False):
        thinker_q = Session.query(Thinker)
        c.query = ''
        c.sep = ''
        
        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'):
            c.query = request.params['q']
            thinker_q = thinker_q.filter(Thinker.name.like(u'%'+request.params['q']+'%'))
            # if only 1 result, go ahead and view that thinker
            if redirect and thinker_q.count() == 1:
                return self.view(thinker_q.first().ID, filetype)
        
        if request.params.get('sep'):
            thinker_q = thinker_q.filter(Thinker.sep_dir == request.params['sep'])
            c.sep = request.params['sep']
            # if only 1 result, go ahead and view that thinker
            if redirect and thinker_q.count() == 1:
                return self.view(thinker_q.first().ID, filetype)

        c.thinkers = thinker_q.all()
        return render('thinker/thinker-list.' + filetype)
Esempio n. 7
0
    def first_order(self,
                    id=None,
                    filetype='html',
                    limit=False,
                    sep_filter=False):

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

        limit = request.params.get('limit', limit)
        sep_filter = request.params.get('sep_filter', sep_filter)
        children = [child for ins in c.idea.nodes for child in ins.children]
        parents = [ins.parent for ins in c.idea.nodes if ins.parent]
        siblings = [child for ins in parents for child in ins.children]

        c.entities = []
        c.entities.extend(parents)
        c.entities.extend(children)
        c.entities.extend(siblings)

        if sep_filter:
            c.entities = [i.idea for i in c.entities if i.idea.sep_dir]
        else:
            c.entities = [i.idea for i in c.entities]

        if c.idea in c.entities:
            c.entities.remove(c.idea)

        c.total = len(c.entities)

        #c.nodes = Session.query(Node).filter_by(parent_id=0).order_by("Name")
        return render('idea/idea-list.' + filetype)
Esempio n. 8
0
    def search(self, id, id2=None):
        # Grab ID(s) from database and get their search string(s).
        c.entity = h.fetch_obj(Entity, id)
        if id2 is None:
            c.entity2 = None
        else:
            c.entity2 = h.fetch_obj(Entity, id2)
        
        #creating link ID(s) for Bing + Google manual search by removing parentheses

        if c.entity2 is None:
            c.entity2_url_label = '' 
        else:
            c.entity2_url_label = ((c.entity2.label).split('('))[0]
            

        c.entity_url_label  = ((c.entity.label).split('('))[0]       

        # Run searches
        try:
            c.sep = EntityController._search_sep(c.entity, c.entity2)
        except Exception as e:
            c.sep = None

        try:
            c.noesis = EntityController._search_noesis(c.entity, c.entity2)
        except:
            c.noesis = None
        # c.bing = EntityController._search_bing(c.entity, c.entity2)
        return render('entity/search.html')
Esempio n. 9
0
    def first_order(self, id=None, filetype='html', limit=False,
                    sep_filter=False):

        c.idea = h.fetch_obj(Idea, id)
         
        limit = request.params.get('limit', limit)
        sep_filter = request.params.get('sep_filter', sep_filter)
        children = [child for ins in c.idea.nodes 
                        for child in ins.children] 
        parents = [ins.parent for ins in c.idea.nodes if ins.parent]
        siblings = [child for ins in parents
                          for child in ins.children]

        c.ideas = []
        c.ideas.extend(parents)
        c.ideas.extend(children)
        c.ideas.extend(siblings) 

        if sep_filter:
            c.ideas = [i.idea for i in c.ideas if i.idea.sep_dir]
        else:
            c.ideas = [i.idea for i in c.ideas]

        if c.idea in c.ideas: 
            c.ideas.remove(c.idea)

        #c.nodes = Session.query(Node).filter_by(parent_id=0).order_by("Name")
        return render('idea/idea-list.' + filetype)
Esempio n. 10
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)
Esempio n. 11
0
    def evaluate(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)

        c.idea = h.fetch_obj(Idea, id, new_id=True)
        node_q = Session.query(Node).filter_by(concept_id=id)
        c.node = node_q.first()
        if request.environ.get('REMOTE_USER', False):
            user = h.get_user(request.environ['REMOTE_USER'])

            sq = Session.query(IdeaEvaluation.cons_id)
            sq = sq.filter(IdeaEvaluation.ante == c.idea)
            sq = sq.filter(IdeaEvaluation.uid == user.ID)
            sq = sq.subquery()

            to_evaluate = c.idea.related.outerjoin(
                (sq, Idea.ID == sq.c.cons_id))
            to_evaluate = to_evaluate.filter(sq.c.cons_id == None)

        else:
            to_evaluate = c.idea.related

        c.paginator = paginate.Page(to_evaluate,
                                    page=int(request.params.get('page', 1)),
                                    items_per_page=10,
                                    controller='idea',
                                    action='edit',
                                    id=id)

        response.headers['Access-Control-Allow-Origin'] = '*'

        return render('idea/idea-edit.html')
Esempio n. 12
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)
Esempio n. 13
0
    def document(self, filetype="html"):
        resp = request.environ.get("pylons.original_response")
        code = cgi.escape(request.GET.get("code", ""))
        content = cgi.escape(request.GET.get("message", ""))
        if resp:
            content = content or resp.body or literal(resp.status)
            code = code or cgi.escape(str(resp.status_int))
        if not code:
            raise Exception("No status code was found")

        req = request.environ.get("pylons.original_request")
        routing = req.environ.get("pylons.routes_dict")
        if routing:
            c.controller = routing.get("controller", None)
            c.id = routing.get("id", None)
            c.filetype = routing.get("filetype", "html")
            c.action = routing.get("action", "view")
        else:
            c.controller = None
            c.id = None
            c.filetype = "html"
            c.action = "view"

        c.code = code
        c.message = content
        return render("error." + c.filetype)
Esempio n. 14
0
    def data_integrity(self, filetype="html", redirect=False):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        idea_q = Session.query(Idea)
        c.ideas = list(idea_q)

        # Missing searchstring
        c.missing_string = [
            idea for idea in c.ideas if not getattr(idea, 'searchstring')
        ]

        # Missing searchpattern
        c.missing_pattern = [
            idea for idea in c.ideas if not getattr(idea, 'searchpattern')
        ]

        # Missing sep_dir
        c.missing_sep_dir = [
            idea for idea in c.ideas if not getattr(idea, 'sep_dir')
        ]

        # Duplicates
        c.duplicate = []
        c.sorted_ideas = sorted(c.ideas, key=lambda idea: idea.label)
        for i in range(len(c.sorted_ideas) - 1):
            if c.sorted_ideas[i].label == c.sorted_ideas[i + 1].label:
                c.duplicate.append(c.sorted_ideas[i])
                c.duplicate.append(c.sorted_ideas[i + 1])

        return render('idea/data_integrity.%s' % filetype)
Esempio n. 15
0
    def document(self, filetype='html'):
        resp = request.environ.get('pylons.original_response')
        code = cgi.escape(request.GET.get('code', ''))
        content = cgi.escape(request.GET.get('message', ''))
        if resp:
            content = literal(resp.status)
            code = code or cgi.escape(str(resp.status_int))
        if not code:
            raise Exception('No status code was found')
        
        req = request.environ.get('pylons.original_request')
        routing = req.environ.get('pylons.routes_dict')
        if routing:
            c.controller = routing.get('controller', None)
            c.id = routing.get('id', None)
            c.filetype = routing.get('filetype', 'html')
            c.action = routing.get('action', 'view')
        else:
            c.controller = None
            c.id = None
            c.filetype = 'html'
            c.action = 'view'

        c.code = code
        c.message = content
        return render('error.' + c.filetype)
Esempio n. 16
0
    def _list_property(self,
                       property,
                       id,
                       filetype='html',
                       limit=False,
                       sep_filter=False,
                       type='thinker'):
        c.thinker = h.fetch_obj(Thinker, id)

        limit = int(request.params.get('limit', limit))
        start = int(request.params.get('start', 0))
        sep_filter = request.params.get('sep_filter', sep_filter)
        property = getattr(c.thinker, property)
        if sep_filter:
            property = property.filter(Entity.sep_dir != '')

        try:
            c.total = property.count()
        except TypeError:
            c.total = len(property)

        if limit:
            property = property[start:start + limit]

        c.entities = property
        return render('%s/%s-list.%s' % (type, type, filetype))
Esempio n. 17
0
    def search(self, id, id2=None):
        # Grab ID(s) from database and get their search string(s).
        c.entity = h.fetch_obj(Entity, id)
        if id2 is None:
            c.entity2 = None
        else:
            c.entity2 = h.fetch_obj(Entity, id2)

        # creating link ID(s) for Bing + Google manual search by removing parentheses

        if c.entity2 is None:
            c.entity2_url_label = ""
        else:
            c.entity2_url_label = ((c.entity2.label).split("("))[0]

        c.entity_url_label = ((c.entity.label).split("("))[0]

        # Run searches
        try:
            c.sep = EntityController._search_sep(c.entity, c.entity2)
        except:
            c.sep = None

        try:
            c.noesis = EntityController._search_noesis(c.entity, c.entity2)
        except:
            c.noesis = None
        # c.bing = EntityController._search_bing(c.entity, c.entity2)
        return render("entity/search.html")
Esempio n. 18
0
    def list(self, filetype='html', redirect=False):
        thinker_q = Session.query(Thinker)
        c.query = ''
        c.sep = ''

        if request.params.get('sep_filter'):
            idea_q = idea_q.filter(Idea.sep_dir != '')

        # check for query
        if request.params.get('q'):
            c.query = request.params['q']
            thinker_q = thinker_q.filter(
                Thinker.name.like(u'%' + request.params['q'] + '%'))
            # if only 1 result, go ahead and view that thinker
            if redirect and thinker_q.count() == 1:
                return self.view(thinker_q.first().ID, filetype)

        if request.params.get('sep'):
            thinker_q = thinker_q.filter(
                Thinker.sep_dir == request.params['sep'])
            c.sep = request.params['sep']
            # if only 1 result, go ahead and view that thinker
            if redirect and thinker_q.count() == 1:
                return self.view(thinker_q.first().ID, filetype)

        c.thinkers = thinker_q.all()
        return render('thinker/thinker-list.' + filetype)
Esempio n. 19
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')
Esempio n. 20
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)
Esempio n. 21
0
 def _list_property(self, property, id, filetype='html', limit=False, sep_filter=False, type='idea'):
     c.idea = h.fetch_obj(Idea, id)
      
     limit = int(request.params.get('limit', limit))
     start = int(request.params.get('start', 0))
     sep_filter = request.params.get('sep_filter', sep_filter)
     property = getattr(c.idea, property)
     if sep_filter:
         property = property.filter(Entity.sep_dir != '')
     
     # TODO: Fix hacky workaround for the AppenderQuery vs. Relationship
     # property issue - upgrading SQLAlchemy may fix this by allowing us to
     # use len() in a smart way.
     try:
         c.total = property.count()
     except TypeError:
         c.total = len(property)
         
      
     if limit:
         property = property[start:start+limit]
     
     c.entities = property
     c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
     return render('%s/%s-list.%s' %(type, type, filetype))
Esempio n. 22
0
    def evaluate(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)

        c.idea = h.fetch_obj(Idea, id, new_id=True)
        node_q = Session.query(Node).filter_by(concept_id=id)
        c.node = node_q.first()
        if request.environ.get('REMOTE_USER', False):
            user = h.get_user(request.environ['REMOTE_USER'])

            sq = Session.query(IdeaEvaluation.cons_id)
            sq = sq.filter(IdeaEvaluation.ante==c.idea)
            sq = sq.filter(IdeaEvaluation.uid==user.ID)
            sq = sq.subquery()

            to_evaluate = c.idea.related.outerjoin((sq, Idea.ID==sq.c.cons_id))
            to_evaluate = to_evaluate.filter(sq.c.cons_id==None)

        else:
            to_evaluate = c.idea.related

        c.paginator = paginate.Page(
            to_evaluate,
            page=int(request.params.get('page', 1)),
            items_per_page=10,
            controller='idea',
            action='edit',
            id=id
        )


        return render('idea/idea-edit.html')
Esempio n. 23
0
    def edit(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)

        c.thinker = h.fetch_obj(Thinker, id)

        return render('thinker/thinker-edit.html')
Esempio n. 24
0
    def data_integrity(self, filetype="html", redirect=False):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        idea_q = Session.query(Idea)
        c.ideas = list(idea_q)

        # Missing searchstring
        c.missing_string = [idea for idea in c.ideas
                            if not getattr(idea, 'searchstring')]
        
        # Missing searchpattern
        c.missing_pattern = [idea for idea in c.ideas
                             if not getattr(idea, 'searchpattern')]
        
        # Missing sep_dir
        c.missing_sep_dir = [idea for idea in c.ideas
                             if not getattr(idea, 'sep_dir')]
            
        # Duplicates
        c.duplicate = []
        c.sorted_ideas = sorted(c.ideas, key=lambda idea: idea.label)
        for i in range(len(c.sorted_ideas) - 1):
            if c.sorted_ideas[i].label == c.sorted_ideas[i+1].label:
                c.duplicate.append(c.sorted_ideas[i])
                c.duplicate.append(c.sorted_ideas[i+1])
                    
        return render('idea/data_integrity.%s' % filetype)
Esempio n. 25
0
    def document(self, filetype='html'):
        resp = request.environ.get('pylons.original_response')
        code = cgi.escape(request.GET.get('code', ''))
        content = cgi.escape(request.GET.get('message', ''))
        if resp:
            content = content or resp.body or literal(resp.status)
            code = code or cgi.escape(str(resp.status_int))
        if not code:
            raise Exception('No status code was found')
        
        req = request.environ.get('pylons.original_request')
        routing = req.environ.get('pylons.routes_dict')
        if routing:
            c.controller = routing.get('controller', None)
            c.id = routing.get('id', None)
            c.filetype = routing.get('filetype', 'html')
            c.action = routing.get('action', 'view')
        else:
            c.controller = None
            c.id = None
            c.filetype = 'html'
            c.action = 'view'

        c.code = code
        c.message = content
        return render('error.' + c.filetype)
Esempio n. 26
0
    def edit(self):
        '''Renders the registration form.'''
        if not h.auth.is_logged_in():
            abort(401)

        c.user = h.get_user(request.environ['REMOTE_USER'])

        return render('account/edit.html')
Esempio n. 27
0
    def view(self, id, filetype='html'):
        sep_filter = request.params.get('sep_filter', False)
        c.sep_filter = sep_filter

        c.school_of_thought = h.fetch_obj(model.SchoolOfThought,
                                          id,
                                          new_id=True)
        return render('school_of_thought/school_of_thought.%s' % filetype)
Esempio n. 28
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)
Esempio n. 29
0
    def edit(self):
        '''Renders the registration form.'''
        if not h.auth.is_logged_in():
            abort(401)

        c.user = h.get_user(request.environ['REMOTE_USER'])

        return render('account/edit.html')
Esempio n. 30
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)
Esempio n. 31
0
    def view(self, id, filetype='html'):
        sep_filter = request.params.get('sep_filter', False) 
        c.sep_filter = sep_filter

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

        c.school_of_thought = h.fetch_obj(model.SchoolOfThought, id, new_id=True)
        return render('school_of_thought/school_of_thought.%s' % filetype)
Esempio n. 32
0
    def edit(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        c.work = h.fetch_obj(Work, id)
        
        return render('work/work-edit.html')
Esempio n. 33
0
    def edit(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        c.school_of_thought = h.fetch_obj(SchoolOfThought, id)

        return render('school_of_thought/school_of_thought-edit.html')
Esempio n. 34
0
    def graph(self, id=None, filetype='nwb', limit=False):
        c.sep_filter = request.params.get('sep_filter', False) 
        c.n = int(request.params.get('n', 8))
        c.recur = int(request.params.get('recur', 3))
        c.thresh = float(request.params.get('thresh', 0))

        c.idea = h.fetch_obj(Idea, id, new_id=True)
        
        return render('idea/graph.' + filetype)
Esempio n. 35
0
    def edit(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        c.school_of_thought = h.fetch_obj(SchoolOfThought, id)

        return render('school_of_thought/school_of_thought-edit.html')
Esempio n. 36
0
 def signout(self):
     ''' 
     Action to sign the user out. The actual signout happens when the
     middleware captures the request, so this function just displays a
     confirmation pageFor ``cookie`` authentication this
     function's routing must be added to the ``authkit.cookie.signoutpath``
     directive.
     '''
     return render('account/signedout.html')
Esempio n. 37
0
    def edit(self, id=None):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        c.work = h.fetch_obj(Work, id)

        return render('work/work-edit.html')
Esempio n. 38
0
    def view(self, id, filetype='html'):
        sep_filter = request.params.get('sep_filter', False) 
        c.sep_filter = sep_filter

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

        c.work = h.fetch_obj(Work, id, new_id=True)
        return render('work/work.%s' % filetype)
Esempio n. 39
0
 def signout(self):
     ''' 
     Action to sign the user out. The actual signout happens when the
     middleware captures the request, so this function just displays a
     confirmation pageFor ``cookie`` authentication this
     function's routing must be added to the ``authkit.cookie.signoutpath``
     directive.
     '''
     return render('account/signedout.html')
Esempio n. 40
0
    def graph(self, id=None, filetype='nwb', limit=False):
        c.sep_filter = request.params.get('sep_filter', False)
        c.n = int(request.params.get('n', 8))
        c.recur = int(request.params.get('recur', 3))
        c.thresh = float(request.params.get('thresh', 0))

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

        return render('idea/graph.' + filetype)
Esempio n. 41
0
    def view(self, id, filetype='html'):
        sep_filter = request.params.get('sep_filter', False) 
        c.sep_filter = sep_filter

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

        c.thinker = h.fetch_obj(Thinker, id, new_id=True)
        return render('thinker/thinker.%s' % filetype)
Esempio n. 42
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)
Esempio n. 43
0
    def data_integrity(self, filetype='html', redirect=False):
        if not h.auth.is_logged_in():
            abort(401)
        if not h.auth.is_admin():
            abort(403)

        journal_q = Session.query(Journal)
        
        # check for query
        if request.params.get('q'):
            journal_q = journal_q.filter(Journal.name.like(u'%'+request.params['q']+'%'))
        
        # get the list of journals
        c.journals = list(journal_q)

        c.missing_issn = []
        c.bad_issn = []
        for journal in c.journals:
            # Missing ISSN
            if not getattr(journal, 'ISSN') or journal.ISSN == '':
                c.missing_issn.append(journal)
            # Journal has bad ISSN format (xxxx-xxxx is good format)
            elif not re.match(r'[0-9]{4}-[0-9]{3}[0-9X]', journal.ISSN):
                c.bad_issn.append(journal)

        # Duplicates
        # It is set up for pairs. If there is more than 2 of the same journal it will have multiples
        c.duplicate = []
        c.sorted_journals = sorted(c.journals, key=lambda journal: journal.label)
        for i in range(len(c.sorted_journals) - 1):
            if c.sorted_journals[i].label == c.sorted_journals[i+1].label:
                c.duplicate.append(c.sorted_journals[i])
                c.duplicate.append(c.sorted_journals[i+1]) 

        # re-get the list of journals (only ones accessed in last 4 weeks)
        # Magic constant of 2419200 corresponds to 4 weeks in seconds
        c.journals = list(journal_q.filter(Journal.last_accessed < (time.time() -2419200)))

        # filter out results into different chunks
        # Valid URL, not found
        c.broken = [journal for journal in c.journals if journal.URL]
        
        # Journal is active, no URL set
        c.missing = [journal for journal in c.journals 
                     if journal.URL is None and journal.active]
        
        # Journal is active, URL is set to blank
        c.blank = [journal for journal in c.journals 
                   if journal.URL == '' and journal.active]
        
        # Jornal is inactive and missing URL
        c.inactive = [journal for journal in c.journals 
                      if journal.URL is None and not journal.active]
        
        return render('journal/data_integrity.' + filetype)
Esempio n. 44
0
    def graph_all(self, filetype='html', limit=False):
        sep_filter = request.params.get('sep_filter', False)
        c.sep_filter = sep_filter
        idea_q = Session.query(Idea)
        c.ideas = idea_q.all()

        edge_q =\
        Session.query(IdeaGraphEdge).order_by(IdeaGraphEdge.jweight.desc()).limit(3*len(c.ideas))
        c.edges = edge_q.all()

        return render('idea/graph_all.' + filetype)
Esempio n. 45
0
 def list(self, filetype='html', redirect=False):
     journal_q = Session.query(Journal)
     
     # check for query
     if request.params.get('q'):
         journal_q = journal_q.filter(Journal.name.like(u'%'+request.params['q']+'%'))
         # if only 1 result, go ahead and view that journal
         if redirect and journal_q.count() == 1:
             return self.view(journal_q.first().id, filetype)
     c.journals = list(journal_q)
     return render('journal/journal-list.' + filetype)
Esempio n. 46
0
    def index(self, id=None):
        #two kinds of functionality; either the entity is found or it is not
        #if found, user is given option to modify; if not found, user is given option to add
        c.found = False
        c.new = False
        c.custom = False

        if id is None:
            c.message = "Edit Idea Manager v1.0; please search for the idea label you would like to add or modify using the search bar to the left."

        return render('admin/idea-edit.html')
Esempio n. 47
0
    def view(self, id, filetype='html'):
        sep_filter = request.params.get('sep_filter', False)
        c.sep_filter = sep_filter

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

        c.school_of_thought = h.fetch_obj(model.SchoolOfThought,
                                          id,
                                          new_id=True)
        return render('school_of_thought/school_of_thought.%s' % filetype)
Esempio n. 48
0
 def graph_all(self, filetype='html', limit=False):
     sep_filter = request.params.get('sep_filter', False) 
     c.sep_filter = sep_filter
     idea_q = Session.query(Idea)
     c.ideas = idea_q.all()
     
     edge_q =\
     Session.query(IdeaGraphEdge).order_by(IdeaGraphEdge.jweight.desc()).limit(3*len(c.ideas))
     c.edges = edge_q.all()
     
     return render('idea/graph_all.' + filetype)
Esempio n. 49
0
 def index(self, id = None):
     #two kinds of functionality; either the entity is found or it is not
     #if found, user is given option to modify; if not found, user is given option to add
     c.found = False
     c.new = False
     c.custom = False
     
     if id is None:
         c.message = "Edit Idea Manager v1.0; please search for the idea label you would like to add or modify using the search bar to the left."
         
     return render ('admin/idea-edit.html')
Esempio n. 50
0
    def review(self):
        if not request.environ.get('REMOTE_USER', False):
            abort(401)
        
        c.user = h.get_user(request.environ['REMOTE_USER'])        

        ieq = Session.query(IdeaEvaluation).order_by(IdeaEvaluation.time.desc())
        c.evaluations = ieq.filter(and_(IdeaEvaluation.uid==c.user.ID,
                                   or_(IdeaEvaluation.generality>-1,
                                       IdeaEvaluation.relatedness>-1))).all()
        
        return render('account/review.html')
Esempio n. 51
0
    def list(self, filetype='html', redirect=False):
        journal_q = Session.query(Journal)

        # check for query
        if request.params.get('q'):
            journal_q = journal_q.filter(
                Journal.name.like(u'%' + request.params['q'] + '%'))
            # if only 1 result, go ahead and view that journal
            if redirect and journal_q.count() == 1:
                return self.view(journal_q.first().id, filetype)
        c.journals = list(journal_q)
        return render('journal/journal-list.' + filetype)
Esempio n. 52
0
    def signin(self):
        identity = request.environ.get('repoze.who.identity')
        if identity is not None:
            came_from = request.params.get('came_from', '')
            if request.environ.get('HTTP_REFERER', '').startswith(came_from)\
                or not came_from:
                redirect('/account/profile')
            if came_from:
                redirect(str(came_from))

        c.failed = request.url == request.environ.get('HTTP_REFERER','')

        return render('/account/signin.html')
Esempio n. 53
0
    def signin(self):
        identity = request.environ.get('repoze.who.identity')
        if identity is not None:
            came_from = request.params.get('came_from', '')
            if request.environ.get('HTTP_REFERER', '').startswith(came_from)\
                or not came_from:
                redirect('/account/profile')
            if came_from:
                redirect(str(came_from))

        c.failed = request.url == request.environ.get('HTTP_REFERER','')

        return render('/account/signin.html')
Esempio n. 54
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)
Esempio n. 55
0
    def related_entries(self, id, filetype="html"):
        c.entity = h.fetch_obj(Entity, id)

        related = sep.get_related()
        related = related[c.entity.sep_dir]

        c.entities = []
        for sep_dir in related:
            entity = Session.query(Entity).filter(Entity.sep_dir == sep_dir).first()
            if entity is not None:
                c.entities.append(entity)

        return render("entity/entity-list.%s" % (filetype))
Esempio n. 56
0
 def log_tests(self):
     checks = request.params
     count = int(request.params['count']) + 1
     if len(checks) == count:
         with open('/Users/alefrost/logfile.txt', 'a') as f:
             f.write('[' + strftime("%a, %d %b %Y %H:%M:%S", gmtime()) + '] ' + h.auth.username(request) + '\n')
         return render('admin/success.html')
     else:
         c.checked = []
         for key, value in checks.iteritems():
             if key == 'test':
                 c.checked.append(str(value))
         return self.tests()
Esempio n. 57
0
    def related_entries(self, id, filetype='html'):
        c.entity = h.fetch_obj(Entity,id)
        
        related = sep.get_related()
        related = related[c.entity.sep_dir]
       
        c.entities = [] 
        for sep_dir in related:
            entity = Session.query(Entity).filter(Entity.sep_dir==sep_dir).first()
            if entity is not None:
                c.entities.append(entity)


        return render('entity/entity-list.%s' %(filetype))
Esempio n. 58
0
    def classes(self, id=None, filetype='html', limit=False, sep_filter=False):
        c.idea = h.fetch_obj(Idea, id)

        limit = request.params.get('limit', limit)
        sep_filter = request.params.get('sep_filter', sep_filter)
        property = [child for ins in c.idea.nodes for child in ins.children]
        if limit:
            property = property[1:limit]
        if sep_filter:
            property = [i.idea for i in property if i.idea.sep_dir]

        c.ideas = property
        #c.nodes = Session.query(Node).filter_by(parent_id=0).order_by("Name")
        return render('idea/idea-list.' + filetype)
Esempio n. 59
0
 def _list_property(self, property, id, filetype='html', limit=False, sep_filter=False, type='idea'):
     c.idea = h.fetch_obj(Idea, id)
      
     limit = request.params.get('limit', limit)
     sep_filter = request.params.get('sep_filter', sep_filter)
     property = getattr(c.idea, property)
     if sep_filter:
         property = property.filter(Entity.sep_dir != '')
     if limit:
         property = property[0:limit-1]
     
     c.ideas = property
     c.nodes = Session.query(Node).filter(Node.parent_id == None).order_by("name").all()
     return render('%s/%s-list.%s' %(type, type, filetype))