Пример #1
0
def register():
    """Registers a user if the email, username and invite code are valid."""
    logged_in = session.get('logged_in')
    if logged_in:
        flash('You already have an account.', 'info')
        return redirect(url_for('home'))

    form = RegisterForm()
    if form.validate_on_submit():
        code = InviteCode.query.filter_by(code=form.invite.data).first()
        if not code or not code.check_code():
            flash('Invalid code.', 'error')
            return redirect(url_for('users.register'))

        code.redeem_code()
        db.session.add(code)
        valid, message = check_username_and_email(form.email.data, form.username.data)

        if not valid:
            flash(message, "error")
            return redirect(url_for('users.login'))
        user = User(form.firstname.data, form.lastname.data, form.username.data,
                    form.email.data, form.password.data)
        
        add_model(user)
        flash('Your account has been created, {0}.'.format(user.firstname), 'success')
        return redirect(url_for('home'))
    return render_template('register.html', title='Sign Up', form=form)
Пример #2
0
def view_all():
    """View all uploaded documents in a grid layout."""
    documents = current_user.documents
    for doc in docs:
        if not doc.thumbnail:
            try:
                doc.set_thumbnail()
                add_model(doc)
            except CrocodocError:
                pass
    return render_template('all.html', docs=documents)
Пример #3
0
def home():
    """Home page view for anonymous and logged-in users."""
    logged_in = session.get("logged_in")
    if logged_in:
        docs = get_all(Document)
        for doc in docs:
            if not doc.thumbnail:
                try:
                    doc.set_thumbnail()
                    add_model(doc)
                except CrocodocError:
                    pass
        return render_template("user_home.html", user=current_user, docs=docs)
    return render_template("index.html")
Пример #4
0
def view_doc(doc_id):
    """View a specific document with Crocodoc, or edit the title."""
    doc = Document.query.get(doc_id)
    if current_user == doc.user:
        title_form = EditDocumentForm()
        file_form = UpdateDocumentForm()
    else:
        title_form = None
        file_form = None
    if title_form and title_form.validate_on_submit():
        doc.name = title_form.name.data
        add_model(doc)
        flash("Changed document name", 'info')
        return redirect(url_for('docs.view_doc', doc_id=doc.uid))
    return render_template('view_doc.html', doc=doc,
                           viewer_url="https://crocodoc.com/view/{0}".format(str(doc.get_croc_session(current_user))),
                           titleForm=title_form, fileForm=file_form)
Пример #5
0
def update_doc(doc_id):
    """Upload a new version of a document."""
    doc = Document.query.get(doc_id)
    form = UpdateDocumentForm()
    if form.validate_on_submit():

        file_obj = form.uploaded.data
        filename = insert_in_filename(werkzeug.secure_filename(file_obj.filename), "-{0}-rev.{1}".format(
            current_user.username, len(doc.versions)))
        upload_to_s3(file_obj, filename)
        s3path = make_s3_path(filename)

        version = Version(form.comment.data, s3path, croc.add_doc_to_croc(s3path), doc)

        add_model(version)
        flash("Added new version of {0}".format(doc.name), 'success')
        return redirect(url_for('docs.view_doc', doc_id=doc.uid))
    else:
        return redirect(url_for('docs.view_doc', doc_id=doc.uid))