def post(self, request, format=None): try: student = Students(**request.prepared) student.creator = request.session['name'] student.save() return APIResponse(code=200, data={'id': student.id}) except ValidationError as ex: return APIResponse(code=400, error=ex)
def post(self, request, format=None): try: teacher = Teachers(**request.prepared) teacher.creator = request.session['name'] teacher.save() return APIResponse(code=200, data={'id': teacher.id}) except ValidationError as ex: return APIResponse(code=400, error=ex)
def get(self, request, format=None): id = request.prepared['id'] try: student = Students.active.get(pk=id) except Students.DoesNotExist as ex: return APIResponse(code=404, error=ex) else: serialized = student.serialize() return APIResponse(data=serialized, code=200)
def post(self, request, format=None): login = request.prepared['login'] password = request.prepared['password'] user = Users.verify(login, password) if user is not None: session.init(request.session, user) return APIResponse(code=200) else: return APIResponse(code=404)
def put(self, request, format=None): data = request.prepared qs = Students.active.filter(pk=data['id']) del data['id'] try: count = Students.update(qs, **data) except ValidationError as ex: return APIResponse(code=400, error=ex) else: if count > 0: return APIResponse(code=200) else: return APIResponse(code=404)
def put(self, request, format=None): data = request.prepared qs = Subscriptions.active.filter(pk=data['id']) del data['id'] if 'status' in data: data['status_date'] = timezone.now() try: count = Subscriptions.update(qs, **data) except ValidationError as ex: return APIResponse(code=400, error=ex) else: if count > 0: return APIResponse(code=200) else: return APIResponse(code=404)
def post(self, request, format=None): data = request.prepared subtype = SubTypes.get(data['subtype']) if subtype is not None: try: datenow = datetime.now() sub = Subscriptions() sub.student_id = data['student_id'] sub.mode = subtype['mode'] sub.lessons_total = subtype['lessons'] sub.date_start = datenow sub.date_end = datenow + relativedelta(months=subtype['months']) sub.changes_left = subtype['changes'] sub.creator = request.session['name'] sub.save() return APIResponse(code=200, data=sub.serialize()) except ValidationError as ex: return APIResponse(code=400, error=ex) else: return APIResponse(code=404)
def get(self, request, format=None): teacher_id = request.prepared['teacher_id'] year = request.prepared['year'] month = request.prepared['month'] + 1 lessons = Lessons.active.filter(teacher=teacher_id, date__year=year, date__month=month) lessons = lessons.serialize('basic', extra_fields=['logbook_id']) Visits.get_reverse_related(lessons, 'lesson_id', 'default', many=True, extra_fields=['student_id']) visits = [x for y in lessons for x in y['visits']] Visits.get_related(visits, related={'student': 'basic'}, many=True) return APIResponse(data=lessons, code=200)
def delete(self, request, format=None): if request.authorized: request.session.flush() return APIResponse(code=200) else: return APIResponse(code=405)
def delete(self, request, format=None): id = request.prepared['id'] Subscriptions.objects.filter(pk=id).update(status='d', status_date=timezone.now()) return APIResponse(code=200)
def get(self, request, format=None): students = Students.get_all(serializer='search') return APIResponse(data=students.values(), code=200)