コード例 #1
0
ファイル: tasks.py プロジェクト: RyanCccc/PurdueCourseSeats
def update_secs(secs):
    for sec in secs:
        max_num, curr_num, name, code, number = util.get_all(sec.crn, sec.term)
        rem_num = max_num - curr_num
        old_remain = sec.remain_seats_num
        seats_change = rem_num - sec.remain_seats_num
        sec.max_seats_num = max_num
        sec.current_seats_num = curr_num
        sec.remain_seats_num = rem_num
        sec.save()
        if seats_change > 0:
            msg = "Wow! your class %s has new seats released!!\n Remain seats change from %s to %s" % (
                sec.crn,
                str(old_remain),
                str(rem_num),
            )
            msg += (
                "\n\n Once you don't need this section any more, "
                "you can log in purdue-class.chenrendong.com to remove this"
                " section."
            )
            users = sec.myuser_set.all()
            restricts = sec.send_restrict.all()
            if not old_remain:
                emails = [user.user.email for user in users]
            else:
                emails = [user.user.email for user in users if user not in restricts]
            if emails:
                send_email.delay(emails, msg)
        elif seats_change < 0:
            msg = "Sorry!!! You class\n %s \nSeats are decreasing!!\n" % sec.crn
            msg += "Remain seats change from %s to %s" % (str(rem_num - seats_change), str(rem_num))
コード例 #2
0
ファイル: models.py プロジェクト: RyanCccc/PurdueCourseSeats
 def create_new_section(self, crn, term):
     try:
         max_num, curr_num, name, code, number = get_all(crn, term)
         return self.create_section(
                     crn, 
                     max_num,
                     curr_num,
                     term,
                     name,
                     code,
                     number,
                 )
     except ParserException as e:
         return e
コード例 #3
0
ファイル: views.py プロジェクト: RyanCccc/PurdueCourseSeats
def seats_check(request, class_crn = None):
    result = None
    exists = True

    #GET
    if request.method == 'GET':
        term = request.GET.get('term', settings.CURRENT_TERM)
        try:
            term = convert_term_to_code(term)
        except:
            term = settings.CURRENT_TERM

        try:
            sec = Section.objects.get(crn = class_crn, term = term)
        except:
            exists = False

        if not exists:
            try:
                max_num, curr_num, name, code, number = get_all(class_crn, term)
                result = json.dumps(
                    {'code': 1,
                        'content': {'max_num' : max_num,
                                    'curr_num' : curr_num,
                                    'rem_num' : (max_num - curr_num),
                                    'name' : name,
                                    'code' : code,
                                    'number' : number,
                                   }
                    }
                )
            except Exception as e:
                result = json.dumps({'code' : 0, 'content': str(e)})
        else:
            max_num = sec.max_seats_num
            curr_num = sec.current_seats_num
            rem_num = sec.remain_seats_num
            name = sec.name
            code = sec.code
            number = sec.number
            result = json.dumps(
                {'code': 1,
                    'content': {'max_num' : max_num,
                                'curr_num' : curr_num,
                                'rem_num' : rem_num,
                                'name' : name,
                                'code' : code,
                                'number' : number,
                               }
                }
            )

    # POST
    elif request.method == 'POST':
        post_json = json.loads(request.body)
        term = post_json['term']
        if not term:
            term = settings.CURRENT_TERM
        crns = post_json['content']
        result = []
        for crn in crns:
            try:
                sec = Section.objects.get(crn = class_crn, term = term)
            except:
                exists = False
            if not exists:
                try:
                    max_num, curr_num, name, code, number = get_all(crn, term)
                    result += json.dumps(
                        {'code': 1,
                            'content': {'max_num' : max_num,
                                        'curr_num' : curr_num,
                                        'rem_num' : (max_num - curr_num),
                                        'name' : name,
                                        'code' : code,
                                        'number' : number,
                                       }
                        }
                    )
                except Exception as e:
                    result += json.dumps({'code' : 0, 'content': str(e)})
            else:
                max_num = sec.max_seats_num
                curr_num = sec.current_seats_num
                rem_num = sec.remain_seats_num
                name = sec.name
                code = sec.code
                number = sec.number
                result += json.dumps(
                    {'code': 1,
                        'content': {'max_num' : max_num,
                                    'curr_num' : curr_num,
                                    'rem_num' : rem_num,
                                    'name' : name,
                                    'code' : code,
                                    'number' : number,
                                   }
                    }
                )

    return HttpResponse(result, content_type="application/json")