Fix urls, update menu, codestyle improvements, add views in documentation

This commit is contained in:
Andrew Smirnov 2021-02-11 20:58:07 +03:00
parent ef36e8de40
commit 8c9b5a9cfa
No known key found for this signature in database
GPG Key ID: 0EFE318E5BB2A82A
5 changed files with 36 additions and 34 deletions

View File

@ -116,13 +116,14 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = os.path.join(BASE_DIR, 'staticroot')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'staticfiles'),
os.path.join(BASE_DIR, 'static'),
]
MEDIA_ROOT = BASE_DIR / 'media'
MEDIA_URL = '/media/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

View File

@ -15,21 +15,22 @@ Including another URLconf
"""
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth.views import LoginView
from django.urls import path, include
from access_controller import settings
from main.views import *
from access_controller.settings import DEBUG
from main.views import main_page, profile_page, CustomRegistrationView
urlpatterns = [
path('admin/', admin.site.urls, name='admin'),
path('', main_page),
path('register/', CustomRegistrationView.as_view(), name='registration'),
# path('', include('django_registration.backends.one_step.urls')),
path('profile/', profile_page, name='profile'),
path('accounts/login/', LoginView.as_view(extra_context={})), # TODO add extra context
path('accounts/', include('django.contrib.auth.urls'))
path('', main_page, name='index'),
path('accounts/profile/', profile_page, name='profile'),
path('accounts/register/', CustomRegistrationView.as_view(), name='registration'),
path('accounts/login/', LoginView.as_view(extra_context={}), name='login'), # TODO add extra context
path('accounts/', include('django.contrib.auth.urls')),
path('accounts/', include('django_registration.backends.one_step.urls')),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -7,3 +7,10 @@ Extra Functions
.. automodule:: main.extra_func
:members:
Views
-----
.. automodule:: main.views
:members:

View File

@ -4,24 +4,20 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<nav class="navbar navbar-light" style="background-color: #00FF00;">
<a class="navbar-brand" href="#">
<a class="navbar-brand" href="{% url 'index' %}">
<img src="{% static 'main/img/logo.png' %}" width="30" height="30" class="d-inline-block align-top" alt="" loading="lazy">
Access Controller
</a>
{% if request.user.is_authenticated %}
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-secondary" href="/accounts/logout">Выйти</a>
<a class="btn btn-secondary" href="">Профиль</a>
</div>
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-secondary" href="{% url 'profile' %}">Профиль</a>
<a class="btn btn-secondary" href="{% url 'logout' %}">Выйти</a>
</div>
{% else %}
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-secondary" href="/accounts/login">Войти</a>
<a class="btn btn-secondary" href="/accounts/register">Зарегистрироваться</a>
</div>
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-secondary" href="/accounts/login">Войти</a>
<a class="btn btn-secondary" href="/accounts/register">Зарегистрироваться</a>
</div>
{% endif %}
</nav>
</header>

View File

@ -31,7 +31,6 @@ class CustomRegistrationView(RegistrationView):
password=form.data['password1']
)
profile = UserProfile(
image='None.png',
user=user,
role=0,
)
@ -65,15 +64,13 @@ def profile_page(request):
:return: объект ответа сервера с HTML-кодом внутри
"""
if request.user.is_authenticated:
# UP = UserProfile.objects.get(user=request.user)
UP = UserProfile.objects.get(user=request.user)
# else: # TODO: Убрать после появления регистрации и авторизации, добавить login_required()
# UP = UserProfile.objects.get(user=1)
user_profile = request.user.userprofile
context = {
'name': set_and_get_name(UP),
'email': set_and_get_email(UP),
'role': set_and_get_role(UP),
'image_name': load_and_get_image(UP),
'name': set_and_get_name(user_profile),
'email': set_and_get_email(user_profile),
'role': set_and_get_role(user_profile),
'image_name': load_and_get_image(user_profile),
'pagename': 'Страница профиля'
}
return render(request, 'pages/profile.html', context)