def _set_submit_deadline(self, thesis: 'Thesis', submit_deadline: Union[str, datetime]): if isinstance(submit_deadline, str): thesis.submit_deadline = parse_date(submit_deadline) if isinstance(submit_deadline, datetime): thesis.submit_deadline = submit_deadline.date() return thesis.submit_deadline
def create(self, request: Request, *args, **kwargs): to_import: Optional[TemporaryUploadedFile] = request.FILES.get('import') published_at = parse_date((request.data.get('published_at') + '/01').replace('/', '-')) if not (to_import and published_at): return Response( data=dict( error=True, message=_('Missing some of needed arguments.'), success=False, ), status=HTTP_400_BAD_REQUEST, ) return Thesis.import_objects.import_from_file( file_to_import=to_import, published_at=published_at, is_final_import=request.data.get('final') == str(True).lower() )
def perform_create(self, serializer: ThesisFullPublicSerializer): thesis = serializer.save( category=get_object_or_404(Category, pk=serializer.initial_data.get('category')), supervisor=serializer.validated_data.get('supervisor'), authors=get_list_or_404( get_user_model(), pk__in=serializer.initial_data.get('authors').split(',') ), published_at=parse_date((serializer.initial_data.get('published_at') + '/01').replace('/', '-')) ) admission = self.request.FILES.get('admission') if admission: Attachment.objects.create_from_upload( uploaded=admission, thesis=thesis, type_attachment=TypeAttachment.objects.get_by_identifier(TypeAttachment.Identifier.THESIS_ASSIGMENT), ) thesis.state = Thesis.State.READY_FOR_SUBMIT thesis.save()
class ThesisViewSet(ModelViewSet): queryset = Thesis.api_objects.get_queryset() pagination_class = DynamicPageSizePagination search_fields = ( 'title__unaccent', 'abstract__unaccent', 'registration_number', 'state', '=authors__username', 'authors__first_name__unaccent', 'authors__last_name__unaccent', '=supervisor__username', 'supervisor__first_name__unaccent', 'supervisor__last_name__unaccent', '=opponent__username', 'opponent__first_name__unaccent', 'opponent__last_name__unaccent', '=category__id', 'category__title', '=published_at_year', ) def get_queryset(self): qs = super().get_queryset() # type: QuerySet user = self.request.user # type: User qs = qs.annotate( _reservable=F('reservable') and Exists( queryset=Reservation.open_reservations.filter( thesis_id=OuterRef('pk'), user=user, ), negated=True, ) ) # no perms to see all thesis, so filter only published ones if not user.has_perm('thesis.change_thesis'): qs = qs.filter( Q(state=Thesis.State.PUBLISHED) | Q(authors=user) | Q(opponent=user, state=Thesis.State.READY_FOR_REVIEW) | Q(supervisor=user, state=Thesis.State.READY_FOR_REVIEW) ) return qs @transaction.atomic def perform_create(self, serializer: ThesisFullPublicSerializer): thesis = serializer.save( category=get_object_or_404(Category, pk=serializer.initial_data.get('category')), supervisor=serializer.validated_data.get('supervisor'), authors=get_list_or_404( get_user_model(), pk__in=serializer.initial_data.get('authors').split(',') ), published_at=parse_date((serializer.initial_data.get('published_at') + '/01').replace('/', '-')) ) admission = self.request.FILES.get('admission') if admission: Attachment.objects.create_from_upload( uploaded=admission, thesis=thesis, type_attachment=TypeAttachment.objects.get_by_identifier(TypeAttachment.Identifier.THESIS_ASSIGMENT), ) thesis.state = Thesis.State.READY_FOR_SUBMIT thesis.save() @transaction.atomic def perform_update(self, serializer: ThesisFullInternalSerializer): data = dict() if author_pks := serializer.initial_data.get('authors'): data['authors'] = get_list_or_404( get_user_model(), pk__in=author_pks ) if published_at := serializer.initial_data.get('published_at'): data['published_at'] = parse_date((published_at + '/01').replace('/', '-'))