Skip to content

Commit

Permalink
[Frontend] Add /stats page
Browse files Browse the repository at this point in the history
  • Loading branch information
aobolensk committed Dec 7, 2020
1 parent 8136414 commit 7b9a2e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions templates/stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'base.html' %}

{% block content %}
<h1>Stats:</h1>
{% for key, value in stats.items %}
<p>{{ key }}: {{ value }}</p>
{% endfor %}
{% endblock %}
1 change: 1 addition & 0 deletions webforces/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
path('accounts/sign_up/', views.sign_up),
path('api/', include('webforces.api.urls')),
path('users/<str:user>/', views.UserView.as_view()),
path('stats/', views.StatsView.as_view()),
]
16 changes: 16 additions & 0 deletions webforces/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
from django.core.exceptions import PermissionDenied
from django.shortcuts import redirect, render
from django.views.generic.base import TemplateView

Expand All @@ -28,6 +29,7 @@ def get_indexes(self, user):
if user.is_superuser:
return [
Href("/users/"+user.username+"/", "profile"),
Href("/stats/", "stats"),
Href("/api/", "api"),
Href("/accounts/logout/", "sign out"),
]
Expand Down Expand Up @@ -58,6 +60,20 @@ def get_context_data(self, **kwargs):
return context


class StatsView(MainPageView):
template_name = "stats.html"

def get_context_data(self, **kwargs):
if not self.request.user.is_superuser:
raise PermissionDenied
context = super().get_context_data(**kwargs)
stats = {
"name": "webforces",
}
context["stats"] = stats
return context


def sign_up(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
Expand Down

0 comments on commit 7b9a2e8

Please sign in to comment.