Exemplo n.º 1
0
    def modify_certificates(self, request, pk=None):
        calendar = self.get_object()
        certificate_id = request.query_params['cert_id']

        try:
            certificate = Certificate.objects.get(id=certificate_id)
        except Certificate.DoesNotExist:
            raise NotFound('Certificate "%s" not found.' % certificate_id)

        if request.method == 'POST':
            # check if already there, and if so, raise 409
            if calendar.certificates.filter(id=certificate.id).exists():
                raise ContentError('Certificate "%s" already selected.' %
                                   certificate_id)

            calendar.certificates.add(certificate)
        elif request.method == 'DELETE':
            if not calendar.certificates.filter(id=certificate.id).exists():
                raise ContentError('Certificate "%s" not in this calendar.' %
                                   course_id)

            calendar.certificates.remove(certificate)

        genie.clear_cached_recommendations(calendar.profile_id, calendar.pk)
        return Response({'success': True})
Exemplo n.º 2
0
    def modify_course(self, request, pk=None):
        semester = self.get_object()

        search_kwargs = {}
        course_name = ''
        if 'course_id' in request.query_params:
            course_name = request.query_params['course_id']
            search_kwargs['course_id'] = course_name
        elif 'short_name' in request.query_params:
            course_name = request.query_params['short_name']
            short_name = COURSE_RE.match(course_name)
            if not short_name:
                raise NotAcceptable(
                    detail='short_name field does not match pattern.')

            search_kwargs['number'] = short_name.group('num')
            search_kwargs['department'] = short_name.group('dept')
            if short_name.group('letter'):
                search_kwargs['letter'] = short_name.group('letter')
        else:
            raise NotAcceptable(
                detail='short_name or course_id parameter required.')

        try:
            course = Course.objects.get(**search_kwargs)
        except Course.DoesNotExist:
            raise NotFound('Course "%s" not found.' % course_name)

        if request.method == 'POST':
            # check if already there, and if so, raise 409
            if semester.courses.filter(id=course.id).exists():
                raise ContentError('Course "%s" already in semester.' %
                                   course_name)

            semester.courses.add(course)
        elif request.method == 'DELETE':
            if not semester.courses.filter(id=course.id).exists():
                raise ContentError('Course "%s" not in semester.' %
                                   course_name)

            semester.courses.remove(course)

        genie.clear_cached_recommendations(semester.calendar.profile_id)
        serializer = CourseSerializer(course)
        return Response(serializer.data)
Exemplo n.º 3
0
    def modify_dept(self, request, pk=None):
        pref = self.get_object()
        short_name = request.query_params['short_name']
        t = request.query_params['t']

        if t not in {'wl', 'bl'}:
            raise NotFound('Department "%s" not found for type "%s".' %
                           (short_name, t))

        if t == 'wl':
            pref_list = pref.wl_depts
            other_list = pref.bl_depts
        else:
            pref_list = pref.bl_depts
            other_list = pref.wl_depts

        try:
            dept = Department.objects.get(short_name=short_name)
        except Department.DoesNotExist:
            raise NotFound('Department "%s" not found.' % short_name)

        if request.method == 'POST':
            # check if already there, and if so, raise 409
            if pref_list.filter(id=dept.id).exists():
                raise ContentError('Department "%s" already in list.' %
                                   short_name)

            if other_list.filter(id=dept.id).exists():
                raise ContentError('Department "%s" in opposing list.' %
                                   short_name)

            pref_list.add(dept)
        elif request.method == 'DELETE':
            if not pref_list.filter(id=dept.id).exists():
                raise ContentError('Department "%s" not in list.' % short_name)

            pref_list.remove(dept)

        genie.clear_cached_recommendations(pref.profile_id)
        return Response({'success': True})
Exemplo n.º 4
0
    def post(self, request):
        data = json.loads(request.POST['data'])
        user = request.user
        genie.store_manual(user, data['courses'])
        user.first_name = data['user']['first_name']
        user.last_name = data['user']['last_name']
        user.profile.year = int(data['graduation_year'])

        if not (user.profile.submitted
                and Calendar.objects.filter(profile=user.profile).exists()):
            calendar = Calendar.objects.create(profile=user.profile,
                                               degree_id=1,
                                               major_id=int(data['major']),
                                               name='Default Calendar')
            genie.generate_semesters(calendar)

        user.profile.submitted = True
        user.save()
        user.profile.save()

        genie.clear_cached_recommendations(user.profile.id)
        return redirect('core:dashboard')
Exemplo n.º 5
0
 def partial_update(self, request, pk=None, *args, **kwargs):
     obj = self.get_object()
     genie.clear_cached_recommendations(obj.profile_id, obj.pk)
     return super(CalendarViewSet,
                  self).partial_update(request, pk, *args, **kwargs)
Exemplo n.º 6
0
 def update(self, request, pk=None, *args, **kwargs):
     obj = self.get_object()
     genie.clear_cached_recommendations(obj.calendar.profile_id,
                                        obj.calendar_id)
     return super(ProgressViewSet, self).update(request, pk, *args,
                                                **kwargs)