Merge branch 'develop' of sika.sahkoinsinoorikilta.fi:vtmk/web2.0 into feature-pep8-fixes

This commit is contained in:
henu
2017-09-20 21:16:47 +03:00
6 changed files with 111 additions and 0 deletions
+43
View File
@@ -4,9 +4,13 @@ from django.shortcuts import render, redirect
from django.contrib.auth import login, logout, authenticate
from django.views.decorators.http import require_http_methods
from django.views.decorators.csrf import ensure_csrf_cookie
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import permission_required
from django.conf import settings
import logging
from webapp.models import OhlhafvChallenge
from webapp.forms import OhlhafvForm
from webapp.tables import OhlhafvTable
@require_http_methods(["GET"])
@@ -57,3 +61,42 @@ def logout_view(request, *args, **kwargs):
def about_view(request, *args, **kwargs):
"""Render about page."""
return render(request, "about.html", {})
@require_http_methods(["GET"])
def ohlhafv_view(request, *args, **kwargs):
form = OhlhafvForm()
return render(request, 'ohlhafv.html', {'form': form})
@ensure_csrf_cookie
@require_http_methods(["POST"])
def ohlhafv_submit(request, *args, **kwargs):
form = OhlhafvForm(request.POST)
if form.is_valid():
form.save()
#return HttpResponseRedirect('/list/')
else:
pass
#return render(request, 'error.html', {'error': form.errors})
return HttpResponseRedirect('/ohlhafv/list/')
@ensure_csrf_cookie
@require_http_methods(["GET"])
def ohlhafv_list(request, *args, **kwargs):
challenges = OhlhafvChallenge.objects.all()
table = OhlhafvTable(challenges,
request=request,
exclude=['id', 'challenger_email', 'victim_email'],
attrs={'class': 'table table-bordered table-hover'})
table.paginate(page=request.GET.get('page', 1), per_page=25)
table_html = table.as_html(request)
context = {
'table': table_html,
'challenge_count': len(challenges),
}
return render(request, 'ohlhafv_list.html', context)