Beispiel #1
0
def delete_category():
    cat_id = request.args.get('cat_id')
    if cat_id is not None and cat_id != '' and int(cat_id) > 1:
        if Category.get_cat(cat_id) is not None:
            db.session.delete(Category.get_cat(cat_id))
            db.session.commit()
    return redirect('/admin/category/')
Beispiel #2
0
def home():
    cat = Category()
    cat_list = cat.get_all_cat()
    query_result = db.session.query(Entry).filter(
        Entry.published == 1).order_by(Entry.created.desc()).all()
    return render_template('front-end/_index.html',
                           post_list=query_result,
                           cat_list=cat_list)
Beispiel #3
0
def category(cat_code):
    cat = Category()
    cat_list = cat.get_all_cat()
    if cat_code is not None and cat_code != '':
        entry_category = Entry.get_entry_by_cat(cat_code, 1)
    else:
        return redirect('/')
    return render_template('front-end/_category.html',
                           cat_list=cat_list,
                           entry_category=entry_category)
def category(cat_id=None):
    account = current_user.username
    page_title = 'Category'
    cat_list = Category.get_category_list()

    # Get category to edit
    if cat_id is not None and cat_id != '' and int(cat_id) > 0:
        if Category.get_cat(cat_id) is not None:
            cat = Category.get_cat(cat_id)
        else:
            cat = ''
    else:
        cat = ''
    return render_template('back-end/_category.html', page_title=page_title, cat_list=cat_list, cat=cat, account=account, current_user=current_user)
Beispiel #5
0
def entry_detail(entry_slug, id):
    cat = Category()
    cat_list = cat.get_all_cat()
    if id is not None and id != '' and int(id) > 0:
        if Entry.get_entry(id, 1) is not None and Entry.get_entry(
                id, 1).slug.lower() == entry_slug.lower():
            entry = Entry.get_entry(id, 1)
            related_posts = Entry.get_related_entry(id, entry.category.id)
        else:
            return redirect('/')
    else:
        return redirect('/')
    return render_template('front-end/_detail.html',
                           entry=entry,
                           cat_list=cat_list,
                           related_posts=related_posts)
Beispiel #6
0
def create_tables():
    db.create_all()

    db.session.add(Role(1, 'Admin'))
    db.session.add(Role(2, 'Teacher'))
    db.session.add(Role(3, 'Trainee'))

    # Add admin
    db.session.add(User())
    db.session.commit()

    # Add teacher
    user = User()
    teacher = user.insert_user(2, 'ducdan', 'ducdan123', 'dan', 'duc', '*****@*****.**', 'binh dinh', 'Viet Nam', 'RCBD', '*****@*****.**', 1)
    db.session.add(teacher)
    db.session.commit()

    # Add trainee
    user = User()
    trainee = user.insert_user(3, 'baotruong', 'baotruong123', 'bao', 'truong' , '*****@*****.**', 'hue', 'Viet Nam', 'softworld', '*****@*****.**', 1)
    db.session.add(trainee)
    db.session.commit()

    db.session.add(Course())
    db.session.add(Class())
    db.session.add(Category())
    db.session.add(Assignment())
    db.session.add(Resources())
    db.session.add(Announcement())
    db.session.add(Trainee_Assignment())
    db.session.commit()

    return redirect('/login/')
Beispiel #7
0
def create_tables():
    db.create_all()
    db.session.add(User())
    db.session.add(Category())
    db.session.add(Entry())
    db.session.commit()

    return redirect('/login/')
def add_category(cat_id=None):
    parent_id = request.form['parent_id']
    code = request.form['code']
    name = request.form['name']
    order = request.form['order']

    if cat_id is not None and cat_id != '' and int(cat_id) > 0:
        cat = Category.query.filter(Category.id != cat_id, Category.code == code).first()
        if cat:
            flash('This category code has already taken.', 'error')
            return redirect('%s%s' % ('/category/', cat_id))
        else:
            Category.update_cat(cat_id, parent_id, code, name, order)
            flash('Category has been updated successfully.', 'success')
    else:
        db.session.add(Category.insert_cat(parent_id, code, name, order))
        flash('Category has been created successfully.', 'success')
    db.session.commit()
    return redirect('/category/')
Beispiel #9
0
def admin_entry(id=None):
    if id is not None and id != '' and int(id) > 0:
        if Entry.get_entry(id) is not None:
            entry = Entry.get_entry(id)
            page_title = 'Update entry'
        else:
            return redirect('/admin/list_entry/')
    else:
        entry = None
        page_title = 'Add new entry'
    cat_list = Category.get_category_list()
    return render_template('back-end/_entry-form.html', page_title=page_title, cat_list=cat_list, entry=entry, account=current_user.username)
Beispiel #10
0
def form_announcement(id=None):
    if id is not None and id != '' and int(id) > 0:
        if Announcement.get_announcement(id) is not None:
            announcement = Announcement.get_announcement(id)
            page_title = 'Update announcement'
        else:
            return redirect('/list_announcement/')
    else:
        announcement = None
        page_title = 'Add new announcement'
    cat_list = Category.get_category_list()
    return render_template('back-end/_announcement-form.html',
                           page_title=page_title,
                           cat_list=cat_list,
                           announcement=announcement,
                           account=current_user.username,
                           current_user=current_user)