Example #1
0
def donation(request, code=None):
    request.session['current_page'] = 'donation'
    if code == settings.THANKS_CODE:
        return render(request, 'home/donation_success.html')
    template_name = set_template_language('home/donation',
                                          request.session.get('language'))
    return render(request, template_name)
Example #2
0
def home(request):
    request.session['current_page'] = 'home'
    arts = Article.objects.filter(published=True)[:7]

    # get template based on language
    template_name = set_template_language('home/index',
                                          request.session.get('language'))
    return render(request, template_name, {
        'recent_arts': arts,
    })
Example #3
0
def index(request):
    request.session['current_page'] = 'blog'
    art_list = Article.objects.filter(published=True)
    paginator = Paginator(art_list, 7, orphans=3)

    page = request.GET.get('page')
    arts = paginator.get_page(page)
    template_name = set_template_language('blog/index',
                                          request.session.get('language'))
    return render(request, template_name, {
        'arts': arts,
    })
Example #4
0
def view_article(request, year, slug):
    art = get_object_or_404(Article, date_created__year=year, slug=slug)

    template_name = set_template_language('blog/view_article',
                                          request.session.get('language'))
    response = render(request, template_name, {
        'art': art,
        'debug': settings.DEBUG,
    })

    if not request.user.is_authenticated and request.COOKIES.get(
            art.slug) is None:
        import datetime
        now = datetime.datetime.now()
        three_days = now + datetime.timedelta(days=3)
        response.set_signed_cookie(art.slug, art.id, expires=three_days)
        art.view_count = F('view_count') + 1
        art.save()

    return response
Example #5
0
def about(request):
    if request.method == 'POST':
        captcha_response = request.POST.get('captcha-response')
        if int(captcha_response) != request.session.get('challenge-answer'):
            messages.error(request, 'ERROR: Incorrect challenge response.')
        else:
            visitor_name = request.POST.get('name')
            visitor_email = request.POST.get('email')
            message = request.POST.get('message')

            email = EmailMessage(
                f'Pesan dari {visitor_name}',
                message,
                f'{visitor_name} via Rawinala.org <{settings.EMAIL_HOST_USER}>',
                settings.ADMINS_EMAIL,
                reply_to=[visitor_email],
            )
            try:
                email.send()
                messages.success(request, 'Message sent.')
            except:
                messages.error(request, 'ERROR: Message not sent.')
        return redirect('home:about')

    # Just show the About page
    request.session['current_page'] = 'about'

    opr1 = random.randint(30, 50)
    opr2 = random.randint(1, 29)
    opn = '+' if random.randint(1, 2) == 1 else '-'
    challenge = f'{opr1} {opn} {opr2}'
    request.session['challenge-answer'] = (opr1 +
                                           opr2) if opn == '+' else (opr1 -
                                                                     opr2)
    template_name = set_template_language('home/about',
                                          request.session.get('language'))
    return render(request, template_name, {
        'challenge': challenge,
    })