def get_sections():
    total_c = 0
    total_s = 0
    courses = Course.objects.all()
    for course in courses:
        total_s += 1
        try:
            link = "https://apis-dev.berkeley.edu/cxf/asws/classoffering/" + course.code + "?_type=json&app_id=a641ceca&app_key=eea0330432f77b498709afe6fe7fb6f8"
            data = json.loads(urlopen(link).read())
            sections = data["ClassOffering"]["sections"]
            if type(sections) == list:
                for section in sections:
                    total_c += 1
                    number = section['sectionNumber']
                    s = Section()
                    s.init(number, course)
                    s.save()
            elif type(sections) == dict:
                total_c += 1
                number = sections['sectionNumber']
                s = Section()
                s.init(number, course)
                s.save()
        except Exception:
            continue
        print "Courses:   " + str(total_s) + " / " + str(len(courses)) + "     Sections:   " + str(total_c)    
Beispiel #2
0
    def post(self, request):
        response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                         'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
        try:
            road_id = int(request.POST.get('roadId', 0))
            district_id = int(request.POST.get('districtId'))
            name = request.POST.get('name')
            start_place = request.POST.get('startPlace')
            end_place = request.POST.get('endPlace')
            xy_coordinate = request.POST.get('XYCOORDINATE', '')
            channel = request.POST.get('channel', '')
            call_sign = request.POST.get('callSign', '')
            remark_1 = request.POST.get('remark1', '')
            remark_2 = request.POST.get('remark2', '')
            remark_3 = request.POST.get('remark3', '')
        except Exception as ex:
            print 'function name: ', __name__
            print Exception, ":", ex
            return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)

        if road_id:
            cur_section = Section(name=name, start_place=start_place, end_place=end_place,
                                                 xy_coordinate=xy_coordinate, road_id=road_id, channel=channel,
                                                 call_sign=call_sign, remark1=remark_1, remark2=remark_2,
                                                 remark3=remark_3, district_id=Road.objects.get(id=road_id).district_id)

            try:
                with transaction.atomic():
                    cur_section.save()
            except Exception as ex:
                print 'function name: ', __name__
                print Exception, ":", ex
                return generate_error_response(error_constants.ERR_SAVE_INFO_FAIL,
                                               status.HTTP_500_INTERNAL_SERVER_ERROR)
            update_road_section_ids(road_id, cur_section.id, True)
        else:
            cur_section = Section(name=name, start_place=start_place,
                                                 end_place=end_place, xy_coordinate=xy_coordinate,
                                                 remark1=remark_1, channel=channel, call_sign=call_sign,
                                                 remark2=remark_2, remark3=remark_3, district_id=district_id)
            try:
                with transaction.atomic():
                    cur_section.save()
            except Exception as ex:
                print 'function name: ', __name__
                print Exception, ":", ex
                return generate_error_response(error_constants.ERR_SAVE_INFO_FAIL,
                                               status.HTTP_500_INTERNAL_SERVER_ERROR)
        return Response(response_data, status=status.HTTP_200_OK)
Beispiel #3
0
    def restore_object(self, attrs, instance=None):
        classgroup = attrs.get('classgroup')
        name = attrs.get('name')

        user = self.context['request'].user

        if instance is None:
            instance = Section(classgroup=classgroup, name=alphanumeric_name(name), display_name=name)
            instance.save()
        else:
            if not ClassGroupPermissions.is_teacher(classgroup, user):
                raise serializers.ValidationError("You do not have permission to modify this section.")
            instance.name = alphanumeric_name(name)
            instance.display_name = name
        return instance
Beispiel #4
0
 def post(self, request):
     response_data = {'retCode': error_constants.ERR_STATUS_SUCCESS[0],
                      'retMsg': error_constants.ERR_STATUS_SUCCESS[1]}
     try:
         section_id = int(request.POST.get('sectionId'))
         name = request.POST.get('name')
         start_place = request.POST.get('startPlace')
         end_place = request.POST.get('endPlace')
         xy_coordinate = request.POST.get('XYCOORDINATE', '')
         channel = request.POST.get('channel', '')
         call_sign = request.POST.get('callSign', '')
         remark_1 = request.POST.get('remark1', '')
         remark_2 = request.POST.get('remark2', '')
         remark_3 = request.POST.get('remark3', '')
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_INVALID_PARAMETER, status.HTTP_400_BAD_REQUEST)
     cur_section = Section.objects.get(id=section_id)
     district_id = cur_section.district_id
     new_section = Section(name=name, start_place=start_place, channel=channel, call_sign=call_sign,
                                          end_place=end_place, xy_coordinate=xy_coordinate,
                                          remark1=remark_1, remark2=remark_2, remark3=remark_3,
                                          district_id=district_id)
     try:
         with transaction.atomic():
             new_section.save()
     except Exception as ex:
         print 'function name: ', __name__
         print Exception, ":", ex
         return generate_error_response(error_constants.ERR_SAVE_INFO_FAIL,
                                        status.HTTP_500_INTERNAL_SERVER_ERROR)
     chief = cur_section.chief.all()
     bureau = cur_section.exec_chief_sub_bureau.all()
     trans = cur_section.exec_chief_trans.all()
     arm_poli = cur_section.exec_chief_armed_poli.all()
     for item in chief:
         new_section.chief.add(item)
     for item in bureau:
         new_section.exec_chief_sub_bureau.add(item)
     for item in trans:
         new_section.exec_chief_trans.add(item)
     for item in arm_poli:
         new_section.exec_chief_armed_poli.add(item)
     # 复制段时将岗及人员全部复制关联
     copy_station_to_new_section(new_section, cur_section)
     return Response(response_data, status.HTTP_200_OK)
Beispiel #5
0
def sections(request):
    if request.method == 'POST':
       # save new post
       heading = request.POST['heading']
       content = request.POST['content']
       
       section = Section(heading=heading)
       section.heading = heading
#       section.content = cgi.escape(content).encode("ascii", "xmlcharrefreplace")
       section.content = content
       section.save()

    # Get all sections from DB
    sections = Section.objects

    return render_to_response('admin/index.html', {'Sections': sections},
                              context_instance=RequestContext(request))
Beispiel #6
0
def sections(request):
    if request.method == 'POST':
        # save new post
        heading = request.POST['heading']
        content = request.POST['content']

        section = Section(heading=heading)
        section.heading = heading
        #       section.content = cgi.escape(content).encode("ascii", "xmlcharrefreplace")
        section.content = content
        section.save()

    # Get all sections from DB
    sections = Section.objects

    return render_to_response('admin/index.html', {'Sections': sections},
                              context_instance=RequestContext(request))
Beispiel #7
0
    def restore_object(self, attrs, instance=None):
        classgroup = attrs.get('classgroup')
        name = attrs.get('name')

        user = self.context['request'].user

        if instance is None:
            instance = Section(classgroup=classgroup,
                               name=alphanumeric_name(name),
                               display_name=name)
            instance.save()
        else:
            if not ClassGroupPermissions.is_teacher(classgroup, user):
                raise serializers.ValidationError(
                    "You do not have permission to modify this section.")
            instance.name = alphanumeric_name(name)
            instance.display_name = name
        return instance
Beispiel #8
0
def manage_sections(request):
    """
    Render the page where instructors can go to make a new section or
    edit existing ones.
    """

    if request.method == "POST":
        # Class is being submitted
        form = NewSectionForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data["name"]
            new_section = Section(name=name)
            new_section.save()
            return HttpResponseRedirect("/managesection/")

    form = NewSectionForm()
    sections = Section.objects.all()
    context = {
        "form": form,
        "sections": sections,
        "listSize": sections.count()
    }
    return render(request, "managesection.html", context)