# Path: hkust-gmission/gmission/rest/base.py
# class ReSTBase(object):
#     @classmethod
#     def universal_before_post(cls, data):
#         # print 'Universal before_post'
#         data.pop('id', None)
# 
#     @classmethod
#     def universal_after_get_many(cls, result=None, search_params=None, **kwargs):
#         if request.method == 'HEAD':
#             if result is not None:
#                 result.pop('objects', [])
#         pass
# 
#     @classmethod
#     @jwt_auth()
#     def check_user_token(cls, **kw):
#         return True
# 
#     @classmethod
#     def processor_name_mapping(cls, prefix):
#         exclude_list = []
#         processors = {}
#         processors_fields = ['GET_SINGLE', 'GET_MANY', 'PATCH_SINGLE', 'PATCH_MANY', 'PUT_SINGLE', 'PUT_MANY', 'POST',
#                              'DELETE']
#         for raw_method in inspect.getmembers(cls, predicate=inspect.ismethod):
#             name, method = raw_method
#             if name.startswith(prefix):
#                 processors[name[len(prefix) + 1:].upper()] = [method.__get__(cls), ]
# 
#         # if cls.__name__ not in exclude_list and prefix == 'before':
#         #     for key in processors_fields:
#         #         preprocessor = processors.get(key, [])
#         #         preprocessor.insert(0, cls.check_user_token)
#         #         processors[key] = preprocessor
#         return processors
# 
#     @classmethod
#     def universal_preprocessors(cls):
#         prefix = 'universal_before'
#         return ReSTBase.processor_name_mapping(prefix)
# 
#     @classmethod
#     def universal_postprocessors(cls):
#         prefix = 'universal_after'
#         return ReSTBase.processor_name_mapping(prefix)
# 
#     @classmethod
#     def rest_preprocessors(cls):
#         prefix = 'before'
#         return cls.processor_name_mapping(prefix)
# 
#     @classmethod
#     def rest_postprocessors(cls):
#         prefix = 'after'
#         return cls.processor_name_mapping(prefix)
# 
#     @classmethod
#     def rest_exclude_columns(cls):
#         # r = [cln for cln in cls.__mapper__.columns if isinstance(cln, db.RelationshipProperty)]
#         return [str(r).split('.')[1] for r in cls.__mapper__.relationships]


from gmission.controllers.geo_controller import filter_location
from gmission.controllers.message_controller import send_answer_message
from .base import ReSTBase
from werkzeug.exceptions import Conflict
from gmission.models import *
from gmission.controllers.task_controller import refresh_task_status, assign_task_to_workers, credit_process, \
    push_worker_to_campaign_user
from gmission.controllers.payment_controller import pay
    def after_get_many(cls, search_params=None, **kwargs):
        pass
        # print 'ReSTAnswer after_get_many'


class ReSTLocation(Location, ReSTBase):
    @classmethod
    def before_post(cls, data):
        pass
        # print 'ReSTLocation before_post'

    @classmethod
    def after_post(cls, **kw):
        pass
        # print 'ReSTLocation after_post'
        # print kw


class ReSTPositionTrace(PositionTrace, ReSTBase):
    @classmethod
    def after_post(cls, result):
        # print 'ReSTPositionTrace after_post'
        pos = get_or_create(UserLastPosition, user_id=result['user_id'])
        # pos:UserLastPosition
        pos.longitude = result['longitude']
        pos.latitude = result['latitude']
        pos.z = result['z']
        db.session.commit()



# Path: hkust-gmission/gmission/rest/base.py
# class ReSTBase(object):
#     @classmethod
#     def universal_before_post(cls, data):
#         # print 'Universal before_post'
#         data.pop('id', None)
# 
#     @classmethod
#     def universal_after_get_many(cls, result=None, search_params=None, **kwargs):
#         if request.method == 'HEAD':
#             if result is not None:
#                 result.pop('objects', [])
#         pass
# 
#     @classmethod
#     @jwt_auth()
#     def check_user_token(cls, **kw):
#         return True
# 
#     @classmethod
#     def processor_name_mapping(cls, prefix):
#         exclude_list = []
#         processors = {}
#         processors_fields = ['GET_SINGLE', 'GET_MANY', 'PATCH_SINGLE', 'PATCH_MANY', 'PUT_SINGLE', 'PUT_MANY', 'POST',
#                              'DELETE']
#         for raw_method in inspect.getmembers(cls, predicate=inspect.ismethod):
#             name, method = raw_method
#             if name.startswith(prefix):
#                 processors[name[len(prefix) + 1:].upper()] = [method.__get__(cls), ]
# 
#         # if cls.__name__ not in exclude_list and prefix == 'before':
#         #     for key in processors_fields:
#         #         preprocessor = processors.get(key, [])
#         #         preprocessor.insert(0, cls.check_user_token)
#         #         processors[key] = preprocessor
#         return processors
# 
#     @classmethod
#     def universal_preprocessors(cls):
#         prefix = 'universal_before'
#         return ReSTBase.processor_name_mapping(prefix)
# 
#     @classmethod
#     def universal_postprocessors(cls):
#         prefix = 'universal_after'
#         return ReSTBase.processor_name_mapping(prefix)
# 
#     @classmethod
#     def rest_preprocessors(cls):
#         prefix = 'before'
#         return cls.processor_name_mapping(prefix)
# 
#     @classmethod
#     def rest_postprocessors(cls):
#         prefix = 'after'
#         return cls.processor_name_mapping(prefix)
# 
#     @classmethod
#     def rest_exclude_columns(cls):
#         # r = [cln for cln in cls.__mapper__.columns if isinstance(cln, db.RelationshipProperty)]
#         return [str(r).split('.')[1] for r in cls.__mapper__.relationships]


# Path: hkust-gmission/gmission/rest/rest_models.py
from gmission.controllers.geo_controller import filter_location
from gmission.controllers.message_controller import send_answer_message
from .base import ReSTBase
from werkzeug.exceptions import Conflict
from gmission.models import *
from gmission.controllers.task_controller import refresh_task_status, assign_task_to_workers, credit_process, \
    push_worker_to_campaign_user
from gmission.controllers.payment_controller import pay

    def after_get_many(cls, search_params=None, **kwargs):
        pass
        # print 'ReSTAnswer after_get_many'


class ReSTLocation(Location, ReSTBase):
    @classmethod
    def before_post(cls, data):
        pass
        # print 'ReSTLocation before_post'

    @classmethod
    def after_post(cls, **kw):
        pass
        # print 'ReSTLocation after_post'
        # print kw


class ReSTPositionTrace(PositionTrace, ReSTBase):
    @classmethod
    def after_post(cls, result):
        # print 'ReSTPositionTrace after_post'
        pos = get_or_create(UserLastPosition, user_id=result['user_id'])
        # pos:UserLastPosition
        pos.longitude = result['longitude']
        pos.latitude = result['latitude']
        pos.z = result['z']
        db.session.commit()



class ReSTUserLastPosition(UserLastPosition, ReSTBase):