Ejemplo n.º 1
0
    def post(self):
        data = {}
        message = ""
        error = False

        try:
            params = request.get_json(force=True)
            tmp = DB.View.find_model_by_video_and_user_id(
                params['video_id'], params['user_id'])
            if tmp is not None:
                tmp.set_count(params['count'])
                data = tmp.json()
            else:

                data = DB.View.create(params).json()

        except Exception as e:
            message = str(e)
            error = True
            DB.session.rollback()

        finally:
            return ResponseAPI('View',
                               'post',
                               data=data,
                               message=message,
                               error=error).json()
Ejemplo n.º 2
0
    def post(self, obj_id, way):
        data = {}
        error = False
        message = ""

        print 'USER ID IS DEFINED IN POST METHOD FOR TESTING!!!'
        user_id = 1

        try:
            parent_type = request.args['parent_type']

            vote = None

            if parent_type == 'video':
                vote = DB.Vote.find_model_by_video_and_user_id(obj_id, user_id)

            elif parent_type == 'comment':
                vote = DB.vote.find_by_comment_and_user_id(obj_id, user_id)

            vote = vote or DB.Vote.create({
                'parent_type': parent_type,
                parent_type + '_id': obj_id,
                'user_id': user_id
            })
            if way == "up":
                vote.set_way(1)

            elif way == "down":
                vote.set_way(0)

            elif way == "remove":
                vote.set_way(-1)

            data = vote.json()

        except Exception as e:
            traceback.print_exc()
            message = str(e)
            error = True

        finally:
            return ResponseAPI('post',
                               'Vote',
                               data=data,
                               message=message,
                               error=error).json()
Ejemplo n.º 3
0
    def get(self, id):
        data = {}
        error = False
        message = ""
        try:
            data = DB.TagAttribute.find_model_by_id(id).json()

        except Exception as e:
            DB.session.rollback()
            message = str(e)
            error = True

        finally:
            return ResponseAPI('TagAttributes',
                               'get',
                               data=data,
                               message=message,
                               error=error).json()
Ejemplo n.º 4
0
    def put(self, id):
        # Edits Video information
        error = False
        message = None

        try:
            video = DB.Video.find_model_by_id(id)
            video.title = request.args.get('title') or video.title
            video.text = request.args.get('text') or video.text
            DB.save()

        except Exception as e:
            DB.session.rollback()
            error = True
            message = str(e)

        finally:
            return ResponseAPI('put', 'Videos', message=message,
                               error=error).json()
Ejemplo n.º 5
0
    def get(self, id):
        data = {}
        message = ""
        error = False

        try:
            data = DB.View.find_model_by_id(id).json()

        except Exception as e:
            message = str(e)
            error = True
            DB.session.rollback()

        finally:
            return ResponseAPI('Views',
                               'get',
                               data=data,
                               message=message,
                               error=error).json()
Ejemplo n.º 6
0
    def post(self):
        data = {}
        error = False
        message = ""

        try:
            params = request.get_json(force=True)
            data = DB.TagAttribute.create(params).json()

        except Exception as e:
            DB.session.rollback()
            message = str(e)
            error = True

        finally:
            return ResponseAPI('TagAttribute',
                               'post',
                               data=data,
                               message=message,
                               error=error).json()
Ejemplo n.º 7
0
    def delete(self, id):
        data = {}
        error = False
        message = ""

        try:
            tag = DB.TagAttribute.find_model_by_id(id)
            #data['Success']=tag.delete()

        except Exception as e:
            DB.session.rollback()
            message = str(e)
            error = True

        finally:
            ResponseAPI('TagAttributes',
                        'delete',
                        data=data,
                        message=message,
                        error=error).json()
Ejemplo n.º 8
0
    def post(self):
        data = {}
        message = ""
        error = False

        try:
            data = db.Comment.create(request.get_json(force=True)).json()

        except Exception as e:
            message = str(e)
            error = True

        finally:
            if error is True:
                DB.db.session.rollback()
            ResponseAPI('Comment',
                        'post',
                        data=data,
                        message=message,
                        error=error).json()
Ejemplo n.º 9
0
    def post(self):
        error = False
        message = ""
        data = {}

        try:
            params = request.get_json(force=True)
            user = DB.User.create(params)
            if user is not None:
                data = {'id': user.id}
        except Exception as e:
            error = True
            message = str(e)

        finally:
            return ResponseAPI('User',
                               'post',
                               error=error,
                               message=message,
                               data=data).json()
Ejemplo n.º 10
0
class Comments(Resource):
    def get(self, id):
        data = {}
        message = ""
        error = False

    try:
        data = DB.Comment.find_model_by_id(id).json()

    except AttributeError:

        message = "Cannot not be set"
        error = True

    except Exception as e:
        message = str(e)
        error = True

    finally:
        if error is True:
            DB.db.session.rollback()
        ResponseAPI('Comments', 'get', data=data, message=message, error=error)
Ejemplo n.º 11
0
    def get(self, id):
        data = {}
        error = False
        message = ""

        try:
            video = DB.Video.find_model_by_id(id)
            if video is not None:
                data = video.json()
                data['views'] = video.get_views(only_count=True)
                print data

        except Exception as e:
            error = True
            message = str(e)
            DB.session.rollback()

        finally:
            return ResponseAPI('get',
                               'Videos',
                               data=data,
                               error=error,
                               message=message).json()
Ejemplo n.º 12
0
    def post(self):
        #Creates video

        error = None
        message = None
        data = None

        try:
            params = request.get_json(force=True)
            params['user_id'] = 1
            data = DB.Video.create(params).json()

        except Exception as e:
            DB.session.rollback()
            error = True
            message = str(e)

        finally:
            return ResponseAPI('post',
                               'Video',
                               message=message,
                               error=error,
                               data=data).json()
Ejemplo n.º 13
0
    def get(self):
        data = {}
        error = False
        message = ""

        try:
            search_word = request.args.get('search')
            if search_word is None:
                data = DB.convert_model_list(DB.TagAttribute.all())

            else:
                data = DB.TagAttribute.find_model_by_search(search_word).json()

        except Exception as e:
            DB.session.rollback()
            message = str(e)
            error = True

        finally:
            return ResponseAPI('TagAttribute',
                               'get',
                               data=data,
                               message=message,
                               error=error).json()