Exemple #1
0
def login():
    if 'back' in request.query:
        back = request.query['back']
    else:
        back = '/'
    if app.current_user is not None:
        app.flash(
            'Log out from current session in order to use different account',
            category='info',
        )
        redirect(back)
    if request.method == 'POST':
        try:
            user = User.get(User.mail == post_get('email'))
        except DoesNotExist:
            app.flash('No such user')
        else:
            if user.user_password == User.encode_password(
                    post_get('password')):
                app.flash('Successfully logged in')
                app.login(user)
                redirect(back)
            else:
                app.flash('Wrong password', category='info')

    template = env.get_template('user/login.html')

    return template.render()
Exemple #2
0
def post_edit(post_id):
    if request.method == 'GET':
        try:
            post = Post.get(Post.post_id == post_id)  # todo: get not deleted
        except Post.DoesNotExist:
            abort(404)

        form = PostForm(obj=post)
        all_categories = Category.select()
        template = env.get_template('post/edit.html')
        return template.render(
            item=post,
            form=form,
            categories=all_categories,
        )
    elif request.method == 'POST':
        post = Post.get(Post.post_id == post_id)
        post.category = post_get('category-id')
        post.post_text = post_get('text')
        post.slug = post_get('slug')
        post.title = post_get('title')
        post.draft = bool(int(post_get('draft')))  # zero int is False
        post.language = post_get('language')
        post.show_on_index = bool(post_get('show-on-index'))
        post.date_updated = datetime.now()
        new_tags = post_get('tags')
        old_tags = Tag.select().join(Tag_to_Post)\
            .where(Tag_to_Post.post_id == post_id)
        remove_tags(old_tags, new_tags, post_id)
        add_new_tags(new_tags, post_id)
        post.save()
        app.flash('Article updated')
        redirect('/post/' + str(post_id))
Exemple #3
0
def photo_delete(photo_id):
    try:
        photo = Photo.get(Photo.photo_id == photo_id)
        photo.delete_instance()
        redirect('/gallery_add')
    except DoesNotExist:
        abort(404)
Exemple #4
0
def banner_delete(banner_id):
    try:
        banner = Banner.get(Banner.banner_id == banner_id)
        banner.delete_instance()
        redirect('/banners')
    except DoesNotExist:
        abort(404)
Exemple #5
0
def post_add():
    form = PostForm()
    if request.method == 'GET':
        all_categories = Category.select()
        template = env.get_template('post/add.html')
        return template.render(
            form=form,
            categories=all_categories,
        )
    if request.method == 'POST':
        post = Post.create(
            category=post_get('category-id'),
            post_text=post_get('text'),
            title=post_get('title'),
            slug=post_get('slug'),
            user=app.current_user.user_id,
            date_posted=datetime.now(),
            draft=bool(int(post_get('draft'))),
            show_on_index=bool(post_get('show-on-index')),
            language=post_get('language'),
        )
        post_id = post.post_id
        post.save()
        add_new_tags(post_get('tags'), post_id)
        redirect('/post/' + str(post_id))
Exemple #6
0
def banners():
    template = env.get_template('banners.html')
    if request.method == 'GET':
        all_banners = Banner.select()
        return template.render({'banners': all_banners})
    elif request.method == 'POST':
        banner_img = request.files.get('banner_img')
        banners_folder = static_path('img/banners/')
        file_path = os.path.join(banners_folder, banner_img.filename)
        # photo_file.save('/img/gallery/')  # new Bottle
        with open(file_path, 'wb') as open_file:
            open_file.write(banner_img.file.read())

        link = post_get('link')
        parsed_link = urlparse(link)
        if parsed_link.scheme == '':
            link = 'http://{0}'.format(link)

        if not parsed_link.path or parsed_link.path == '#':
            link = '#'

        banner = Banner.create(desc=post_get('desc'),
                               link=link,
                               img=banner_img.filename)
        app.flash('+1 banner')
        redirect('/banners')
Exemple #7
0
def post_add():
    form = PostForm()
    if request.method == 'GET':
        all_categories = Category.select()
        template = env.get_template('post/add.html')
        return template.render(
            form=form,
            categories=all_categories,
        )
    if request.method == 'POST':
        post = Post.create(
            category=post_get('category-id'),
            post_text=post_get('text'),
            title=post_get('title'),
            slug=post_get('slug'),
            user=app.current_user.user_id,
            date_posted=datetime.now(),
            draft=bool(int(post_get('draft'))),
            show_on_index=post_get_checkbox('show_on_index'),
            language=post_get('language'),
        )
        post_id = post.post_id
        post.save()
        add_new_tags(post_get('tags'), post_id)
        redirect('/post/' + str(post_id))
Exemple #8
0
def login():
    if 'back' in request.query:
        back = request.query['back']
    else:
        back = '/'
    if app.current_user is not None:
        app.flash(
            'Log out from current session in order to use different account',
            category='info',
        )
        redirect(back)
    if request.method == 'POST':
        try:
            user = User.get(User.mail == post_get('email'))
        except DoesNotExist:
            app.flash('No such user')
        else:
            if user.user_password == User.encode_password(
                    post_get('password')):
                app.flash('Successfully logged in')
                app.login(user)
                redirect(back)
            else:
                app.flash('Wrong password', category='info')

    template = env.get_template('user/login.html')

    return template.render()
Exemple #9
0
def sp_delete(sp_id):
    try:
        sp = StaticPage.get(StaticPage.id == sp_id)
        sp.delete_instance()
        app.flash('Page was deleted', 'success')
        redirect('/sp/add')
    except DoesNotExist:
        abort(404)
Exemple #10
0
def quote_delete(quote_id):
    try:
        quote = Quote.get(Quote.quote_id == quote_id)
        quote.delete_instance()
        app.flash('Quote removed', 'success')
        redirect('/quote/add')
    except DoesNotExist:
        abort(404)
Exemple #11
0
def post_delete(post_id):
    try:
        post = Post.get(Post.post_id == post_id)
        post.deleted = True
        post.save()
        app.flash('Post has been deleted', 'success')
        redirect()
    except Post.DoesNotExist:
        abort(404)
Exemple #12
0
def category_add():
    if request.method == 'GET':
        all_categories = Category.select()
        template = env.get_template('post/category_add.html')
        return template.render(categories=all_categories)
    if request.method == 'POST':
        new_category = Category.create(category_name=post_get('category_name'))
        app.flash(u'Нова категорія була успішно додана')
        redirect('/category/add')
Exemple #13
0
def post_delete(post_id):
    try:
        post = Post.get(Post.post_id == post_id)
        post.deleted = True
        post.save()
        app.flash('Post has been deleted', 'success')
        redirect()
    except Post.DoesNotExist:
        abort(404)
Exemple #14
0
def post_renew(post_id):
    try:
        post = Post.get(Post.post_id == post_id)
        post.date_updated = datetime.now()
        post.save()
        app.flash('Article was revived')
        redirect('/post/%s' % post_id)
    except DoesNotExist:
        abort(404)
Exemple #15
0
def category_add():
    if request.method == 'GET':
        all_categories = Category.select()
        template = env.get_template('post/category_add.html')
        return template.render(categories=all_categories)
    if request.method == 'POST':
        new_category = Category.create(category_name=post_get('category_name'))
        app.flash('New category was added')
        redirect('/category/add')
Exemple #16
0
def post_renew(post_id):
    try:
        post = Post.get(Post.post_id == post_id)
        post.date_updated = datetime.now()
        post.save()
        app.flash(u'Стаття актуалізована')
        redirect('/post/%s' % post_id)
    except DoesNotExist:
        abort(404)
Exemple #17
0
 def wrapper(*args, **kwargs):
     if app.current_user is not None:
         r = Role.get(Role.role == role)
         if app.current_user.role.level >= r.level:
             return func(*args, **kwargs)
         app.flash('You have no permissions to view this')
         redirect()
     app.flash('Login first')
     redirect('/login?back=' + request.path)
Exemple #18
0
 def wrapper(*args, **kwargs):
     if app.current_user is not None:
         r = Role.get(Role.role == role)
         if app.current_user.role.level >= r.level:
             return func(*args, **kwargs)
         app.flash('You have no permissions to view this')
         redirect()
     app.flash('Login first')
     redirect('/login?back=' + request.path)
Exemple #19
0
def update_account():
    user = app.current_user
    update_form = UserEditForm(request.POST, user)
    if update_form.validate():
        update_form.populate_obj(user)
        user.save()
        app.flash('Successfully updated')
    else:
        app.flash('Check your form', category='error')
    redirect('/account')  # without return redirect because of raise inside
Exemple #20
0
def update_account():
    user = app.current_user
    update_form = UserEditForm(request.POST, user)
    if update_form.validate():
        update_form.populate_obj(user)
        user.save()
        app.flash('Successfully updated')
    else:
        app.flash('Check your form', category='error')
    redirect('/account')  # without return redirect because of raise inside
Exemple #21
0
def category_delete(category_id):
    try:
        category = Category.get(Category.category_id == category_id)
        try:
            category.delete_instance()
        except IntegrityError as e:
            app.flash(u'Категорія містить статті. Неможливо видалити', 'error')

        redirect('/category/add')

    except DoesNotExist:
        abort(404)
Exemple #22
0
def category_delete(category_id):
    try:
        category = Category.get(Category.category_id == category_id)
        try:
            category.delete_instance()
        except IntegrityError as e:
            app.flash(u'Категорія містить статті. Неможливо видалити', 'error')

        redirect('/category/add')

    except DoesNotExist:
        abort(404)
Exemple #23
0
def post_edit(post_id):
    if request.method == 'GET':
        try:
            post = Post.get(Post.post_id == post_id)  # todo: get not deleted
        except Post.DoesNotExist:
            abort(404)

        form = PostForm(obj=post)
        all_categories = Category.select()
        template = env.get_template('post/edit.html')
        return template.render(
            item=post,
            form=form,
            categories=all_categories,
        )
    elif request.method == 'POST':
        post = Post.get(Post.post_id == post_id)
        post.category = post_get('category-id')
        post.post_text = post_get('text')
        post.slug = post_get('slug')
        post.title = post_get('title')
        post.draft = bool(int(post_get('draft')))  # zero int is False
        post.language = post_get('language')
        post.show_on_index = post_get_checkbox('show_on_index')
        post.date_updated = datetime.now()
        new_tags = post_get('tags')
        old_tags = Tag.select().join(Tag_to_Post)\
            .where(Tag_to_Post.post_id == post_id)
        remove_tags(old_tags, new_tags, post_id)
        add_new_tags(new_tags, post_id)
        post.save()
        app.flash('Article updated')
        return redirect('/post/' + str(post_id))
Exemple #24
0
def gallery():
    template = env.get_template('gallery_add.html')
    if request.method == 'GET':
        photos = Photo.select()
        return template.render(photos=photos)
    elif request.method == 'POST':
        photo_file = request.files.get('photo')

        file_ext = os.path.splitext(photo_file.filename)[1]
        gallery_folder = static_path('img/gallery/')
        f_name = generate_filename(prefix='photo', suffix=file_ext)
        file_path = os.path.join(gallery_folder, f_name)
        # photo_file.save('/img/gallery/')  # new Bottle
        with open(file_path, 'wb') as open_file:
            open_file.write(photo_file.file.read())

        photo = Photo.create(desc=post_get('desc'),
                             photo=f_name)
        app.flash('Picture added to the gallery')
        redirect('/gallery_add')
Exemple #25
0
def edit_do(request, id_, **kwargs):
    content = request.form.get("content", "")
    action = request.form.get("action", "")
    action = action.lower()

    if action == "delete":
        deldata = document.delete(notedb(), xapdb, id_)
        if deldata is None:
            return notfound()
    else:
        updatedata = document.update(notedb(), xapdb, id_, content)
        if updatedata is None:
            return notfound()

    return redirect("document.index")
Exemple #26
0
def signup():

    template = env.get_template('user/signup.html')
    form = SignupForm(request.POST)
    if request.method == 'POST':
        if form.validate():
            try:
                user = User.get(User.mail == form.mail.data)
            except DoesNotExist:
                new_user = User.create(
                    mail=form.mail.data,
                    user_password=User.encode_password(form.password.data),
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    nickname=form.nickname.data,
                )
                app.flash('Well done! Now you can log in')
                redirect('/login')
            else:
                app.flash(
                    'User with such an email already exists',
                    category='info',
                )
    return template.render(form=form)
Exemple #27
0
def signup():

    template = env.get_template('user/signup.html')
    form = SignupForm(request.POST)
    if request.method == 'POST':
        if form.validate():
            try:
                user = User.get(User.mail == form.mail.data)
            except DoesNotExist:
                new_user = User.create(
                    mail=form.mail.data,
                    user_password=User.encode_password(form.password.data),
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    nickname=form.nickname.data,
                )
                app.flash('Well done! Now you can log in')
                redirect('/login')
            else:
                app.flash(
                    'User with such an email already exists',
                    category='info',
                )
    return template.render(form=form)
Exemple #28
0
def index():
    redirect('/post')
Exemple #29
0
def post_publish(post_id):
    p = Post.get_or_404(Post.post_id == post_id)
    p.draft = False
    p.save()
    app.flash('Post was published', 'success')
    redirect('/post/%s' % post_id)
Exemple #30
0
def create_do(request, **kwargs):
    content = request.form.get("content", "")
    document.create(notedb(), xapdb, content)
    return redirect("document.index")
Exemple #31
0
def post_publish(post_id):
    p = Post.get_or_404(Post.post_id == post_id)
    p.draft = False
    p.save()
    app.flash('Post was published', 'success')
    return redirect('/post/%s' % post_id)
Exemple #32
0
def logout():
    app.logout()
    app.flash('Successfully logged out!')
    redirect()
Exemple #33
0
 def wrapper(*args, **kwargs):
     if app.current_user is not None:
         return func(*args, **kwargs)
     app.flash('Login to view this page')
     redirect('/login?back=' + request.path)
Exemple #34
0
 def wrapper(*args, **kwargs):
     if app.current_user is not None:
         return func(*args, **kwargs)
     app.flash('Login to view this page')
     redirect('/login?back=' + request.path)
Exemple #35
0
def logout():
    app.logout()
    app.flash('Successfully logged out!')
    redirect()