Fix urls, update menu, codestyle improvements, add views in documentation
This commit is contained in:
parent
ef36e8de40
commit
8c9b5a9cfa
@ -116,13 +116,14 @@ USE_TZ = True
|
|||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
STATIC_ROOT = os.path.join(BASE_DIR, 'staticroot')
|
||||||
STATICFILES_DIRS = [
|
STATICFILES_DIRS = [
|
||||||
os.path.join(BASE_DIR, 'staticfiles'),
|
os.path.join(BASE_DIR, 'static'),
|
||||||
]
|
]
|
||||||
|
|
||||||
MEDIA_ROOT = BASE_DIR / 'media'
|
MEDIA_ROOT = BASE_DIR / 'media'
|
||||||
MEDIA_URL = '/media/'
|
MEDIA_URL = '/media/'
|
||||||
|
|
||||||
LOGIN_REDIRECT_URL = '/'
|
LOGIN_REDIRECT_URL = '/'
|
||||||
LOGOUT_REDIRECT_URL = '/'
|
LOGOUT_REDIRECT_URL = '/'
|
||||||
|
|
||||||
|
@ -15,21 +15,22 @@ Including another URLconf
|
|||||||
"""
|
"""
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from django.urls import path, include
|
|
||||||
from django.contrib.auth.views import LoginView
|
from django.contrib.auth.views import LoginView
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
from access_controller import settings
|
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 = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls, name='admin'),
|
path('admin/', admin.site.urls, name='admin'),
|
||||||
path('', main_page),
|
path('', main_page, name='index'),
|
||||||
path('register/', CustomRegistrationView.as_view(), name='registration'),
|
path('accounts/profile/', profile_page, name='profile'),
|
||||||
# path('', include('django_registration.backends.one_step.urls')),
|
path('accounts/register/', CustomRegistrationView.as_view(), name='registration'),
|
||||||
path('profile/', profile_page, name='profile'),
|
path('accounts/login/', LoginView.as_view(extra_context={}), name='login'), # TODO add extra context
|
||||||
path('accounts/login/', LoginView.as_view(extra_context={})), # TODO add extra context
|
path('accounts/', include('django.contrib.auth.urls')),
|
||||||
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)
|
||||||
|
@ -7,3 +7,10 @@ Extra Functions
|
|||||||
|
|
||||||
.. automodule:: main.extra_func
|
.. automodule:: main.extra_func
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
|
||||||
|
Views
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. automodule:: main.views
|
||||||
|
:members:
|
||||||
|
@ -4,24 +4,20 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
|
||||||
<nav class="navbar navbar-light" style="background-color: #00FF00;">
|
<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">
|
<img src="{% static 'main/img/logo.png' %}" width="30" height="30" class="d-inline-block align-top" alt="" loading="lazy">
|
||||||
Access Controller
|
Access Controller
|
||||||
</a>
|
</a>
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
|
<div class="btn-group" role="group" aria-label="Basic example">
|
||||||
<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="/accounts/logout">Выйти</a>
|
<a class="btn btn-secondary" href="{% url 'logout' %}">Выйти</a>
|
||||||
<a class="btn btn-secondary" href="">Профиль</a>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
|
<div class="btn-group" role="group" aria-label="Basic example">
|
||||||
<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/login">Войти</a>
|
<a class="btn btn-secondary" href="/accounts/register">Зарегистрироваться</a>
|
||||||
<a class="btn btn-secondary" href="/accounts/register">Зарегистрироваться</a>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
@ -31,7 +31,6 @@ class CustomRegistrationView(RegistrationView):
|
|||||||
password=form.data['password1']
|
password=form.data['password1']
|
||||||
)
|
)
|
||||||
profile = UserProfile(
|
profile = UserProfile(
|
||||||
image='None.png',
|
|
||||||
user=user,
|
user=user,
|
||||||
role=0,
|
role=0,
|
||||||
)
|
)
|
||||||
@ -65,15 +64,13 @@ def profile_page(request):
|
|||||||
:return: объект ответа сервера с HTML-кодом внутри
|
:return: объект ответа сервера с HTML-кодом внутри
|
||||||
"""
|
"""
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
# UP = UserProfile.objects.get(user=request.user)
|
user_profile = request.user.userprofile
|
||||||
UP = UserProfile.objects.get(user=request.user)
|
|
||||||
# else: # TODO: Убрать после появления регистрации и авторизации, добавить login_required()
|
|
||||||
# UP = UserProfile.objects.get(user=1)
|
|
||||||
context = {
|
context = {
|
||||||
'name': set_and_get_name(UP),
|
'name': set_and_get_name(user_profile),
|
||||||
'email': set_and_get_email(UP),
|
'email': set_and_get_email(user_profile),
|
||||||
'role': set_and_get_role(UP),
|
'role': set_and_get_role(user_profile),
|
||||||
'image_name': load_and_get_image(UP),
|
'image_name': load_and_get_image(user_profile),
|
||||||
'pagename': 'Страница профиля'
|
'pagename': 'Страница профиля'
|
||||||
}
|
}
|
||||||
return render(request, 'pages/profile.html', context)
|
return render(request, 'pages/profile.html', context)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user