Exemplo n.º 1
0
def page_edit(id):
    content = Content.query.filter_by(id=id).first()
    form = ContentForm()
    if form.validate_on_submit():
        content = Content.query.filter_by(id=id).first()
        content.body = form.body.data
        content.title = form.title.data
        db.session.commit()
    else:
        form.title.data = content.title
        form.body.data = content.body

    return render_template('page/edit.html', title="Side redigering", content=content, form=form)
Exemplo n.º 2
0
def index(request):
    if request.method == 'POST':
        form = ContentForm(request.POST)
        # Check the validity of the form
        if form.is_valid():
            content = form.cleaned_data['content']
            if not Content.objects.filter(content=content).exists():
                content = form.save(commit=False)
                content.save()
                messages.success(request, 'Content submitted successfully.')
                return HttpResponseRedirect('/user/')
            else:
                form.add_error(field='content', error="Duplicated value")

        interests = Interest.objects.all()
        return render(request, 'interest.html', {
            'form': form,
            'interests': interests
        })
    else:
        interests = Interest.objects.all()
        form = ContentForm()
        return render(request, "index.html", {
            "interests": interests,
            "form": form
        })
Exemplo n.º 3
0
def content():
    form = ContentForm()
    if form.validate_on_submit():
        print(form.fest.data)
        print(form.picture.data)
        picture_file = save_picture(form.picture.data)
        post = Post(fest=form.fest.data,
                    content=form.content.data,
                    image_file=picture_file)
        db.session.add(post)
        db.session.commit()
        flash('Content Posted', 'success')
        return redirect(url_for('home'))
    return render_template('content.html', title='Content', form=form)
Exemplo n.º 4
0
def draft_view_readonly(art_id, draft_id):

    # print("Request made")
    draft = Draft.query.get(draft_id)
    article = Article.query.get(art_id)
    form = ContentForm()

    if article.author != g.user:
        return redirect(url_for('admin.index'))

    path = ''.join([
        'app/documents/',
        article.folder])

    file_path = os.path.join(os.getcwd(), path)

    if not os.path.exists(file_path):
        os.makedirs(file_path)

    file_path_new = ''.join([str(file_path), '/revision_', str(draft.revision_number), '.md'])

    return render_template(
            'admin/draft_detail.html',
            fp=''.join(['/documents/', article.folder, '/revision_', str(draft.revision_number), '.md']),
            # title = article.title,
            form=form, read_only=True)
Exemplo n.º 5
0
def listing(id):
    p = Produce.query.all()
    s = Supplier.query.all()
    listing = Listing.query.get(id)
    form = ContentForm()
    if form.validate_on_submit():
        content = Content(quantity=form.quantity.data,
                          cart=current_user,
                          list=listing)
        db.session.add(content)
        db.session.commit()
        return redirect(url_for('browse'))
    return render_template('listing.html',
                           listing=listing,
                           produce=p,
                           supplier=s,
                           title='Listing',
                           form=form)
Exemplo n.º 6
0
def update_content(post_id):
    post = Post.query.get_or_404(post_id)
    form = ContentForm()

    if form.validate_on_submit():
        post.fest = form.fest.data
        post.content = form.content.data
        if form.picture.data:
            delete_picture(post.image_file)
            picture_file = save_picture(form.picture.data)
            post.image_file = picture_file
        db.session.commit()
        flash('Your Content Has been updated', 'success')
        return redirect(url_for('home'))
    elif request.method == 'GET':
        form.fest.data = post.fest
        form.content.data = post.content
    return render_template('content.html', title='Update Content', form=form)
Exemplo n.º 7
0
def draft_view(art_id, draft_id):
    print(request.method)
    # if request.method == 'POST':
    #     print("POSTED")
    # elif request.method == 'GET':
    #     print('GIT GUD')
    draft = Draft.query.get(draft_id)
    article = Article.query.get(art_id)
    form = ContentForm()

    if article.author != g.user:
        return redirect(url_for('admin.index'))

    path = ''.join([
        'app/admin/documents/',
        article.folder])

    file_path = os.path.join(os.getcwd(), path)

    if not os.path.exists(file_path):
        os.makedirs(file_path)

    file_path_new = ''.join([str(file_path), '/revision_', str(draft.revision_number), '.md'])

    if form.validate_on_submit():
        print("Form received")
        content = form.file_content.data
        print(content)
        with open(file_path_new, mode='w') as f:
            f.write(content)

        flash("Draft saved")
        return redirect(url_for('admin.draft_view', art_id=article.id, draft_id=draft.id))

    return render_template(
            'admin/draft_detail.html',
            fp=''.join(['/admin/documents/', article.folder, '/revision_', str(draft.revision_number), '.md']),
            # title=article.title,
            art_id=art_id,
            draft_id=draft_id,
            form=form, read_only=False)
Exemplo n.º 8
0
def index():
    # once decorated with login_required
    # it will check if current session["user_id"] is none
    # if none is true, login_required with redirect to /login
    # if not none, allow access to route
    form = ContentForm()
    user = session["user_id"]
    return render_template("index.html",
                           title="Home",
                           user=user,
                           password=userdata[0]['password'],
                           hashed_pwd=userdata[0]['hashed_pwd'],
                           form=form)
Exemplo n.º 9
0
def manage():
    title = "Manage"
    IPStore(title)
    footer = "These forms are used to create new objects within the SQLite3 database and to edit existing objects."
    projects = Project.query.all()
    blogs = Blog.query.all()
    reviews = Review.query.all()
    songs = Music.query.all()
    content = [projects, blogs, reviews, songs]
    users = User.query.all()
    form = ContentForm()
    musicform = MusicForm()
    return render_template('pages/manage.html',
                           title=title,
                           content=content,
                           form=form,
                           musicform=musicform,
                           projects=projects,
                           blogs=blogs,
                           reviews=reviews,
                           users=users,
                           songs=songs,
                           footer=footer)