def post(self, request: HttpRequest, user: User) -> HttpResponse: form = GenGroupByFileForm(request.POST, request.FILES) if not form.is_valid(): message = str(form.errors.as_data()) return HttpResponse(message) byte_data: bytes = request.FILES['file'].read() data = byte_data.decode('utf-8') norm_data = json.loads(data) teacher = Teacher.objects.get(user=user) try: for group_data in norm_data: try: group = StudGroup.objects.create(name=group_data['group']) except IntegrityError: group = StudGroup.objects.get(name=group_data['group']) users_list: list = group_data['users'] for user_str in users_list: try: surname, name, middlename = user_str.split(' ') except ValueError: return Notification.error( 'Опечатка в {}'.format(user_str)) try: user = User.objects.get(family_name=surname, given_name=name, middle_name=middlename) except User.DoesNotExist: return Notification.error( 'Пользователь {} не найден'.format(user_str)) group.users.add(user) group.save() teacher.groups.add(group) teacher.save() except Exception as e: raise e return Notification.error(str(e)) return Notification.success( 'Группа успешно создана и прикреплена к вам!')
def resumed(): notification = Notification('Debugger.resumed') return notification
def paused(): notification = Notification('Debugger.paused') return notification
def scriptParsed(): notification = Notification('Debugger.scriptParsed') return notification
def reloaded(): notification = Notification('Page.loadEventFired') return notification
def globalObjectCleared(): notification = Notification('Debugger.globalObjectCleared') return notification
def messagesCleared(): notification = Notification('Console.messagesCleared') return notification
def messageRepeatCountUpdated(): notification = Notification('Console.messageRepeatCountUpdated') return notification
def messageAdded(): notification = Notification('Console.messageAdded') return notification