Exemplo n.º 1
0
def signup():

    form = SignupForm(next=request.args.get('next',None))

    if form.validate_on_submit():

        code = UserCode.query.filter_by(code=form.code.data).first()

        if code:
            user = User(role=code.role)
            form.populate_obj(user)

            db.session.add(user)
            db.session.delete(code)
            db.session.commit()

            identity_changed.send(current_app._get_current_object(),
                                  identity=Identity(user.id))

            flash(_("Welcome, %(name)s", name=user.nickname), "success")

            next_url = form.next.data

            if not next_url or next_url == request.path:
                next_url = url_for('frontend.blog', username=user.username)

            return redirect(next_url)
        else:
            form.code.errors.append(_("Code is not allowed"))

    return render_template("account/signup.html", form=form)
Exemplo n.º 2
0
def template_edit(path):

    path = os.path.join(current_app.root_path, 'templates', "%s.html" % path)
    html = ""

    try:
        f = open(path)
        html = f.read()
        f.close()
    except:
        flash(_("Template file does not exists"), "error")

    form = TemplateForm(html=html.decode('utf8'))

    if form.validate_on_submit():

        f = open(path, 'w')
        f.write(form.html.data.encode('utf8'))
        f.close()

        flash(_("Saving success"), "success")

        return redirect(url_for("frontend.index"))

    return render_template("blog/template_edit.html",
                            form=form,
                            path=path)
Exemplo n.º 3
0
def login():

    form = LoginForm(login=request.args.get('login', None),
                     next=request.args.get('next', None))

    if form.validate_on_submit():

        user, authenticated = User.query.authenticate(form.login.data,
                                                      form.password.data)

        if user and authenticated:
            session.permanent = form.remember.data

            identity_changed.send(current_app._get_current_object(),
                                  identity=Identity(user.id))

            flash(_("Welcome back, %(name)s", name=user.username), "success")

            next_url = form.next.data

            if not next_url or next_url == request.path:
                next_url = url_for('frontend.people', username=user.username)

            return redirect(next_url)

        else:

            flash(_("Sorry, invalid login"), "error")

    return render_template("account/login.html", form=form)
Exemplo n.º 4
0
def login():

    form = LoginForm(login=request.args.get('login',None),
                     next=request.args.get('next',None))

    if form.validate_on_submit():

        user, authenticated = User.query.authenticate(form.login.data,
                                                      form.password.data)

        if user and authenticated:
            session.permanent = form.remember.data

            identity_changed.send(current_app._get_current_object(),
                                  identity=Identity(user.id))

            flash(_("Welcome back, %(name)s", name=user.username), "success")

            next_url = form.next.data

            if not next_url or next_url == request.path:
                next_url = url_for('frontend.blog', username=user.username)

            return redirect(next_url)

        else:

            flash(_("Sorry, invalid login"), "error")

    return render_template("account/login.html", form=form)
Exemplo n.º 5
0
def signup():

    form = SignupForm(next=request.args.get('next', None))

    if form.validate_on_submit():

        code = UserCode.query.filter_by(code=form.code.data).first()

        if code:
            user = User(role=code.role)
            form.populate_obj(user)

            db.session.add(user)
            db.session.delete(code)
            db.session.commit()

            identity_changed.send(current_app._get_current_object(),
                                  identity=Identity(user.id))

            flash(_("Welcome, %(name)s", name=user.nickname), "success")

            next_url = form.next.data

            if not next_url or next_url == request.path:
                next_url = url_for('frontend.people', username=user.username)

            return redirect(next_url)
        else:
            form.code.errors.append(_("Code is not allowed"))

    return render_template("account/signup.html", form=form)
Exemplo n.º 6
0
def template_edit(path):

    path = os.path.join(current_app.root_path, 'templates', "%s.html" % path)
    html = ""

    try:
        f = open(path)
        html = f.read()
        f.close()
    except:
        flash(_("Template file does not exists"), "error")

    form = TemplateForm(html=html.decode('utf8'))

    if form.validate_on_submit():

        f = open(path, 'w')
        f.write(form.html.data.encode('utf8'))
        f.close()

        flash(_("Saving success"), "success")

        return redirect(url_for("frontend.index"))

    return render_template("blog/template_edit.html", form=form, path=path)
Exemplo n.º 7
0
def add_comment(post_id, parent_id=None):

    post = Post.query.get_or_404(post_id)

    parent = Comment.query.get_or_404(parent_id) if parent_id else None

    form = CommentForm()

    if form.validate_on_submit():

        comment = Comment(post=post,
                          parent=parent,
                          ip=ip2long(request.environ['REMOTE_ADDR']))
        form.populate_obj(comment)

        if g.user:
            comment.author = g.user

        db.session.add(comment)
        db.session.commit()

        signals.comment_added.send(post)

        flash(_("Thanks for your comment"), "success")

        return redirect(comment.url)

    return render_template("blog/add_comment.html",
                           parent=parent,
                           post=post,
                           form=form)
Exemplo n.º 8
0
def add_comment(post_id, parent_id=None):

    post = Post.query.get_or_404(post_id)

    parent = Comment.query.get_or_404(parent_id) if parent_id else None

    form = CommentForm()

    if form.validate_on_submit():
        comment = Comment(post=post,
                          parent=parent,
                          ip=ip2long(request.environ['REMOTE_ADDR']))
        form.populate_obj(comment)

        if g.user:
            comment.author = g.user

        db.session.add(comment)
        db.session.commit()

        signals.comment_added.send(post)

        flash(_("Thanks for your comment"), "success")

        return redirect(comment.url)

    return render_template("blog/add_comment.html",
                           parent=parent,
                           post=post,
                           form=form)
Exemplo n.º 9
0
def people(username,page=1):
    people = User.query.get_by_username(username)
    form = TwitterForm()
    if form.validate_on_submit():
        api = people.twitter_api
        if api is None:
            return redirect(url_for('account.twitter'))
        content = form.content.data.encode("utf-8")
        status = people.post_twitter(content)
        if status:
            flash(_("Twitter posting is success"),"success")
            return redirect(url_for('frontend.people',
                                    username=username,
                                    page=page))
        else:
            flash(_("Twitter posting is failed"),"error")

    page_obj = Post.query.filter(Post.author_id==people.id).as_list()\
                         .paginate(page,per_page=Post.PER_PAGE)
    page_url = lanbda page: url_for("post.people",
                                    username=username,
                                    page=page)
    return render_template("blog/people.html",
                           form=form,
                           page_obj=page_obj,
                           page_url=page_url,
                           people=people)
Exemplo n.º 10
0
def index(page=1):
    if page < 1:
        page = 1
    ups = Upload.query

    page_obj = ups.paginate(page=page, per_page=Upload.PER_PAGE)

    page_url = lambda page: url_for("uploads.index", page=page)

    return render_template("blog/uploads.html", page_obj=page_obj, page_url=page_url)
Exemplo n.º 11
0
def tag(slug, page=1):

    tag = Tag.query.filter_by(slug=slug).first_or_404()

    page_obj = tag.posts.as_list() \
                        .paginate(page, per_page=Post.PER_PAGE)

    page_url = lambda page: url_for("post.tag", slug=slug, page=page)

    return render_template("blog/list.html",
                           page_obj=page_obj,
                           page_url=page_url)
Exemplo n.º 12
0
def index(year=None,month=None,day=None,page=1):
    if page<1:page=1
    page_obj = Post.query.archive(year,month,day).as_list()\
                         .paginate(page,per_page=Post.PER_PAGE)
    page_url = lambda page:url_for("post.index",
                                   year=year,
                                   month=month,
                                   day=day,
                                   page=page)
    return render_template("blog/list.html",
                           page_obj=page_obj,
                           page_url=page_url)
Exemplo n.º 13
0
def index(year=None, month=None, day=None, page=1):

    if page < 1: page = 1

    page_obj = Post.query.archive(year,month,day).as_list() \
                         .paginate(page, per_page=Post.PER_PAGE)

    page_url = lambda page: url_for(
        "post.index", year=year, month=month, day=day, page=page)

    return render_template("blog/list.html",
                           page_obj=page_obj,
                           page_url=page_url)
Exemplo n.º 14
0
Arquivo: link.py Projeto: ajaxj/fkmv
def index(page=1):

    links = Link.query

    if g.user is None:
        links = links.filter(Link.passed == True)

    page_obj = links.paginate(page=page, per_page=Link.PER_PAGE)

    page_url = lambda page: url_for("link.index", page=page)

    return render_template("admin/links.html",
                           page_obj=page_obj,
                           page_url=page_url)
Exemplo n.º 15
0
def tag(slug, page=1):

    tag = Tag.query.filter_by(slug=slug).first_or_404()

    page_obj = tag.posts.as_list() \
                        .paginate(page, per_page=Post.PER_PAGE)

    page_url = lambda page: url_for("post.tag",
                                    slug=slug,
                                    page=page)

    return render_template("blog/list.html",
                            page_obj=page_obj,
                            page_url=page_url)
Exemplo n.º 16
0
def index(page=1):
    
    links = Link.query

    if g.user is None:
        links = links.filter(Link.passed==True)

    page_obj = links.paginate(page=page, per_page=Link.PER_PAGE)

    page_url = lambda page: url_for("link.index",page=page)

    return render_template("blog/links.html", 
                            page_obj=page_obj,
                            page_url=page_url)
Exemplo n.º 17
0
def add():

    form = UploadForm()

    if "file" in request.files:

        filename = uploader.save(request.files["file"])
        upload = Upload(file=filename)
        db.session.add(upload)
        db.session.commit()

        flash(_("Upload successful"), "success")

        return redirect(url_for("uploads.index"))

    return render_template("blog/add_upload.html", form=form)
Exemplo n.º 18
0
def submit():

    form = PostForm()

    if form.validate_on_submit():

        post = Post(author=g.user)
        form.populate_obj(post)

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

        flash(_("Posting success"), "success")

        return redirect(post.url)

    return render_template("blog/submit.html", form=form)
Exemplo n.º 19
0
Arquivo: post.py Projeto: ajaxj/fkmv
def edit(post_id):

    post = Post.query.get_or_404(post_id)

    form = PostForm(title=post.title, slug=post.slug, content=post.content, tags=post.tags, obj=post)

    if form.validate_on_submit():

        form.populate_obj(post)

        db.session.commit()

        flash(_("Post has been changed"), "success")

        return redirect(post.url)

    return render_template("admin/submit.html", form=form)
Exemplo n.º 20
0
def submit():

    form = PostForm()

    if form.validate_on_submit():

        post = Post(author=g.user)
        form.populate_obj(post)

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

        flash(_("Posting success"), "success")

        return redirect(post.url)

    return render_template("blog/submit.html", form=form)
Exemplo n.º 21
0
def search(page=1):
    keywords = request.args.get('q','').strip()
    if not keywords:
        return redirect(url_for("frontend.index"))
    page_obj = Post.query.search(keywords).as_list()\
                         .paginate(page,per_page=Post.PER_PAGE)
    if page_obj.total == 1:
        post = page_obj.items[0]
        return redirect(post.url)

    page_url = lambda page:url_for('frontend.search',
                                   page=page,
                                   keywords=keywords)
    return render_template("blog/search_result.html",
                           page_obj=page_obj,
                           page_url=page_url,
                           keywords=keywords)
Exemplo n.º 22
0
def post(uear,month,day,slug):
    post = Post.query.get_by_slug(slug)

    date = (post.created_date.year,
            post.created_date.month,
            post.created_date.day)

    if date != (year, month, day):
        return redirect(post.url)

    prev_post = Post.query.filter(Post.created_date<post.created_date) \
                          .first()
    next_post = Post.query.filter(Post.created_date>post.created_date) \
                          .order_by('created_date asc').first()

    return render_template("blog/view.html",
                            post=post,
                            prev_post=prev_post,
                            next_post=next_post,
                            comment_form=CommentForm())
Exemplo n.º 23
0
def post(year, month, day, slug):

    post = Post.query.get_by_slug(slug)

    date = (post.created_date.year, post.created_date.month,
            post.created_date.day)

    if date != (year, month, day):
        return redirect(post.url)

    prev_post = Post.query.filter(Post.created_date<post.created_date) \
                          .first()
    next_post = Post.query.filter(Post.created_date>post.created_date) \
                          .order_by('created_date asc').first()

    return render_template("blog/view.html",
                           post=post,
                           prev_post=prev_post,
                           next_post=next_post,
                           comment_form=CommentForm())
Exemplo n.º 24
0
Arquivo: post.py Projeto: ajaxj/fkmv
def delete(post_id):

    post = Post.query.get_or_404(post_id)
    post.permissions.delete.test(403)

    Comment.query.filter_by(post=post).delete()

    db.session.delete(post)
    db.session.commit()

    if g.user.id != post.author_id:
        body = render_template("emails/post_deleted.html", post=post)

        message = Message(subject="Your post has been deleted", body=body, recipients=[post.author.email])

        mail.send(message)

    flash(_("The post has been deleted"), "success")

    return jsonify(success=True, redirect_url=url_for("frontend.index"))
Exemplo n.º 25
0
Arquivo: link.py Projeto: ajaxj/fkmv
def add():

    form = LinkForm()

    if form.validate_on_submit():

        link = Link()
        form.populate_obj(link)

        if g.user and g.user.is_moderator:
            link.passed = True

        db.session.add(link)
        db.session.commit()

        flash(_("Adding success"), "success")

        return redirect(url_for('link.index'))

    return render_template("admin/add_link.html", form=form)
Exemplo n.º 26
0
def add():
    
    form = LinkForm()

    if form.validate_on_submit():
        
        link = Link()
        form.populate_obj(link)

        if g.user and g.user.is_moderator:
            link.passed = True

        db.session.add(link)
        db.session.commit()

        flash(_("Adding success"), "success")

        return redirect(url_for('link.index'))

    return render_template("blog/add_link.html", form=form)
Exemplo n.º 27
0
def edit(post_id):

    post = Post.query.get_or_404(post_id)

    form = PostForm(title=post.title,
                    slug=post.slug,
                    content=post.content,
                    tags=post.tags,
                    obj=post)

    if form.validate_on_submit():

        form.populate_obj(post)

        db.session.commit()

        flash(_("Post has been changed"), "success")

        return redirect(post.url)

    return render_template("blog/submit.html", form=form)
Exemplo n.º 28
0
def search(page=1):

    keywords = request.args.get('q', '').strip()

    if not keywords:
        return redirect(url_for("frontend.index"))

    page_obj = Post.query.search(keywords).as_list() \
                         .paginate(page, per_page=Post.PER_PAGE)

    if page_obj.total == 1:

        post = page_obj.items[0]
        return redirect(post.url)

    page_url = lambda page: url_for(
        'frontend.search', page=page, keywords=keywords)

    return render_template("blog/search_result.html",
                           page_obj=page_obj,
                           page_url=page_url,
                           keywords=keywords)
Exemplo n.º 29
0
def delete(post_id):

    post = Post.query.get_or_404(post_id)
    post.permissions.delete.test(403)

    Comment.query.filter_by(post=post).delete()

    db.session.delete(post)
    db.session.commit()

    if g.user.id != post.author_id:
        body = render_template("emails/post_deleted.html", post=post)

        message = Message(subject="Your post has been deleted",
                          body=body,
                          recipients=[post.author.email])

        mail.send(message)

    flash(_("The post has been deleted"), "success")

    return jsonify(success=True, redirect_url=url_for('frontend.index'))
Exemplo n.º 30
0
def people(username, page=1):

    people = User.query.get_by_username(username)

    form = TwitterForm()

    if form.validate_on_submit():

        api = people.twitter_api

        if api is None:
            return redirect(url_for('account.twitter'))

        content = form.content.data.encode("utf8")

        status = people.post_twitter(content)

        if status:
            flash(_("Twitter posting is success"), "success")

            return redirect(
                url_for('frontend.people', username=username, page=page))
        else:
            flash(_("Twitter posting is failed"), "error")

    page_obj = Post.query.filter(Post.author_id==people.id).as_list() \
                         .paginate(page, per_page=Post.PER_PAGE)

    page_url = lambda page: url_for(
        "post.people", username=username, page=page)

    return render_template("blog/people.html",
                           form=form,
                           page_obj=page_obj,
                           page_url=page_url,
                           people=people)
Exemplo n.º 31
0
def about():
    return render_template("blog/about.html")
Exemplo n.º 32
0
def archive():

    return render_template("blog/archive.html")
Exemplo n.º 33
0
def tags():

    return render_template("blog/tags.html")
Exemplo n.º 34
0
            db.session.add(user)
            db.session.delete(code)
            db.session.commit()

            identity_changed.send(current_app._get_current_object(),
                                  identity=Identity(user.id))
            flash(_("Welcome, %(name)s",name=user.nickname),"success")
            next_url = form.next.data
            if not next_url or next_url  == request.path:
                next_url = url_for('frontend.people',username=user.username)

            return redirect(next_url)
    else:
        from.code.errors.append(_("Code is not allowed"))
return render_template("account/signup.html",form=form)


@account.route("/logout/")
def logout():
    flash(_("You are now logged out"),"success")
    identity_changed.send(current_app._get_current_object(),
                          identity=AnonymousIdentity())
    next_url = request.args.get('next','')

    if not next_url or next_url == request.path:
        next_url = url_for("frontend.index")

    return redirect(next_url)

@aaccount.route("/twitter/")
Exemplo n.º 35
0
def display(slug):
    post = Post.query.get_by_slug(slug)
    return render_template("blog/page.html", post=post)
Exemplo n.º 36
0
 def page_not_found(error):
     if request.is_xhr:
         return jsonify(error=_('Sorry, page not found'))
     return render_template("errors/404.html", error=error)
Exemplo n.º 37
0
def tags():

    return render_template("blog/tags.html")
Exemplo n.º 38
0
def archive():
    
        
    return render_template("blog/archive.html")
Exemplo n.º 39
0
 def page_not_found(error):
     if request.is_xhr:
         return jsonify(error=_('Sorry, page not found'))
     return render_template("errors/404.html", error=error)
Exemplo n.º 40
0
def about():
    return render_template("blog/about.html")
Exemplo n.º 41
0
 def server_error(error):
     if request.is_xhr:
         return jsonify(error=_('Sorry, an error has occurred'))
     return render_template("errors/500.html", error=error)
Exemplo n.º 42
0
 def forbidden(error):
     if request.is_xhr:
         return jsonify(error=_('Sorry, page not allowed'))
     return render_template("errors/403.html", error=error)
Exemplo n.º 43
0
 def forbidden(error):
     if request.is_xhr:
         return jsonify(error=_('Sorry, page not allowed'))
     return render_template("errors/403.html", error=error)
Exemplo n.º 44
0
 def server_error(error):
     if request.is_xhr:
         return jsonify(error=_('Sorry, an error has occurred'))
     return render_template("errors/500.html", error=error)
Exemplo n.º 45
0
@frontend.route("/tags/")
def tags():
    return render_template("blog/tags.html")

@frontend.route("/tags/<slug>/")
@frontend.route("/tags/<slug>/page/<int:page>")
def tag(slug,page=1)
    tag = Tag.query.filter_by(slug=slug).first_or_404()
    page_obj = tag.posts.as_list()\
                        .paginate(page,per_page=Post.PER_PAGE)
    page_url = lambda page:url_for("post.tag",
                                   slug=sulg,
                                   page=page)
    return render_template("blog/list.html",
                           page_obj=page_obj,
                           page_url=page_url)


@frontend.route("/people/<username>",methods=("GET","POST"))
@frontend.route("/people/<username>/page/<int:page>/",method=("GET","POST"))
def people(username,page=1):
    people = User.query.get_by_username(username)
    form = TwitterForm()
    if form.validate_on_submit():
        api = people.twitter_api
        if api is None:
            return redirect(url_for('account.twitter'))
        content = form.content.data.encode("utf-8")
        status = people.post_twitter(content)
        if status: