Пример #1
0
def about(request):
    """" return the about page """
    # Page about
    page = get_page("about")
    # Categories
    categories = get_about_categories()
    # Terms
    terms = get_terms()
    context = Context()
    context.update(page=page, categories=categories, terms=terms)
    return render(request, 'aboutapp/about.html', context)
Пример #2
0
def post(request, post_name):
    """ return the page with the post selected """
    # Post
    post = get_post(post_name)
    # Page post
    page = {
        "link_name": "blog",
        "title": "Blog|{}".format(post.category_name),
        "subtitle": post.title
    }
    # Main titles
    main_titles = get_page("post")
    # Comments
    comments = get_comments(post_name)
    if len(comments) == 0:
        # Alert message
        no_comment = get_alert_message("no comment")
    else:
        no_comment = False
    # Card button
    buttons_card = get_buttons_card("comment")
    # Form POST
    form = CommentForm()
    add_comment = False
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            # send a message to admin to inform him
            # that a comment has been added and save it in db
            comment = form.save(commit=False)
            comment.post = post
            send_mail(
                "A comment was added.",
                "'{}'\nhas been added to the post '{}' by {} <- {} ->".format(
                    comment.text, post_name, comment.author_name,
                    comment.author_email),
                "DjangoWebSite", ['JBthePenguin'],
                fail_silently=False)
            comment.save()
            form = CommentForm()
            # Alert message
            add_comment = get_alert_message("add comment")
    context = Context()
    context.update(page=page,
                   main_titles=main_titles,
                   btn_card_text=buttons_card[0].text,
                   post=post,
                   comments=comments,
                   form=form,
                   no_comment=no_comment,
                   add_comment=add_comment)
    return render(request, 'blogapp/post.html', context)
Пример #3
0
def portfolio(request):
    """ return the portfolio page """
    # Page portfolio
    page = get_page("portfolio")
    # Categories
    categories = get_portfolio_categories()
    # Projects
    projects = get_all_projects()
    # Card button
    buttons_card = get_buttons_card("portfolio")
    context = Context()
    context.update(
        page=page, categories=categories,
        projects=projects, btn_card_text=buttons_card[0].text)
    return render(request, 'portfolioapp/portfolio.html', context)
Пример #4
0
def blog(request):
    """ return the blog page """
    # Page blog
    page = get_page("blog")
    # Categories
    categories = get_blog_categories()
    # Post
    posts = get_all_posts()
    # Card button
    buttons_card = get_buttons_card("blog")
    context = Context()
    context.update(page=page,
                   categories=categories,
                   posts=posts,
                   btn_card_text=buttons_card[0].text)
    return render(request, 'blogapp/blog.html', context)
Пример #5
0
def project(request, project_name):
    """ return the page with the project selected """
    # Project
    project = get_project(project_name)
    # Page
    page = {
        "link_name": "portfolio",
        "title": "Portfolio|{}".format(project.category_name),
        "subtitle": project.title}
    # Card button
    buttons_card = get_buttons_card("project")
    context = Context()
    context.update(
        page=page,
        project=project,
        btn_card_text=buttons_card[0].text)
    return render(request, 'portfolioapp/project.html', context)
Пример #6
0
def contact(request):
    """ return the page with contact form
    save a message and send email"""
    # Page contact
    page = get_page("contact")
    # Contact items
    contact_items = get_all_contact_items()
    # contact_items = ContactItem.objects.all().order_by('position')
    # Main titles
    main_titles = get_page("main-contact")
    # Card buttons
    buttons_card = get_buttons_card("contact")
    # Form POST
    form = ContactForm()
    sent_message = False
    if request.method == 'POST':
        # message has sent
        form = ContactForm(request.POST, )
        if form.is_valid():
            # send the message to admin and save it in db
            message = form.save(commit=False)
            send_mail(message.subject,
                      message.content,
                      "DjangoWebSite: {} <- {} ->".format(
                          message.contact_name, message.contact_email),
                      ['JBthePenguin'],
                      fail_silently=False)
            message.save()
            form = ContactForm()
            # Alert messages
            sent_message = get_alert_message("sent message")
    context = Context()
    context.update(page=page,
                   contact_items=contact_items,
                   main_titles=main_titles,
                   btn_card_text=buttons_card[0].text,
                   sent_message=sent_message,
                   form=form)
    return render(request, 'contactapp/contact.html', context)
Пример #7
0
def index(request):
    """ return the index page """
    pages = get_all_page()
    context = Context()
    context.update(page=pages[0], pages=pages[1:])
    return render(request, 'websiteapp/index.html', context)
Пример #8
0
def mentions(request):
    """ return the page with legal mentions"""
    page = get_page("mentions")
    context = Context()
    context.update(page=page)
    return render(request, 'websiteapp/mentions.html', context)