Merge branch 'fil_P-10' into P-10
This commit is contained in:
commit
2ddc208bdc
6 files changed
+84
-15
No files matched your search
@@ -47,11 +47,12 @@ from ckeditor_uploader.fields import RichTextUploadingField
|
|||||||
|
|
||||||
# Модели(Таблицы) для хранения календаря
|
# Модели(Таблицы) для хранения календаря
|
||||||
class Calendar(models.Model):
|
class Calendar(models.Model):
|
||||||
author = models.ForeignKey(DictEmployee,blank=True,null=True, on_delete=models.PROTECT, verbose_name='Автор календаря')
|
author = models.ForeignKey(DictEmployee, on_delete=models.PROTECT, verbose_name='Автор календаря')
|
||||||
cl_name = models.CharField(max_length=300, verbose_name='Название')
|
cl_name = models.CharField(max_length=300, verbose_name='Название')
|
||||||
cl_color = models.CharField(max_length=300, verbose_name='Цвет')
|
cl_color = models.CharField(max_length=300, verbose_name='Цвет', null=True)
|
||||||
cl_descr = models.CharField(max_length=300, verbose_name='Описание')
|
cl_descr = models.CharField(max_length=300, verbose_name='Описание')
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Календарь"
|
verbose_name = "Календарь"
|
||||||
verbose_name_plural = "Календари"
|
verbose_name_plural = "Календари"
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class CalendarEventSerializer(serializers.ModelSerializer):
|
|||||||
model = Event
|
model = Event
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CalendarsSerializer(serializers.ModelSerializer):
|
class CalendarsSerializer(serializers.ModelSerializer):
|
||||||
""" Сериализатор календарей """
|
""" Сериализатор календарей """
|
||||||
# editor = serializers.SerializerMethodField("is_editor")
|
# editor = serializers.SerializerMethodField("is_editor")
|
||||||
@@ -62,12 +64,7 @@ class EmployeeSerializer(serializers.ModelSerializer):
|
|||||||
fields = ["title","id","employees",'selected']
|
fields = ["title","id","employees",'selected']
|
||||||
|
|
||||||
def get_deps(self,obj):
|
def get_deps(self,obj):
|
||||||
# все было в принципе круто, но вот момент
|
|
||||||
# смотри, поменял.
|
|
||||||
# Я добавил просто в модели DictEmployee полю id_dict_department related_name
|
|
||||||
# Соответствено, переходя от отдела, нам уже не надо фильтровать всю таблицу сотрудников, а можем фильтровать только по актуальности дочек объекта отдела - его сотрудников )
|
|
||||||
# Мелочь, но, получается короче и, по идее, минус действие
|
|
||||||
# Ну и наследоваться от INFOUSERCARD смысла тут нет - мы его и не используем
|
|
||||||
return UsersSerializer(obj.dep_user.filter(deleted=0), many=True).data
|
return UsersSerializer(obj.dep_user.filter(deleted=0), many=True).data
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -79,3 +76,27 @@ class UsersSerializer(serializers.ModelSerializer):
|
|||||||
fields = ['title', "id", 'id_dict_department','selected' ]
|
fields = ['title', "id", 'id_dict_department','selected' ]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MyCalendarPostParametersParticipants(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = CalendarParticipants
|
||||||
|
exclude = ['calendar','id']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MyCalendarPostParameters(serializers.ModelSerializer):
|
||||||
|
id=serializers.IntegerField(required=False)
|
||||||
|
# author = serializers.IntegerField(required=False)
|
||||||
|
participant = MyCalendarPostParametersParticipants(source="get_participants", many=True, required=False)
|
||||||
|
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Calendar
|
||||||
|
exclude =['author']
|
||||||
|
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ from .views import *
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# path('calendarEvents/', CalendarEventsAPIView.as_view(), name='calendarEvents'),
|
# path('calendarEvents/', CalendarEventsAPIView.as_view(), name='calendarEvents'),
|
||||||
path('get_employees/', GetEmployees.as_view(), name='get_employees'),
|
path('get_employees/', GetEmployees.as_view(), name='get_employees'),
|
||||||
path('get_calendars/', GetCalendars.as_view(), name='get_calendars'),
|
path('my_calendars/', MyCalendars.as_view(), name='get_calendars'),
|
||||||
path('exclusion_dates/', ExclusionDatesAPIView.as_view(), name='exclusion_dates'),
|
path('exclusion_dates/', ExclusionDatesAPIView.as_view(), name='exclusion_dates'),
|
||||||
# path('createEvents/', CreateEventsAPIView.as_view(), name='createEvents')
|
# path('createEvents/', CreateEventsAPIView.as_view(), name='createEvents')
|
||||||
]
|
]
|
||||||
@@ -7,7 +7,7 @@ from rest_framework.response import Response
|
|||||||
import json
|
import json
|
||||||
from django.db.models.functions import TruncYear
|
from django.db.models.functions import TruncYear
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from drf_yasg.utils import swagger_auto_schema
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -22,13 +22,47 @@ class ExclusionDatesAPIView(APIView):
|
|||||||
return Response({year:months})
|
return Response({year:months})
|
||||||
|
|
||||||
|
|
||||||
class GetCalendars(APIView):
|
class MyCalendars(APIView):
|
||||||
def get(self, request):
|
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
calendars = Calendar.objects.filter(Q(get_participants__participant_calendar__id=request.user.user.id) | Q(author__id=request.user.user.id)).distinct()
|
calendars = Calendar.objects.filter(Q(get_participants__participant_calendar__id=request.user.user.id) | Q(author__id=request.user.user.id)).distinct()
|
||||||
return Response(CalendarsSerializer(calendars,many=True).data)
|
return Response(CalendarsSerializer(calendars,many=True).data)
|
||||||
# return Response(CalendarsSerializer(calendars,context={'request': request},many=True).data)
|
|
||||||
#
|
@swagger_auto_schema(request_body=MyCalendarPostParameters)
|
||||||
|
def post(self,request):
|
||||||
|
'''
|
||||||
|
Создание/редактирование календаря
|
||||||
|
если нет id = пойдет создавать календарь. В противном случае - на обновление
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
ob=MyCalendarPostParameters(data=request.data)
|
||||||
|
if ob.is_valid():
|
||||||
|
ob = ob.data
|
||||||
|
if 'id' in ob:
|
||||||
|
newcal,created = Calendar.objects.update_or_create(id=ob['id'],defaults=ob)
|
||||||
|
|
||||||
|
else:
|
||||||
|
newcal=Calendar.objects.create(**ob, author=DictEmployee(id=request.user.user.id))
|
||||||
|
|
||||||
|
if 'participant' in ob:
|
||||||
|
ptspnt = []
|
||||||
|
for x in ob['participant']:
|
||||||
|
x['participant_calendar']=DictEmployee(id=x['participant_calendar'])
|
||||||
|
print(x['participant_calendar'])
|
||||||
|
CalendarParticipants.objects.update_or_create(calendar=newcal, participant_calendar=x['participant_calendar'],
|
||||||
|
defaults=x)
|
||||||
|
ptspnt.append(x['participant_calendar'])
|
||||||
|
print(ptspnt)
|
||||||
|
CalendarParticipants.objects.exclude(calendar=newcal,participant_calendar__in=ptspnt).delete()
|
||||||
|
else:
|
||||||
|
return Response({"mess":"Ошибка валидации полей"})
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return Response({"mess":"Ошибка операции"})
|
||||||
|
|
||||||
|
return Response({"mess": f"Календарь успешно {'обновлен' if 'id' in ob else 'создан'}"})
|
||||||
|
|
||||||
|
|
||||||
class GetEmployees(APIView):
|
class GetEmployees(APIView):
|
||||||
|
|||||||
@@ -24,7 +24,19 @@ SECRET_KEY=stngs.secret_key
|
|||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
myDEBUG=True
|
myDEBUG=True
|
||||||
|
SWAGGER_SETTINGS = {
|
||||||
|
'DEFAULT_INFO': 'import.path.to.urls.api_info',
|
||||||
|
'SECURITY_DEFINITIONS': {
|
||||||
|
'Basic': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'Bearer': {
|
||||||
|
'type': 'apiKey',
|
||||||
|
'name': 'Authorization',
|
||||||
|
'in': 'header'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = []
|
||||||
CHANNEL_LAYERS = {
|
CHANNEL_LAYERS = {
|
||||||
"default": {
|
"default": {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ schema_view = get_schema_view(
|
|||||||
title="Портал API",
|
title="Портал API",
|
||||||
default_version='v0.1',
|
default_version='v0.1',
|
||||||
description="API портала инспекции 9966",
|
description="API портала инспекции 9966",
|
||||||
|
|
||||||
# terms_of_service="https://www.google.com/policies/terms/",
|
# terms_of_service="https://www.google.com/policies/terms/",
|
||||||
# contact=openapi.Contact(email="contact@snippets.local"),
|
# contact=openapi.Contact(email="contact@snippets.local"),
|
||||||
# license=openapi.License(name="BSD License"),
|
# license=openapi.License(name="BSD License"),
|
||||||
|
|||||||
Reference in new issue
Block a user