From f21eb2dcd41b024f23f539622169c8985fd81ddb Mon Sep 17 00:00:00 2001 From: Iurii Tatishchev Date: Thu, 15 Apr 2021 08:43:10 -0700 Subject: [PATCH 1/2] minor fixes --- access_controller/settings.py | 2 +- access_controller/urls.py | 26 -------------------------- main/views.py | 28 ++-------------------------- 3 files changed, 3 insertions(+), 53 deletions(-) diff --git a/access_controller/settings.py b/access_controller/settings.py index ddcd372..f9b5119 100644 --- a/access_controller/settings.py +++ b/access_controller/settings.py @@ -58,8 +58,8 @@ EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = 'group02django@gmail.com' EMAIL_HOST_PASSWORD = 'djangogroup02' -SERVER_EMAIL = EMAIL_HOST_USER DEFAULT_FROM_EMAIL = EMAIL_HOST_USER +SERVER_EMAIL = EMAIL_HOST_USER TEMPLATES = [ { diff --git a/access_controller/urls.py b/access_controller/urls.py index 57d1d01..f6a6754 100644 --- a/access_controller/urls.py +++ b/access_controller/urls.py @@ -14,7 +14,6 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.contrib.auth import views as auth_views from django.urls import path, include from main.views import main_page, profile_page, CustomRegistrationView, CustomLoginView, registration_error @@ -30,41 +29,16 @@ urlpatterns = [ path('accounts/register/error/', registration_error, name='registration_email_error'), path('accounts/login/', CustomLoginView.as_view(), name='login'), path('accounts/', include('django.contrib.auth.urls')), - path('accounts/', include('django_registration.backends.one_step.urls')), path('work/', work_page, name="work"), path('work/hand_over/', work_hand_over, name="work_hand_over"), path('work/become_engineer/', work_become_engineer, name="work_become_engineer"), path('work/get_tickets', work_get_tickets, name='work_get_tickets'), path('accounts/', include('django_registration.backends.activation.urls')), - path('accounts/login/', include('django.contrib.auth.urls')), path('control/', AdminPageView.as_view(), name='control'), path('statistic/', statistic_page, name='statistic'), ] -urlpatterns += [ - path( - 'password_reset/', - auth_views.PasswordResetView.as_view(), - name='password_reset' - ), - path( - 'password_reset/done/', - auth_views.PasswordResetDoneView.as_view(), - name='password_reset_done' - ), - path( - 'reset///', - auth_views.PasswordResetConfirmView.as_view(), - name='password_reset_confirm' - ), - path( - 'reset/done/', - auth_views.PasswordResetCompleteView.as_view(), - name='password_reset_complete' - ), -] - # Django REST urlpatterns += [ path('api/', include(router.urls)) diff --git a/main/views.py b/main/views.py index 9971c58..0129b3a 100644 --- a/main/views.py +++ b/main/views.py @@ -1,7 +1,3 @@ -import logging -import os -from datetime import datetime - from smtplib import SMTPException from django.contrib import messages @@ -13,7 +9,6 @@ from django.contrib.auth.forms import PasswordResetForm from django.contrib.auth.views import LoginView from django.contrib.contenttypes.models import ContentType from django.contrib.messages.views import SuccessMessageMixin -from django.core.exceptions import PermissionDenied from django.core.handlers.wsgi import WSGIRequest from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render, redirect, get_list_or_404 @@ -25,7 +20,7 @@ from rest_framework import viewsets from rest_framework.response import Response from zenpy.lib.api_objects import User as ZenpyUser -from access_controller.settings import EMAIL_HOST_USER, ZENDESK_ROLES, ZENDESK_MAX_AGENTS, ZENDESK_GROUPS +from access_controller.settings import DEFAULT_FROM_EMAIL, ZENDESK_ROLES, ZENDESK_MAX_AGENTS from main.extra_func import check_user_exist, update_profile, get_user_organization, \ make_engineer, make_light_agent, get_users_list, update_users_in_model, count_users, \ StatisticData, log, ZendeskAdmin @@ -36,7 +31,6 @@ from .models import UserProfile def setup_context(profile_lit: bool = False, control_lit: bool = False, work_lit: bool = False, registration_lit: bool = False, login_lit: bool = False): - print(profile_lit, control_lit, work_lit, registration_lit, login_lit) context = { 'profile_lit': profile_lit, 'control_lit': control_lit, @@ -88,7 +82,7 @@ class CustomRegistrationView(RegistrationView): opts = { 'use_https': self.request.is_secure(), 'token_generator': default_token_generator, - 'from_email': EMAIL_HOST_USER, + 'from_email': DEFAULT_FROM_EMAIL, 'email_template_name': 'registration/password_reset_email.html', 'subject_template_name': 'registration/password_reset_subject.txt', 'request': self.request, @@ -205,23 +199,6 @@ def work_page(request: WSGIRequest, id: int) -> HttpResponse: return redirect("login") -def user_update(zenpy_user: User, admin: User, request: WSGIRequest) -> UserProfile: - """ - Функция устанавливает пользователю роль "agent" (изменяет профиль). - - :param zenpy_user: Пользователь Zendesk - :param admin: Пользователь - :param request: Запрос установки роли "agent" в Userprofile - :return: Обновленный профиль пользователя - """ - - admin.users.update(zenpy_user) - request.user.userprofile.role = "agent" - request.user.userprofile.custom_role_id = zenpy_user.custom_role_id - request.user.userprofile.save() - messages.success(request, "Права были изменены") - - @login_required() def work_hand_over(request: WSGIRequest) -> HttpResponseRedirect: """ @@ -348,7 +325,6 @@ class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageM return context # TODO: need to get profile page url - class CustomLoginView(LoginView): """ Отображение страницы авторизации пользователя From 18cc98f11adc780670f3810c7ce28f642c664ae3 Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Thu, 15 Apr 2021 19:55:34 +0300 Subject: [PATCH 2/2] Fix type hints --- docs/source/conf.py | 3 +++ main/extra_func.py | 8 ++++---- main/forms.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 7e99943..d45b1cd 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -132,6 +132,7 @@ extensions = { 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.viewcode', + 'sphinx.ext.napoleon', 'sphinx_rtd_theme', 'sphinx.ext.graphviz', 'sphinx.ext.inheritance_diagram', @@ -205,3 +206,5 @@ set_type_checking_flag = True typehints_fully_qualified = True always_document_param_types = True typehints_document_rtype = True + +napoleon_attr_annotations = True diff --git a/main/extra_func.py b/main/extra_func.py index 758875a..27986c8 100644 --- a/main/extra_func.py +++ b/main/extra_func.py @@ -114,7 +114,7 @@ class ZendeskAdmin: user = self.admin.users.search(email).values[0] return user.organization.name if user.organization else None - def create_admin(self) -> Zenpy: + def create_admin(self) -> None: """ Функция создает администратора, проверяя наличие вводимых данных в env. @@ -141,7 +141,7 @@ class ZendeskAdmin: raise ValueError('invalid access_controller`s login data') -def update_role(user_profile: UserProfile, role: int) -> UserProfile: +def update_role(user_profile: UserProfile, role: int) -> None: """ Функция меняет роль пользователя. @@ -157,7 +157,7 @@ def update_role(user_profile: UserProfile, role: int) -> UserProfile: zendesk.admin.users.update(user) -def make_engineer(user_profile: UserProfile, who_changes: User) -> UserProfile: +def make_engineer(user_profile: UserProfile, who_changes: User) -> None: """ Функция устанавливает пользователю роль инженера. @@ -167,7 +167,7 @@ def make_engineer(user_profile: UserProfile, who_changes: User) -> UserProfile: update_role(user_profile, ROLES['engineer']) -def make_light_agent(user_profile: UserProfile, who_changes: User) -> UserProfile: +def make_light_agent(user_profile: UserProfile, who_changes: User) -> None: """ Функция устанавливает пользователю роль легкого агента. diff --git a/main/forms.py b/main/forms.py index 613fc34..22bd76b 100644 --- a/main/forms.py +++ b/main/forms.py @@ -14,7 +14,7 @@ class CustomRegistrationForm(RegistrationFormUniqueEmail): :type visible_fields.email: :class:`django_registration.forms.RegistrationFormUniqueEmail` """ - def __init__(self, *args, **kwargs) -> RegistrationFormUniqueEmail: + def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) for visible in self.visible_fields(): if visible.field.widget.attrs.get('class', False):