示例#1
0
def event():
    if not request.json:
        return render_json(406, {'error': 'Mime-type is not application/json'})

    if request.json.get('id') is None:
        return render_json(406, {'error': 'Invalid Stripe event'})

    try:
        safe_event = PaymentEvent.retrieve(request.json.get('id'))
        parsed_event = Invoice.parse_from_event(safe_event)

        user = Invoice.prepare_and_save(parsed_event)

        if parsed_event.get('total') > 0:
            plan = Subscription.get_plan_by_id(user.subscription.plan)
            user.add_coins(plan)
    except InvalidRequestError as e:
        # We could not parse the event.
        return render_json(422, {'error': str(e)})
    except Exception as e:
        # Return a 200 because something is really wrong and we want Stripe to
        # stop trying to fulfill this webhook request.
        return render_json(200, {'error': str(e)})

    return render_json(200, {'success': True})
示例#2
0
    def get():
        staff = Staff.query.all()
        if staff:
            return render_json(
                200, {'staff': [member.to_json() for member in staff]})

        return render_json(404, {'message': 'No staff found'})
    def post():
        content = request.form
        practice_area_ids = content.get('practiceAreas', '')
        staff_ids = content.get('staff', '')
        file_open = content.get('fileOpen', None)
        file_open_date_object = datetime.strptime(file_open, '%d/%m/%Y')

        matter = Matter()
        matter.file_open = file_open_date_object.strftime(
            '%m/%d/%Y') if file_open else None
        matter.costs_on_account = content.get('costsOnAccount')
        matter.description = content.get('description')

        if practice_area_ids:
            practice_areas = [
                PracticeArea.query.get(int(id))
                for id in practice_area_ids.split(",")
            ]
            matter.practice_areas = practice_areas

        if staff_ids:
            staff = [Staff.query.get(int(id)) for id in staff_ids.split(",")]
            matter.staff = staff

        try:
            matter.save()
            return render_json(200, {'matter': matter.to_json()})
        except:
            return render_json(500, {'message': "An error occurred."})
    def get(id):
        matter = Matter.query.get_or_404(id)

        if matter:
            return render_json(200, {'matter': matter.to_json()})

        return render_json(404, {'message': 'No matter found'})
示例#5
0
def srch_popltn_stats():
    # 인구통계 검색
    sido_cds = request.form.getlist('ps-sido')
    sigu_cds = request.form.getlist('ps-sigu')
    emd_cds = request.form.getlist('ps-emd')
    age_cds = request.form.getlist('ps-age')
    sex_cds = request.form.getlist('ps-sex')
    syear = request.form.get('ps-syear')
    smonth = request.form.get('ps-smonth')
    eyear = request.form.get('ps-eyear')
    emonth = request.form.get('ps-emonth')

    rs = PopltnStats.select_all(sido_cds, sigu_cds, emd_cds, age_cds, syear,
                                smonth, eyear, emonth)

    if rs is None:
        return render_json(401, {'msg': '검색 중 오류가 발생하였습니다.'})

    return render_json(200,
                       items=[{
                           'area_nm': item.area_nm,
                           'man_sum': item.man_sum,
                           'woman_sum': item.woman_sum,
                           'total_sum': item.total_sum
                       } for item in rs])
    def put(user_id):
        content = request.form
        user = User.query.get_or_404(user_id)

        if user:        
            user.role = content.get('role', None)
            user.active = content.get('active', None)
            user.first_name = " ".join(word.capitalize() for word in content.get('firstName', '').split())
            user.middle_name = " ".join(word.capitalize() for word in content.get('middleName', '').split())
            user.last_name = " ".join(word.capitalize() for word in content.get('lastName', '').split())
            user.phone_number = content.get('phoneNumber', '')
            user.unit_number = content.get('unitNumber', '')
            user.street_address = content.get('streetAddress', '')
            user.suburb = content.get('suburb', '')
            user.postcode = content.get('postcode', '')
            user.state = content.get('state', '')
            user.country = content.get('country', '')

            try: 
                user.save()
                return render_json(200, {'user': user.to_json()})
            except:
                return render_json(500, {'message': "An error occurred."})
 
        return render_json(404, {'message': 'No user with ID {} found'.format(user_id)})
示例#7
0
    def get():
        comments = Comment.query.all()
        comments = [comment.to_json() for comment in comments]
        if comments:
            return render_json(200, {'comments': comments})

        return render_json(404, {'message': 'No comments found'})
    def post(): 
        content = request.form
        
        user = User()
        user.role = content.get('role', None)
        user.username = content.get('username', '')
        user.password = content.get('password', '')
        user.email = content.get('email', '')
        user.first_name = " ".join(word.capitalize() for word in content.get('firstName', '').split())
        user.middle_name = " ".join(word.capitalize() for word in content.get('middleName', '').split())
        user.last_name = " ".join(word.capitalize() for word in content.get('lastName', '').split())
        user.phone_number = content.get('phoneNumber', '')
        user.unit_number = content.get('unitNumber', '')
        user.street_address = content.get('streetAddress', '')
        user.suburb = content.get('suburb', '')
        user.postcode = content.get('postcode', '')
        user.state = content.get('state', '')
        user.country = content.get('country', '')

        try: 
            user.save()
        except:
            return render_json(500, {'message': "An error occurred."})
        
        return render_json(200, {'user': user.to_json()})
    def get():
        users = User.query.all()
        users = [user.to_json() for user in users]
        if users:
            return render_json(200, {'users': users})

        return render_json(404, {'message': 'No users found'})
    def get(slug):
        practice_area = PracticeArea.get_by_slug(slug)

        if practice_area:
            return render_json(200, {'practiceArea': practice_area.to_json()})

        return render_json(404, {'message': 'No practice areas found'})
示例#11
0
    def get():
        client = Client.query.all()
        if client:
            return render_json(
                200, {'clients': [member.to_json() for member in client]})

        return render_json(404, {'message': 'No client found'})
    def get():
        matters = Matter.query.all()
        matter = [matter.to_json() for matter in matters]
        if matter:
            return render_json(200, {'matters': matter})

        return render_json(404, {'message': 'No matter found'})
    def get(post_id):
        post = Post.query.get_or_404(post_id)
        comments = [comment.to_json() for comment in post.comments]

        if post:
            return render_json(200, {'comments': comments})

        return render_json(404, {'message': 'No comments found for this post'})
    def get():
        practice_areas = PracticeArea.query.all()
        if practice_areas:
            return render_json(
                200,
                {'practiceAreas': [area.to_json() for area in practice_areas]})

        return render_json(404, {'message': 'No posts found'})
    def delete(user_id):
        user = User.query.get_or_404(user_id)
        if user: 
            # try:
            user.delete()
            return render_json(200, {'user': user.to_json()})
            # except: 
            #     return render_json(500, {'message': "An error occurred."})

        return render_json(404, {'message': 'No user with ID {} found'.format(user_id)})
示例#16
0
def coupon_code():
    code = request.form.get('coupon_code')
    if code is None:
        return render_json(422, {'error': 'Coupon code cannot be processed.'})

    coupon = Coupon.find_by_code(code)
    if coupon is None:
        return render_json(404, {'error': 'Coupon code not found.'})

    return render_json(200, {'data': coupon.to_json()})
示例#17
0
def get_law_areas():
    # 법정 구역 목록을 조회한다.
    sid_cd = request.args.get('sid_cd') or request.form.get('sid_cd')
    sgg_cd = request.args.get('sgg_cd') or request.form.get('sgg_cd')

    if sid_cd:
        items = LawSggArea.find_by_sid_cd(sid_cd)

        return render_json(200,
                           items=[{
                               'sgg_cd':
                               item.sgg_cd,
                               'sgg_ko_nm':
                               item.sgg_ko_nm,
                               'coordinates':
                               json.loads(item.geojson)['coordinates'],
                               'layers':
                               'hms:law_sgg_area',
                               'featureid':
                               'law_sgg_area.' + item.sgg_cd
                           } for item in items])

    elif sgg_cd:
        items = LawEmdArea.find_by_sgg_cd(sgg_cd)

        return render_json(200,
                           items=[{
                               'emd_cd':
                               item.emd_cd,
                               'emd_ko_nm':
                               item.emd_ko_nm,
                               'coordinates':
                               json.loads(item.geojson)['coordinates'],
                               'layers':
                               'hms:law_emd_area',
                               'featureid':
                               'law_emd_area.' + item.emd_cd
                           } for item in items])

    else:
        items = LawSidArea.find_all()

        return render_json(200,
                           items=[{
                               'sid_cd':
                               item.sid_cd,
                               'sid_ko_nm':
                               item.sid_ko_nm,
                               'coordinates':
                               json.loads(item.geojson)['coordinates'],
                               'layers':
                               'hms:law_sid_area',
                               'featureid':
                               'law_sid_area.' + item.sid_cd
                           } for item in items])
示例#18
0
def delete_bookmark():
    id = request.form.get('id')

    obj = Bookmark.query.get(id)

    if obj and obj.user_id == current_user.id:
        obj.delete()

        return render_json(200, {'msg': '삭제되었습니다.'})

    return render_json(400, {'msg': '삭제되지 않았습니다.'})
示例#19
0
    def put(comment_id):
        comment = Comment.query.get_or_404(comment_id)
        if comment:
            comment.visible = request.form.get('visible')
        try:
            comment.save()
            return render_json(200, {'comment': comment.to_json()})
        except:
            return render_json(500, {'message': "An error occurred."})

        return render_json(
            404, {'message': 'No comment with ID {} found'.format(comment_id)})
示例#20
0
    def get():
        return render_json(
            200, {
                'admin': {
                    'posts': Post.query.count(),
                    'users': User.query.count(),
                    'matters': Matter.query.count(),
                    'practiceAreas': PracticeArea.query.count()
                }
            })

        return render_json(404, {'message': 'No data found'})
    def post():
        content = request.form
        user = User.find_by_identity(content.get('identity'))

        if user and user.authenticated(password=content.get('password')):
            if login_user(user, remember=True) and user.is_active():
                user.update_activity_tracking(request.remote_addr)
                return render_json(200, {'message': 'Login successful'})
            else:
                return render_json(401, {'message': 'This account has been disabled'})
        else:
            return render_json(401, {'message': 'Identity or password provided was incorrect.'})
示例#22
0
def update_bookmark():
    id = request.form.get('id')
    name = request.form.get('name')

    obj = Bookmark.query.get(id)

    if obj and name and obj.user_id == current_user.id:
        obj.name = name
        obj.save()

        return render_json(200, {'msg': '수정되었습니다.'})

    return render_json(400, {'msg': '수정되지 않았습니다.'})
    def post():
        content = request.form
        title = content['title']
        image = request.files.get('file', None)

        if Post.find_by_title(title):
            return render_json(
                404, {
                    'message':
                    "A post with the title '{}' already exists. Please choose another title"
                    .format(title)
                })

        post = Post()
        post.title = title
        post.author_id = content['author']
        post.practice_area_id = content['practiceArea']
        post.body = [content['body']]
        post.summary = content['summary']

        if image:
            filename = secure_filename(image.filename)
            path_to_image_2000 = os.path.join(
                current_app.config['IMAGES_2000'], filename)
            path_to_image_400 = os.path.join(current_app.config['IMAGES_400'],
                                             filename)

            image_2000 = Image.open(image)
            image_400 = Image.open(image)
            image_2000.thumbnail((2000, 2000))
            image_400.thumbnail((400, 400))

            image_2000.save(path_to_image_2000)
            image_400.save(path_to_image_400)

            with current_app.app_context():
                post.img_src = url_for(
                    'static', filename='images/2000/{}'.format(filename))
                post.thumbnail_src = url_for(
                    'static', filename='images/400/{}'.format(filename))
        else:
            post.img_src = ''
            post.thumbnail_src = ''

        try:
            post.save()
        except:
            return render_json(500, {'message': "An error occurred."})

        return render_json(200, {'post': post.to_json()})
    def delete(post_id):
        post = Post.query.get_or_404(post_id)
        if post:
            try:
                post.delete()
                posts = [
                    post.to_json()
                    for post in Post.query.order_by(Post.created_on.desc())
                ]
                return render_json(200, {'posts': posts})
            except:
                return render_json(500, {'message': "An error occurred."})

        return render_json(
            404, {'message': 'No post with ID {} found'.format(post_id)})
示例#25
0
    def post():
        content = request.form
        comment = Comment()
        comment.content = request.form.get('content')
        comment.user_id = current_user.id
        comment.post_id = request.form.get('postId')

        try:
            comment.save()
        except:
            return render_json(
                500,
                {'message': "An error occurred whilst posting your comment."})

        return render_json(200, {'comment': comment.to_json()})
示例#26
0
def get_codes():
    # 그룹코드로 코드 목록을 조회한다.
    group_code = request.args.get('group_code') or request.form.get(
        'group_code')

    if group_code:
        codes = Code.find_by_group_code(group_code)

        return render_json(200,
                           codes=[{
                               'code': code.code,
                               'name': code.name
                           } for code in codes])

    return render_json(401, {'msg': '등록되지 않은 그룹코드입니다.'})
 def get():
     if current_user:
         if current_user.is_authenticated:
             return render_json(200, {
                 'currentUser': {
                     'role': current_user.role,
                     'name': current_user.first_last_name,
                     'username': current_user.username,
                     'photo': current_user.photo
                 }
             })
         else:
             return render_json(200, {
                 'currentUser': {}
             }) 
     
     return render_json(500, {'message': 'An error occured.'})
示例#28
0
def insert_bookmark():
    name = request.form.get('name')
    target = request.form.get('target')
    parameter = request.form.get('parameter')

    if name and target and parameter:
        obj = Bookmark()
        obj.user_id = current_user.id
        obj.name = name
        obj.target = target
        obj.parameter = parameter

        obj.save()

        return render_json(200, {'msg': '저장되었습니다.'})

    return render_json(400, {'msg': '저장되지 않았습니다.'})
示例#29
0
def srch_popltn_mvmt():
    # 인구이동 검색
    out_sid_cds = request.form.getlist('out_sid_cd')
    out_sgg_cds = request.form.getlist('out_sgg_cd')
    out_emd_cds = request.form.getlist('out_emd_cd')
    in_sid_cd = request.form.get('in_sid_cd')
    in_sgg_cd = request.form.get('in_sgg_cd')
    in_emd_cd = request.form.get('in_emd_cd')
    mv_reasn_cds = request.form.getlist('mv_reasn_cd')
    aplcnt_ages = request.form.getlist('aplcnt_age', type=int)
    aplcnt_sex_cds = request.form.getlist('aplcnt_sex_cd')
    fmly_nums = request.form.getlist('fmly_num', type=int)
    st_yyyymm = request.form.get('st_year') + request.form.get('st_month')
    ed_yyyymm = request.form.get('ed_year') + request.form.get('ed_month')

    # 지도 출력
    if request.form.get('req_type') == 'map':
        items = PopltnMvmt.find_by_filter_for_map(out_sid_cds, out_sgg_cds,
                                                  out_emd_cds, in_sid_cd,
                                                  in_sgg_cd, in_emd_cd,
                                                  mv_reasn_cds, aplcnt_ages,
                                                  aplcnt_sex_cds, fmly_nums,
                                                  st_yyyymm, ed_yyyymm)

        return render_json(200,
                           rows=[{
                               'coordinates':
                               json.loads(item.geojson)['coordinates'],
                               'hshold_cnt':
                               item.hshold_cnt,
                               'fmly_sum':
                               item.fmly_sum
                           } for item in items])

    # 그리드 출력
    items = PopltnMvmt.find_by_filter_for_grid(out_sid_cds, out_sgg_cds,
                                               out_emd_cds, in_sid_cd,
                                               in_sgg_cd, in_emd_cd,
                                               mv_reasn_cds, aplcnt_ages,
                                               aplcnt_sex_cds, fmly_nums,
                                               st_yyyymm, ed_yyyymm)

    return jsonify({
        'rows': [{
            'in_yyyymm': item.in_yyyymm,
            'in_sid': item.in_sid,
            'in_sgg': item.in_sgg,
            'in_emd': item.in_emd,
            'out_sid': item.out_sid,
            'out_sgg': item.out_sgg,
            'out_emd': item.out_emd,
            'mv_reasn': item.mv_reasn,
            'aplcnt_clsftn': item.aplcnt_clsftn,
            'aplcnt_age': item.aplcnt_age,
            'aplcnt_sex': item.aplcnt_sex,
            'fmly_num': item.fmly_num
        } for item in items]
    })
    def post():
        content = request.get_json()
        title = content.get('title', None)
        title_error = "A post with that title already exists."

        if Post.find_by_title(title):
            return render_json(404, {'title': title_error})

        return None