コード例 #1
0
ファイル: post.py プロジェクト: bmwant/bmwlog
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))
コード例 #2
0
def tr():
    app.flash('Trying flashing bying', 'error')
    tg = Tag.get(Tag.tag_id == 36)
    print(tg.posts_count)
    quote = Quote.select().first()
    messages = StreamMessage.select()
    return render_template('info.html', messages=messages, quote=quote)
コード例 #3
0
ファイル: site.py プロジェクト: bmwant/bmwlog
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')
コード例 #4
0
def upload():
    """
    Uploads a file to the site storage on the server
    """
    # todo: add auto-rename
    # todo: add format checking and size for pictures
    form = SimpleUploadForm(request.POST)
    template = env.get_template('upload.html')
    if request.method == 'POST' and form.validate():
        up_file = form.upload_file.data
        folder = os.path.join(config.ROOT_FOLDER, form.file_folder.data)
        if not os.path.exists(folder):
            os.makedirs(folder)
        new_filename = up_file.filename
        file_path = os.path.join(folder, new_filename)
        # Generate unique filename if one already exists
        if os.path.exists(file_path):
            new_filename = distort_filename(up_file.filename)
            file_path = os.path.join(folder, new_filename)
        # photo_file.save('/img/gallery/')  # new Bottle
        with open(file_path, 'wb') as open_file:
            open_file.write(up_file.file.read())
        uploaded_file = join_all_path(['/',
                                       form.file_folder.data,
                                       new_filename]).replace('\\', '/')
        app.flash(u'Файл завантажено')
        return template.render(form=form, uploaded_file=uploaded_file)
    return template.render(form=form)
コード例 #5
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)

        all_categories = Category.select()
        template = env.get_template('post/edit.html')
        return template.render(item=post,
                               categories=all_categories,
                               submit_button=u'Оновити')
    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.title = post_get('title')
        post.draft = bool(int(post_get('draft')))  # zero int is False
        post.language = post_get('language')
        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(u'Статтю успішно оновлено')
        redirect('/post/' + str(post_id))
コード例 #6
0
ファイル: post.py プロジェクト: bmwant/bmwlog
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))
コード例 #7
0
ファイル: site.py プロジェクト: bmwant/bmwlog
def upload():
    """
    Uploads a file to the site storage on the server
    """
    # todo: add auto-rename
    # todo: add format checking and size for pictures
    form = SimpleUploadForm(request.POST)
    template = env.get_template('upload.html')
    if request.method == 'POST' and form.validate():
        up_file = form.upload_file.data
        folder = os.path.join(config.ROOT_FOLDER, form.file_folder.data)
        if not os.path.exists(folder):
            os.makedirs(folder)
        new_filename = up_file.filename
        file_path = os.path.join(folder, new_filename)
        # Generate unique filename if one already exists
        if os.path.exists(file_path):
            new_filename = distort_filename(up_file.filename)
            file_path = os.path.join(folder, new_filename)
        # photo_file.save('/img/gallery/')  # new Bottle
        with open(file_path, 'wb') as open_file:
            open_file.write(up_file.file.read())
        uploaded_file = join_all_path(['/',
                                       form.file_folder.data,
                                       new_filename]).replace('\\', '/')
        app.flash('File uploaded')
        return template.render(form=form, uploaded_file=uploaded_file)
    return template.render(form=form)
コード例 #8
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(u'+1 новий банер')
        redirect('/banners')
コード例 #9
0
ファイル: site.py プロジェクト: bmwant/bmwlog
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)
コード例 #10
0
ファイル: site.py プロジェクト: bmwant/bmwlog
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)
コード例 #11
0
def quote_add():
    template = env.get_template('quote_add.html')
    all_quotes = Quote.select()
    if request.method == 'POST':
        quote = Quote.create(text=post_get('text'),
                             author=post_get('author'))
        app.flash(u'Цитата додана', 'success')
    return template.render({'quotes': all_quotes})
コード例 #12
0
ファイル: site.py プロジェクト: bmwant/bmwlog
def quote_add():
    template = env.get_template('quote_add.html')
    all_quotes = Quote.select()
    if request.method == 'POST':
        quote = Quote.create(text=post_get('text'),
                             author=post_get('author'))
        app.flash('Quote added', 'success')
    return template.render({'quotes': all_quotes})
コード例 #13
0
def sp_delete(sp_id):
    try:
        sp = StaticPage.get(StaticPage.id == sp_id)
        sp.delete_instance()
        app.flash(u'Сторінка видалена', 'success')
        redirect('/sp/add')
    except DoesNotExist:
        abort(404)
コード例 #14
0
def quote_delete(quote_id):
    try:
        quote = Quote.get(Quote.quote_id == quote_id)
        quote.delete_instance()
        app.flash(u'Цитата видалена', 'success')
        redirect('/quote/add')
    except DoesNotExist:
        abort(404)
コード例 #15
0
ファイル: post.py プロジェクト: bmwant/bmwlog
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)
コード例 #16
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')
コード例 #17
0
ファイル: post.py プロジェクト: bmwant/bmwlog
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')
コード例 #18
0
ファイル: post.py プロジェクト: bmwant/bmwlog
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)
コード例 #19
0
ファイル: post.py プロジェクト: bmwant/bmwlog
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)
コード例 #20
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)
コード例 #21
0
def post_delete(post_id):
    try:
        post = Post.get(Post.post_id == post_id)
        post.deleted = True
        post.save()
        app.flash(u'Статтю видалено', 'success')
        redirect()
    except Post.DoesNotExist:
        abort(404)
コード例 #22
0
ファイル: user.py プロジェクト: bmwant/bmwlog
 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)
コード例 #23
0
ファイル: user.py プロジェクト: bmwant/bmwlog
 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)
コード例 #24
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(u'У Вас недостатньо прав для перегляду')
         redirect()
     app.flash(u'Увійдіть, щоб переглянути дану сторінку')
     redirect('/login?back=' + request.path)
コード例 #25
0
ファイル: user.py プロジェクト: bmwant/bmwlog
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
コード例 #26
0
ファイル: user.py プロジェクト: bmwant/bmwlog
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
コード例 #27
0
def category_delete(category_id):
    try:
        category = Category.get(Category.category_id == category_id)
    except DoesNotExist:
        abort(404)
    try:
        category.delete_instance()
    except IntegrityError as e:
        app.flash(u'Категорія містить статті. Неможливо видалити', 'error')

    redirect('/category/add')
コード例 #28
0
ファイル: post.py プロジェクト: bmwant/bmwlog
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)
コード例 #29
0
def sp_add():
    form = StaticPageForm(request.POST)
    template = env.get_template('static_page_admin.html')

    if form.validate_on_post():
        app.log(form.page_url.data)
        new_page = StaticPage.create(title=form.title.data,
                                     url=form.page_url.data,
                                     text=form.text.data)
        app.flash('New page!')
    pages = StaticPage.select()
    return template.render(form=form, pages=pages)
コード例 #30
0
def update_account():
    user = app.current_user
    update_form = UserEditForm(request.POST, user)
    if update_form.validate():
        # user.update(**update_form.data).execute()
        update_form.populate_obj(user)
        print(update_form.data)
        user.save()
        print(user.picture)
        app.flash(u'Дані успішно оновлено')
    else:
        app.flash(u'Incorrect somtethisd')
    redirect('/account')  # without return redirect because of raise inside
コード例 #31
0
ファイル: site.py プロジェクト: bmwant/bmwlog
def joke_add():
    template = env.get_template('item_add.html')
    all_jokes = SiteJoke.select()
    form = ItemForm(model_class=SiteJoke, url_prefix='joke')
    if request.method == 'POST':
        SiteJoke.create(
            text=post_get('text'),
        )
        app.flash('New joke is here', 'success')
    return template.render({
        'form': form,
        'items': all_jokes,
    })
コード例 #32
0
ファイル: user.py プロジェクト: bmwant/bmwlog
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()
コード例 #33
0
def login():
    if 'back' in request.query:
        back = request.query['back']
    else:
        back = '/'
    if app.current_user is not None:
        app.flash(u'Вийдіть з поточної сесії, щоб увійти під іншим акаунтом')
        redirect(back)
    if request.method == 'POST':
        try:
            user = User.get(User.mail == post_get('email'))
        except DoesNotExist:
            app.flash(u'Немає такого користувача')
        else:
            if user.user_password == User.encode_password(
                    post_get('password')):
                app.flash(u'Ви успішно увійшли')
                app.login(user)
                redirect(back)
            else:
                app.flash(u'Невірний пароль')

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

    return template.render()
コード例 #34
0
ファイル: user.py プロジェクト: bmwant/bmwlog
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()
コード例 #35
0
ファイル: site.py プロジェクト: bmwant/bmwlog
def sp_add():
    form = StaticPageForm(
        request.POST,
        model_class=StaticPage,
        url_prefix='sp',
    )
    template = env.get_template('item_add.html')

    if form.validate_on_post():
        app.log(form.page_url.data)
        StaticPage.create(
            title=form.title.data,
            url=form.page_url.data,
            text=form.text.data,
        )
        app.flash('New page!')
    pages = StaticPage.select()
    return template.render(form=form, items=pages)
コード例 #36
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(u'Фото успішно додане')
        redirect('/gallery_add')
コード例 #37
0
ファイル: site.py プロジェクト: bmwant/bmwlog
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')
コード例 #38
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(u'Успішна реєстрація. Тепер ви можете увійти')
                redirect('/login')
            else:
                app.flash(u'Користувач з такою поштою уже існує')
    return template.render(form=form)
コード例 #39
0
ファイル: user.py プロジェクト: bmwant/bmwlog
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)
コード例 #40
0
ファイル: user.py プロジェクト: bmwant/bmwlog
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)
コード例 #41
0
ファイル: user.py プロジェクト: bmwant/bmwlog
def logout():
    app.logout()
    app.flash('Successfully logged out!')
    redirect()
コード例 #42
0
ファイル: user.py プロジェクト: bmwant/bmwlog
 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)
コード例 #43
0
def logout():
    app.logout()
    app.flash(u'Ви успішно вийшли')
    redirect()
コード例 #44
0
ファイル: user.py プロジェクト: bmwant/bmwlog
def logout():
    app.logout()
    app.flash('Successfully logged out!')
    redirect()
コード例 #45
0
ファイル: user.py プロジェクト: bmwant/bmwlog
 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)
コード例 #46
0
ファイル: post.py プロジェクト: bmwant/bmwlog
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)
コード例 #47
0
 def wrapper(*args, **kwargs):
     if app.current_user is not None:
         return func(*args, **kwargs)
     app.flash(u'Увійдіть, щоб переглянути дану сторінку')
     redirect('/login?back=' + request.path)
コード例 #48
0
def post_publish(post_id):
    p = Post.get_or_404(Post.post_id == post_id)
    p.draft = False
    p.save()
    app.flash(u'Стаття опублікована', 'success')
    redirect('/post/%s' % post_id)