コード例 #1
0
 def get(self):
     logging.info('get recorded courses request. ip: {}'.format(
         reqparse.request.headers.getlist("X-Real-IP")))
     rec_courses = models.rec_courses()
     for item in rec_courses:
         item['weeks'] = None
     return rec_courses
コード例 #2
0
ファイル: resources.py プロジェクト: lolibooki/ishan_app
    def post(self):
        parser_copy = parser.copy()
        parser_copy.add_argument('_id', required=False)
        parser_copy.add_argument('field_name', required=False)

        try:
            data = parser_copy.parse_args()
            _id = data.get('_id', None)
        except:
            _id = None

        try:
            data = parser_copy.parse_args()
            field_name = data.get('field_name', None)
        except:
            field_name = None

        if field_name is not None:
            fields = models.fields(name=field_name)
        else:
            fields = models.fields(_id=_id)

        for item in fields:
            duration = 0
            for _item in item['clist']:
                # course_duration = 0
                if _item['course'] is not None:
                    if isinstance(_item['course'], list):
                        subdur = 0
                        course_list = list()
                        for course in _item['course']:
                            dur = len(models.rec_courses(_id=course)['weeks'])
                            course_list.append(models.rec_courses(_id=course))
                            if dur > subdur:
                                subdur = dur
                        course_duration = subdur
                        _item['course'] = course_list
                    else:
                        course_duration = len(models.rec_courses(_id=_item['course'])['weeks'])
                        _item['course'] = models.rec_courses(_id=_item['course'])
                    duration += course_duration
            item['duration'] = duration

        logging.info('get fields request. ip: {}'.format(reqparse.request.headers.getlist("X-Real-IP")))
        return fields
コード例 #3
0
ファイル: resources.py プロジェクト: lolibooki/ishan_app
    def post(self):
        parser_copy = parser.copy()
        parser_copy.add_argument('_id', help='This field cannot be blank', required=True)

        data = parser_copy.parse_args()

        try:
            if models.rec_courses(_id=data['_id']):
                return models.rec_courses(_id=data['_id'])
            elif models.ip_courses(_id=data['_id']):
                return models.ip_courses(_id=data['_id'])
            elif models.live_courses(_id=data['_id']):
                return models.live_courses(_id=data['_id'])
            else:
                return {'status': 400,
                        'message': 'id is incorrect'}
        except Exception as e:
            return {'status': 400,
                    'message': 'id not included'}
コード例 #4
0
 def get_list(self, *args, **kwargs):
     count, data = super(UserView, self).get_list(*args, **kwargs)
     print('get_list')
     course_list = list()
     for item in data:
         if item.get('reccourse'):
             item['reccourse'] = [
                 models.rec_courses(_id=course)['title']
                 for course in item["reccourse"].keys()
             ]
     return count, data
コード例 #5
0
ファイル: resources.py プロジェクト: lolibooki/ishan_app
 def get(self):
     from pprint import pprint
     logging.info('get recorded courses request. ip: {}'.format(reqparse.request.headers.getlist("X-Real-IP")))
     course_list = models.rec_courses()
     new_course_list = list()
     for item in course_list:
         if item["field_name"] == "temp":
             continue
         else:
             new_course_list.append(item)
     return new_course_list
コード例 #6
0
    def post(self):
        parser_copy = parser.copy()
        parser_copy.add_argument('_id',
                                 help='This field cannot be blank',
                                 required=True)
        parser_copy.add_argument('ctype',
                                 help='This field cannot be blank',
                                 required=True)  # ip/rec/liv
        parser_copy.add_argument('method',
                                 help='This field cannot be blank',
                                 required=True)  # 1:full/2,3:installment
        data = parser_copy.parse_args()

        current_user = get_jwt_identity()
        user = models.find_user({'mphone': current_user})

        if data['ctype'] == "ip":
            if ObjectId(data["_id"]) in user["ipcourse"]:
                return {
                    'status': 405,
                    'message': 'this course is currently purchased'
                }
            courses = models.ip_courses(_id=data['_id'])
        elif data['ctype'] == "rec":
            if ObjectId(data["_id"]) in user["reccourse"].keys():
                return {
                    'status': 405,
                    'message': 'this course is currently purchased'
                }
            courses = models.rec_courses(_id=data['_id'])
        elif data['ctype'] == "liv":
            if ObjectId(data["_id"]) in user["livecourse"].keys():
                return {
                    'status': 405,
                    'message': 'this course is currently purchased'
                }
            courses = models.live_courses(_id=data['_id'])
        else:
            return {'status': 400, 'message': 'course type or id is incorrect'}

        if courses['price'] == '0':
            if data['ctype'] == 'ip':
                models.add_user_ip_course(str(user["_id"]),
                                          str(courses["_id"]))
            elif data['ctype'] == 'rec':
                models.add_user_rec_course(str(user["_id"]),
                                           str(courses["_id"]))
            elif data['ctype'] == 'liv':
                srid = models.user_has_skyroom(str(user["_id"]))
                if srid:
                    models.add_user_live_course(str(user["_id"]),
                                                str(courses["_id"]), srid)
                else:
                    srid = models.add_user_skyroom(str(user["_id"]))
                    models.add_user_live_course(str(user["_id"]),
                                                str(courses["_id"]), srid)
            else:
                return {'status': 400, 'message': 'something went wrong'}
            return {'status': 200, 'message': 'free course added to user'}

        try:
            # TODO: in db all prices must be in integer form not price with "," sign!
            course_price = int(
                int(courses['price'].replace(',', '')) / int(data['method']))
            payment_desc = PAYMENT_DESCRIPTION.format(courses['title'])
            # for item in courses:
            #     if item["_id"] == ObjectId(data['_id']):
            #         course_price = int(item['price'])/int(data['method'])
            #         payment_desc = PAYMENT_DESCRIPTION.format(item['title'])
            if not course_price or not payment_desc:
                return {'status': 500, 'message': 'course does not exist'}
        except KeyError as e:
            return {'status': 404, 'message': e}

        callback_url = SERVER_IP + '/PayCallback/{}/{}/{}/{}/{}'.format(
            data['method'], str(user['_id']), data['_id'], course_price,
            data['ctype'])

        client = Client(ZARINPAL_WEBSERVICE)
        result = client.service.PaymentRequest(MMERCHANT_ID, course_price,
                                               payment_desc, EMAIL, MOBILE,
                                               callback_url)
        # for debug
        # print(result, course_price, callback_url, payment_desc)
        if result.Status == 100:
            return {
                'status': 200,
                'url':
                'https://www.zarinpal.com/pg/StartPay/' + result.Authority
            }
        else:
            return {'status': 500, 'error': 'Zarinpal not responding'}
コード例 #7
0
 def _get_course_list(self, _form):
     print('_get_course_list')
     courses = [(item['_id'], item['title'])
                for item in models.rec_courses()]
     _form.reccourse.choices = courses
     return _form
コード例 #8
0
ファイル: resources.py プロジェクト: lolibooki/ishan_app
    def post(self):
        parser_copy = parser.copy()
        
        parser_copy.add_argument('file', type=werkzeug.datastructures.FileStorage, location='files')
        parser_copy.add_argument('fname', help='This field cannot be blank', required=True)
        parser_copy.add_argument('lname', help='This field cannot be blank', required=True)
        parser_copy.add_argument('mphone', help='This field cannot be blank', required=True)
        parser_copy.add_argument('phone', help='This field cannot be blank', required=True)
        parser_copy.add_argument('gender', help='This field cannot be blank', required=True)
        parser_copy.add_argument('city', help='This field cannot be blank', required=True)
        parser_copy.add_argument('address', help='This field cannot be blank', required=True)
        parser_copy.add_argument('softskill', help='This field cannot be blank', required=False)
        parser_copy.add_argument('otherskill', help='This field cannot be blank', required=False)
        parser_copy.add_argument('course', help='This field cannot be blank', required=True)
        parser_copy.add_argument('adv_time', help='This field cannot be blank', required=True)

        data = parser_copy.parse_args()

        try:
            course = models.rec_courses(_id=data['course'])
        except:
            return {'status': 400,
                    'message': 'invalid course id'}

        field = models.fields(name=course['field_name'])

        if data['file'] is None:
            for item in field['clist']:
                if course["_id"] in item['course']:
                    if int(item['term']) > 1:
                        return {'status': 400,
                                'message': 'course has prerequisite, must include project file'}

        order = {
            'fname': data['fname'],
            'lname': data['lname'],
            'mphone': data['mphone'],
            'adv_time': datetime.datetime.strptime(data['adv_time'], "%Y-%m-%dT%H:%M:%S"),
            'phone': data['phone'],
            'gender': data['gender'],
            'city': data['city'],
            'address': data['address'],
            'softskill': data.get('softskill', None),
            'otherskill': data.get('otherskill', None),
            'course': data['course'],
            'status': 0
        }

        file = data['file']
        if file:
            # file name format is: "date-username-filename" like: "201985-AhmadTroy-file.zip"
            file_name = '{}-{}-{}'.format(str(datetime.datetime.now().date()).replace('-', ''),
                                          data['fname']+data['lname'],
                                          file.filename)
            file.save(os.path.join(COURSE_REQUESTS, file_name))
            order['attach'] = os.path.join(UPLOAD_FOLDER, file_name)

        sub = models.pre_order(order)
        if not sub:
            return {'status': 500,
                    'message': 'something went wrong'}
        else:
            return {'status': 200,
                    'message': 'pre order submitted'}