Example #1
0
def search_dasboard_category():

    data = []
    form = dashboard_searchform.DashboardSearchForm()

    if request.method == 'POST' and form.validate_on_submit():
        if request.form['query'] is not None:
            data_array = sql.session.query(Categories).filter(
                Categories.category_title.match(request.form['query'])).all()
            for x in data_array:
                data = x

            return jsonify(id=str(data.id),
                           title=data.category_title,
                           author=data.category_author,
                           category=data.category_category,
                           date=data.category_date)
Example #2
0
def search_dasboard_inner():

    data = []
    form = dashboard_searchform.DashboardSearchForm()

    if request.method == 'POST' and form.validate_on_submit():

        data_array = sql.session.query(Content).filter(
            Content.content_title.match(request.form['query'])).all()
        for x in data_array:
            data = x

        return jsonify(id=str(data.id),
                       title=data.content_title,
                       author=data.content_author,
                       category=data.content_category,
                       date=data.content_date)
    else:
        return False
Example #3
0
def search_dasboard_main():

    data = []
    form = dashboard_searchform.DashboardSearchForm()

    if request.method == 'POST' and form.validate_on_submit():

        data_array = sql.session.query(Articles).filter(
            Articles.article_title.match(request.form['query'])).all()
        for x in data_array:
            data = x

        return jsonify(id=str(data.id),
                       title=data.article_title,
                       author=data.article_author,
                       category=data.article_category,
                       date=data.article_date)
    else:
        return redirect(url_for('show_dashboard_main'))
Example #4
0
def search_dasboard_users():

    data = []
    form = dashboard_searchform.DashboardSearchForm()

    if request.method == 'POST' and form.validate_on_submit():

        data_array = sql.session.query(Users).filter(
            Users.login.match(request.form['query'])).all()
        for x in data_array:
            data = x.login
            data = x.email
            data = x.regdate
            data = x.usr_level

        return jsonify(id=str(data.id),
                       title=data.login,
                       author=data.regdate,
                       date=data.regdate)
    else:
        return False
Example #5
0
def update_dashboard_inner():
    form = dashboard_itemsform.DashboardItemsForm()
    form_next = dashboard_searchform.DashboardSearchForm()
    author = g.user
    conn = engine.connect()

    if request.method == 'POST':
        if form.rename.data and form.validate_on_submit():
            checkboxes = request.form.getlist('item_chb')

            # form.delid.data is the unicode list thing which
            # we convert to integer using regexp
            delid = int(re.search("\d+", str(form.delid.data)).group())

            if author is not None:
                articles = Content.query.all()
                n = None
                for x in checkboxes:

                    # x is the unicode list thing which
                    # we convert to integer using regexp
                    x = int(re.search("\d+", str(x)).group())

                    for art_id in articles:
                        if art_id.id == x:
                            n = art_id.id
                    if x == n and x != delid:
                        stmt = update(Content).where(Content.id == x).values(
                            id=delid)
                        try:
                            conn.execute(stmt)
                            conn.close()
                            flash(
                                "Item {} is changed to {}".format(
                                    x, form.delid.data), 'info')
                        except exc.IntegrityError:
                            flash("Item {} is exists".format(delid), 'error')
                    elif x == delid:
                        flash("Item {} is exists".format(delid), 'error')
                    else:
                        flash(
                            "Item {} is not changed to {}".format(
                                x, form.delid.data), 'error')
            else:
                return redirect(url_for('show_login'))
            return redirect(url_for('show_dashboard_inner'))

        elif form.rename.data is True and form.validate_on_submit() is False:
            flash("No item selected", 'error')
            return redirect(url_for('show_dashboard_inner'))

        elif form.delete.data and form.validate_on_submit():
            checkboxes = request.form.getlist('item_chb')

            if author is not None:
                articles = Content.query.all()
                n = None
                for x in checkboxes:

                    # x is the unicode list thing which
                    # we convert to integer using regexp
                    x = int(re.search("\d+", str(x)).group())

                    for art_id in articles:
                        if art_id.id == x:
                            n = art_id.id
                    if x == n:
                        stmt = delete(Content).where(Content.id == x)
                        conn.execute(stmt)
                        conn.close()
                        flash("Item {} is deleted!".format(x), 'info')
                    elif x == n:
                        flash("Item {} is exists".format(x), 'error')
                    else:
                        flash("Item {} is not deleted!".format(x), 'error')
            else:
                return redirect(url_for('show_login'))
            return redirect(url_for('show_dashboard_inner'))

        elif form.delete.data is True and form.validate_on_submit() is False:
            flash("No item selected", 'error')
            return redirect(url_for('show_dashboard_inner'))
        elif form_next.validate_on_submit():
            data = []
            data_array = sql.session.query(Content).filter(
                Content.content_title.match(form_next.query.data)).all()
            if data_array:
                for x in data_array:
                    data = x

                return jsonify(id=str(data.id),
                               title=data.content_title,
                               author=data.content_author,
                               category=data.content_category,
                               date=data.content_date,
                               published=data.published)
            else:
                return redirect(url_for('show_dashboard_inner'))

    return render_template('adminboard/adminboard_inner.html', form=form)