Пример #1
0
def documentViewer(id):
    try:
        document = Document().getObjectsByKey("_id", id)[0]
    except Exception as e:
        print e
        return abort(404)

    document.accessed = datetime.datetime.now()
    document.vanillaSave()

    annotations = Annotation().getObjectsByKey("document", id)
    cases = Case().matchObjects({})

    categories = Category().matchObjects({})
    annotations.sort(key=lambda a: a.location[0])
    document.contents = Pandoc().convert("markdown_github", "html",
                                         document.contents)

    document.highlightArticles()

    return render_template("documents/viewer.html",
                           name="Document",
                           document=document,
                           cases=cases,
                           annotations=annotations,
                           categories=categories)
Пример #2
0
def documentDownload(id, filetype):
    try:
        document = Document().getObjectsByKey("_id", id)[0]
    except:
        return abort(404)

    return document.download(filetype, login.current_user)
Пример #3
0
def index():
    users = User().matchObjects({}, limit=5)
    documents = Document().matchObjects({},
                                        limit=10,
                                        fields={
                                            "title": True,
                                            "author": True,
                                            "secure": True,
                                            "summary": True,
                                            "document_type": True
                                        })

    # Parse blog feed
    blogRssUrl = "http://blog.yuras.nl/rss/"
    blogFeed = feedparser.parse(blogRssUrl)

    news = {}
    for entry in blogFeed.entries:
        news[entry.link] = entry.title

    return render_template("homepage/index.html",
                           name="Dashboard",
                           users=users,
                           documents=documents,
                           news=news,
                           active="dashboard")
Пример #4
0
def documentDelete(id):
    try:
        document = Document().getObjectsByKey("_id", id)[0]
    except:
        return abort(404)

    document.remove()

    return json.dumps({
        "success": "true",
        "new_csrf": generate_csrf_token()
    })
Пример #5
0
def documentRelated(id):
    try:
        document = Document().matchObjects({"_id": id},
                                           fields={
                                               "_id": True,
                                               "contents": True,
                                               "tags": True
                                           })[0]
    except Exception as e:
        print e
        return abort(404)

    return document.getRelatedDocumentsByTags()
Пример #6
0
def documentsTable(amount, page):
    fields = {
        "title": True,
        "_created": True,
        "author": True,
        "secure": True,
        "_id": True
    }
    documents = Document().matchObjects({},
                                        limit=int(amount),
                                        skip=int(page) * int(amount),
                                        fields=fields)
    return render_template("documents/table.html", documents=documents)
Пример #7
0
def documentArticles(id):
    try:
        document = Document().matchObjects({"_id": id},
                                           fields={
                                               "_id": True,
                                               "title": True,
                                               "category": True,
                                               "contents": True,
                                               "tags": True,
                                               "wordcount": True
                                           })[0]
    except Exception as e:
        traceback.print_exc(file=sys.stdout)
        return abort(404)

    return json.dumps(document.getArticlesFromContent())
Пример #8
0
def documentTFIDF(id):
    try:
        document = Document().matchObjects({"_id": id},
                                           fields={
                                               "_id": True,
                                               "title": True,
                                               "category": True,
                                               "contents": True,
                                               "tags": True,
                                               "wordcount": True
                                           })[0]
    except Exception as e:
        traceback.print_exc(file=sys.stdout)
        return abort(404)

    return document.documentAnalysis()
Пример #9
0
def documentsJSON(amount, page):
    fields = {
        "title": True,
        "_created": True,
        "author": True,
        "secure": True,
        "_id": True
    }
    documents = Document().matchObjects({},
                                        limit=int(amount),
                                        skip=int(page) * int(amount),
                                        fields=fields)
    return json.dumps([
        dict([(f, str(getattr(d, f, None))) for f in fields if fields[f]])
        for d in documents
    ])
Пример #10
0
def fullTFIDFRun():
    print "Performing total TFIDF run."
    allDocuments = Document().matchObjects({},
                                           fields={
                                               "_id": True,
                                               "title": True,
                                               "category": True,
                                               "contents": True,
                                               "wordcount": True,
                                               "articles": True
                                           })

    for d in allDocuments:
        print "TFIDF for", d.title,
        d.tfidf(allDocuments=allDocuments)
        print len(d.tags), "results"

    return json.dumps({"success": "true"})
Пример #11
0
def fullArticlesRun():
    print "Performing total articles run."
    allDocuments = Document().matchObjects({},
                                           fields={
                                               "_id": True,
                                               "title": True,
                                               "category": True,
                                               "contents": True,
                                               "tags": True,
                                               "wordcount": True
                                           })

    for d in allDocuments:
        print "Articles for", d.title,
        d.getArticlesFromContent()
        print len(d.articles), "results"

    return json.dumps({"success": "true"})
Пример #12
0
def documentSave(id):
    try:
        document = Document().getObjectsByKey("_id", id)[0]
    except:
        document = None

    title = request.form.get("title", "").encode('utf-8')
    contents = request.form.get("contents", "").encode('utf-8')
    category = request.form.get("category", "").encode('utf-8')
    annotations = request.form.get("annotations", "").encode('utf-8')

    document.author = login.current_user.username

    if document.save(title, contents, category, annotations):
        return json.dumps({
            "success": "true",
            "new_csrf": generate_csrf_token()
        })

    return abort(500)
Пример #13
0
def userProfile():
    error = request.args.get("error", None)
    passwordError = None
    passwordErrors = {
        "password-toocommon":
        "The password you tried to use was is too common.",
        "password-incorrect": "The old password you provided was incorrect",
        "password-nomatch": "The new passwords you sent don't match up.",
        "password-tooshort": "The password you're trying too use is too short."
    }
    if error is not None:
        passwordError = passwordErrors.get(error, None)

    documents = Document().getObjectsByKey("author",
                                           login.current_user.username,
                                           limit=10)
    return render_template("users/profile.html",
                           name="Your profile page",
                           user=login.current_user,
                           documents=documents,
                           passwordError=passwordError,
                           success=request.args.get("success", None),
                           active="profile")
Пример #14
0
def lawViewer(id):
    try:
        document = Document().getObjectsByKey("_id", id)[0]
    except Exception as e:
        print e
        return abort(404)

    document.accessed = datetime.datetime.now()
    document.vanillaSave()

    cases = Case().matchObjects({})

    categories = Category().matchObjects({})
    document.contents = Pandoc().convert("markdown_github", "html",
                                         document.contents)

    document.highlightArticles()

    return render_template("documents/law.html",
                           name="Law",
                           document=document,
                           cases=cases,
                           categories=categories)
Пример #15
0
def documentQuickSearch():
    keywords = request.args.get("keywords", "").split(" ")
    return Document().quickSearch(keywords)
Пример #16
0
def documentNew():
    doc = Document()
    doc.author = login.current_user.username
    doc.save()
    _id = doc._id
    return redirect("/documents/%s" % _id)