Exemplo n.º 1
0
def landing_page(id, etype=None, slug=None):
    ent = Entity.query.filter(Entity.id == id).first()

    if not ent:
        raise NotFoundException()

    if etype and etype != ent.type:
        raise NotFoundException()

    if slug:
        if not kvstore.get('titles_enabled'):
            raise NotFoundException()
        elif slug != ent.slug:
            raise NotFoundException()

    docs = ent.documents
    #docs = filter(lambda doc: doc.enabled, docs)
    if kvstore.get('titles_enabled'):
        title = ent.title if ent.title else 'Untitled'
    else:
        title = ent.id

    return render_template('landing.html',
                           title=title,
                           documents=docs)
Exemplo n.º 2
0
def admin_settings(form=None):
    if not form:
        form = SettingsForm(data={'default_notice':kvstore.get('default_notice'),
                                  'titles_enabled':kvstore.get('titles_enabled'),
                                  'logo_url':kvstore.get('logo_url'),
                                  'domains':kvstore.get('domains')})

    return render_template('resolver/settings.html', title='Settings',
                           form=form, version=VERSION)
Exemplo n.º 3
0
def admin_settings(form=None):
    if not form:
        form = SettingsForm(
            data={
                'default_notice': kvstore.get('default_notice'),
                'titles_enabled': kvstore.get('titles_enabled'),
                'logo_url': kvstore.get('logo_url'),
                'domains': kvstore.get('domains')
            })

    return render_template('resolver/settings.html',
                           title='Settings',
                           form=form,
                           version=VERSION)
Exemplo n.º 4
0
    def persistent_uri(self):
        uri = app.config['BASE_URL']
        uri += '/collection/%s/representation/%s/%s' % (self.entity.type,
                                                        self.entity_id,
                                                        self.order)

        p = urlparse.urlparse(uri, 'http')
        netloc = p.netloc or p.path
        path = p.path if p.netloc else ''
        p = urlparse.ParseResult('http', netloc, path, *p[3:])
        uri = p.geturl()

        uris = [uri]

        if kvstore.get('titles_enabled'):
            uris.append(uri+'/'+self.entity.slug)
        if self.reference:
            uri = app.config['BASE_URL'] + '/collection/%s/representation/%s' % (self.entity.type, self.entity_id)

            p = urlparse.urlparse(uri, 'http')
            netloc = p.netloc or p.path
            path = p.path if p.netloc else ''
            p = urlparse.ParseResult('http', netloc, path, *p[3:])
            uri = p.geturl()

            uris.append(uri)

        return uris
Exemplo n.º 5
0
    def persistent_uri(self):
        uri = app.config['BASE_URL']
        uri += '/collection/%s/representation/%s/%s' % (
            self.entity.type, self.entity_id, self.order)

        p = urlparse.urlparse(uri, 'http')
        netloc = p.netloc or p.path
        path = p.path if p.netloc else ''
        p = urlparse.ParseResult('http', netloc, path, *p[3:])
        uri = p.geturl()

        uris = [uri]

        if kvstore.get('titles_enabled'):
            uris.append(uri + '/' + self.entity.slug)
        if self.reference:
            uri = app.config[
                'BASE_URL'] + '/collection/%s/representation/%s' % (
                    self.entity.type, self.entity_id)

            p = urlparse.urlparse(uri, 'http')
            netloc = p.netloc or p.path
            path = p.path if p.netloc else ''
            p = urlparse.ParseResult('http', netloc, path, *p[3:])
            uri = p.geturl()

            uris.append(uri)

        return uris
Exemplo n.º 6
0
def admin_list_entities(form=None, show_form=None):
    if "application/json" in request.headers["Accept"]:
        return admin_list_entities_dynamic()

    # entities = Entity.query.all()
    form = form if form else EntityForm()
    return render_template("resolver/entities.html", title="Entities", # entities=entities,
                           form=form, titles_enabled=kvstore.get('titles_enabled'),
                           show_form=show_form)
Exemplo n.º 7
0
def document_representation(id, etype=None, opt=None, num=None, slug=None):
    ent = Entity.query.filter(Entity.id == id).first()

    if not ent:
        raise NotFoundException()
    if etype and ent.type != etype:
        raise NotFoundException()

    if opt:
        # opt can be num or slug
        # how do we differentiate between num and slug?
        # We could try to check if num is parseable as an int, but slug could be
        # parseable as an int also
        # Solution: try to parse as int, if parseable =>
        #   treat it as num, not as slug (even if it is the slug)
        try:
            num = int(opt)
            doc = Representation.query.filter(Representation.order == num,
                                              Document.entity_id == id).first()
        except ValueError:
            # opt == slug
            if kvstore.get('titles_enabled') and\
               ent.slug != opt:
                raise NotFoundException()

            doc = Representation.query.filter(Representation.reference == True,
                                              Document.entity_id == id).first()
    elif num:
        # num also implies slug
        if kvstore.get('titles_enabled') and\
           ent.slug != slug:
            raise NotFoundException()

        doc = Representation.query.filter(Representation.order == num,
                                          Document.entity_id == id).first()
    else:
        # only ID
        doc = Representation.query.filter(Representation.reference == True,
                                          Document.entity_id == id).first()
    if not doc:
        raise NotFoundException()

    return show_document(doc)
Exemplo n.º 8
0
def admin_view_entity(id, form=None):
    ent = Entity.query.filter(Entity.id == id).first()
    if ent:
        form = form if form else EntityForm(obj=ent)
        return render_template("resolver/entity.html", title="Entity",
                               entity=ent, documents=ent.documents, form=form,
                               data_formats=data_formats, new_form=EntityForm(),
                               titles_enabled=kvstore.get('titles_enabled'))
    else:
        flash("Entity not found!", "danger")
        return redirect("/resolver/entity")
Exemplo n.º 9
0
def admin_list_entities(form=None, show_form=None):
    if "application/json" in request.headers["Accept"]:
        return admin_list_entities_dynamic()

    # entities = Entity.query.all()
    form = form if form else EntityForm()
    return render_template(
        "resolver/entities.html",
        title="Entities",  # entities=entities,
        form=form,
        titles_enabled=kvstore.get('titles_enabled'),
        show_form=show_form)
Exemplo n.º 10
0
def show_document(doc):
    hit = DocumentHit(doc.id, request.remote_addr, request.referrer)
    db.session.add(hit)
    db.session.commit()

    if doc.enabled:
        if doc.url:
            return redirect(doc.url, code=303)
        else:
            title = "No link"
    else:
        title = "Link disabled"

    if doc.notes:
        message = doc.notes
    else:
        message = False

    return render_template("notice.html", title=title, message=message,
                           default_notice=kvstore.get('default_notice_clean'),
                           logo_url=kvstore.get('logo_url'))
Exemplo n.º 11
0
def document_data(id, etype=None, opt=None, format=None, slug=None):
    ent = Entity.query.filter(Entity.id == id).first()
    if not ent:
        raise NotFoundException()
    if etype and ent.type != etype:
        raise NotFoundException()

    if opt:
        # opt can be format or slug
        # what if the slug is 'html'?
        # Solution: if opt is in data_formats =>
        #   treat as format, not as slug (even if it is the slug)
        if opt in data_formats:
            doc = Data.query.filter(Document.entity_id == id,
                                    Data.format == opt).first()
        else:
            if kvstore.get('titles_enabled') and\
               ent.slug != opt:
                raise NotFoundException()

            doc = Data.query.filter(Document.entity_id == id,
                                    Data.format == DEFAULT_FORMAT).first()
    elif format:
        # format also implies slug
        if kvstore.get('titles_enabled') and\
           ent.slug != slug:
            raise NotFoundException()

        doc = Data.query.filter(Document.entity_id == id,
                                Data.format == format).first()
    else:
        # only ID
        doc = Data.query.filter(Document.entity_id == id,
                                Data.format == DEFAULT_FORMAT).first()

    if not doc:
        raise NotFoundException()

    return show_document(doc)
Exemplo n.º 12
0
    def persistent_uri(self):
        url = app.config['BASE_URL'] + '/collection/%s' % self.id

        p = urlparse.urlparse(url, 'http')
        netloc = p.netloc or p.path
        path = p.path if p.netloc else ''
        p = urlparse.ParseResult('http', netloc, path, *p[3:])
        url = p.geturl()

        if kvstore.get('titles_enabled'):
            return [url, url + '/%s' % self.slug]
        else:
            return [url]
Exemplo n.º 13
0
def admin_view_entity(id, form=None):
    ent = Entity.query.filter(Entity.id == id).first()
    if ent:
        form = form if form else EntityForm(obj=ent)
        return render_template("resolver/entity.html",
                               title="Entity",
                               entity=ent,
                               documents=ent.documents,
                               form=form,
                               data_formats=data_formats,
                               new_form=EntityForm(),
                               titles_enabled=kvstore.get('titles_enabled'))
    else:
        flash("Entity not found!", "danger")
        return redirect("/resolver/entity")
Exemplo n.º 14
0
    def persistent_uri(self):
        uri = app.config['BASE_URL']
        uri += '/collection/%s/data/%s/%s' % (self.entity.type, self.entity_id,
                                              self.format)

        p = urlparse.urlparse(uri, 'http')
        netloc = p.netloc or p.path
        path = p.path if p.netloc else ''
        p = urlparse.ParseResult('http', netloc, path, *p[3:])
        uri = p.geturl()

        uris = [uri]

        if kvstore.get('titles_enabled'):
            uris.append(uri + '/' + self.entity.slug)
        if self.format == 'html':
            uris.append(uri[:-5])

        return uris
Exemplo n.º 15
0
    def persistent_uri(self):
        uri = app.config['BASE_URL']
        uri += '/collection/%s/data/%s/%s' % (self.entity.type, self.entity_id,
                                              self.format)

        p = urlparse.urlparse(uri, 'http')
        netloc = p.netloc or p.path
        path = p.path if p.netloc else ''
        p = urlparse.ParseResult('http', netloc, path, *p[3:])
        uri = p.geturl()

        uris = [uri]

        if kvstore.get('titles_enabled'):
            uris.append(uri+'/'+self.entity.slug)
        if self.format == 'html':
            uris.append(uri[:-5])

        return uris