Ejemplo n.º 1
0
def cms_update(unique_id):
    form = forms.DatabaseForm()
    post = models.Post.query.get(unique_id)

    if form.validate_on_submit():
        post.css_class = get_theme(form.color.data)
        post.title = bleach.clean(form.title.data)
        post.icon = form.icon.data
        post.subtitle = bleach.clean(form.subtitle.data)
        post.content = generate_markdown(form.content.data, True)
        post.month = form.month.data
        post.year = form.year.data
        db.session.commit()

        flash('The post titled %s has been updated!' % post.title)
        return redirect(url_for('cms'))

    form.color.data = post.css_class
    form.title.data = post.title
    form.icon.data = post.icon
    form.subtitle.data = post.subtitle
    form.content.data = post.content

    return render_template('/old-site/blog/cms/edit-post.html',
                           form=form,
                           post=post,
                           icons=dog_icons())
Ejemplo n.º 2
0
def cms_submit():
    form = forms.DatabaseForm()
    if not form.validate_on_submit():
        return render_template('/old-site/blog/cms/new-post.html',
                               icons=dog_icons(),
                               form=form)
    else:
        css_class = get_theme(form.color.data)
        title = bleach.clean(form.title.data)
        icon = form.icon.data
        subtitle = bleach.clean(form.subtitle.data)
        content = generate_markdown(form.content.data, True)
        date_string = form.hidden_date.data
        month = form.month.data
        year = form.year.data

        post = models.Post(css_class=css_class,
                           title=title,
                           icon=icon,
                           subtitle=subtitle,
                           date=date_string,
                           month=month,
                           content=content,
                           year=year)

        db.session.add(post)
        db.session.commit()

        flash('Your post titled %s has been added to the database!' % title)
        return redirect(url_for('cms'))
Ejemplo n.º 3
0
def cms():
    posts = models.Post.query.order_by(models.Post.id.desc()).all()
    link = '/logout'
    text = 'Logout'
    needs_approval = approval_notification()

    if posts:
        current_month = datetime.today().strftime('%B %Y')
        last_month = (datetime.today() - timedelta(weeks=4)).strftime('%B %Y')
        two_months_ago = (datetime.today() -
                          timedelta(weeks=8)).strftime('%B %Y')
        current_month_posts = []
        last_month_posts = []
        two_months_ago_posts = []
        older_posts = []
        statistics = stats(posts, 0)

        for post in posts:
            if get_recent_posts(post) == 'Current Month':
                current_month_posts.append(post)
            elif get_recent_posts(post) == 'Last Month':
                last_month_posts.append(post)
            elif get_recent_posts(post) == 'Two Months Ago':
                two_months_ago_posts.append(post)
            else:
                older_posts.append(post)

    # Placeholder code to be used in case of a blank DB
    else:
        current_month_posts = ''
        last_month_posts = ''
        two_months_ago_posts = ''
        older_posts = ''
        current_month = ''
        last_month = ''
        two_months_ago = ''
        statistics = ''

    return render_template('/old-site/blog/cms/cms.html',
                           icons=dog_icons(),
                           form=forms.DatabaseForm(),
                           current_month_posts=current_month_posts,
                           last_month_posts=last_month_posts,
                           two_months_ago_posts=two_months_ago_posts,
                           older_posts=older_posts,
                           current_month=current_month,
                           last_month=last_month,
                           two_months_ago=two_months_ago,
                           stats=statistics,
                           link=link,
                           text=text,
                           needs_approval=needs_approval,
                           title='CMS')
Ejemplo n.º 4
0
def new_post():
    form = forms.DatabaseForm()
    form.month.data = datetime.today().month
    form.year.data = datetime.today().year
    form.hidden_date.data = datetime.today().strftime('%A %B %d, %Y')
    # Grabbing most recent entry's primary key to determine next CSS class
    latest_id = models.Post.query.all()[-1].id + 1
    form.color.data = get_color(latest_id)
    link = '/cms'
    text = 'CMS'

    return render_template('/old-site/blog/cms/new-post.html',
                           form=form,
                           icons=dog_icons(),
                           link=link,
                           text=text,
                           title='New Post')
Ejemplo n.º 5
0
def cms_edit(unique_id):
    form = forms.DatabaseForm()
    post = models.Post.query.get(unique_id)
    link = '/cms'
    text = 'CMS'

    form.color.data = post.css_class
    form.icon.data = post.icon
    form.title.data = post.title
    form.subtitle.data = post.subtitle
    form.content.data = generate_markdown(post.content, True)
    form.hidden_date.data = post.date
    form.month.data = post.month
    form.year.data = post.year

    return render_template('/old-site/blog/cms/edit-post.html',
                           post=post,
                           form=form,
                           icons=dog_icons(),
                           link=link,
                           text=text,
                           title='Edit Post')