def reg(request): reg_form = RegForm(request.GET); if reg_form.is_valid(): user = User() user.login_id = reg_form.cleaned_data[ParamConsts.LOGINID] user.login_id_type = reg_form.cleaned_data[ParamConsts.LOGINIDTYPE] user.device_id = reg_form.cleaned_data[ParamConsts.DEVICEID] user.device_model = reg_form.cleaned_data[ParamConsts.DEVICEMODEL] user.device_os = reg_form.cleaned_data[ParamConsts.DEVICEOS] user.device_token = reg_form.cleaned_data[ParamConsts.DEVICETOKEN] user.country_code = reg_form.cleaned_data[ParamConsts.COUNTRYCODE] user.language = reg_form.cleaned_data[ParamConsts.LANGUAGE] returnCode = errors.ERROR_SUCCESS try: services.register_user(user) except errors.ErrorException as e: returnCode = e.code if returnCode == errors.ERROR_SUCCESS: return get_json_response(get_return_dict(returnCode, {ParamConsts.USERID: user.id})) else: return get_json_response(get_return_dict(returnCode)) else: returnCode = errors.ERROR_PARAMETER return get_json_response(get_return_dict(returnCode, message=reg_form.errors))
def gnp(request): gnp_form = GnpForm(request.GET) if gnp_form.is_valid(): latitude = gnp_form.cleaned_data[ParamConsts.LATITUDE] longtitude = gnp_form.cleaned_data[ParamConsts.LONGTITUDE] places = services.get_nearby_places(latitude, longtitude) return_code = errors.ERROR_SUCCESS return get_json_response(get_return_dict(return_code, __get_return_list(places))) else: return_code = errors.ERROR_PARAMETER return get_json_response(get_return_dict(return_code, message=gnp_form.errors))
def ufp(request): ufp_form = UfpForm(request.GET) if ufp_form.is_valid(): user_id = ufp_form.cleaned_data[ParamConsts.USERID] place_id = ufp_form.cleaned_data[ParamConsts.PLACEID] services.user_follow_place(user_id, place_id); return_code = errors.ERROR_SUCCESS return get_json_response(get_return_dict(return_code)) else: returnCode = errors.ERROR_PARAMETER return get_json_response(get_return_dict(returnCode, message=ufp_form.errors)) pass
def gpp(request): gpp_form = GppForm(request.GET) if gpp_form.is_valid(): place_id = gpp_form.cleaned_data[ParamConsts.PLACEID] before = gpp_form.cleaned_data[ParamConsts.AFTER_TIMESTAMP] max_count = gpp_form.cleaned_data[ParamConsts.MAX_COUNT] posts = services.get_place_posts(place_id, before, max_count) returnCode = errors.ERROR_SUCCESS return get_json_response(get_return_dict(returnCode, __get_return_list(posts))) else: returnCode = errors.ERROR_PARAMETER return get_json_response(get_return_dict(returnCode, message=gpp_form.errors))
def cpl(request): cpl_form = CplForm(request.GET) if cpl_form.is_valid(): place = Place() place.name = cpl_form.cleaned_data[ParamConsts.NAME] place.user_id = cpl_form.cleaned_data[ParamConsts.USERID] place.app_id = cpl_form.cleaned_data[ParamConsts.APPID] place.latitude = cpl_form.cleaned_data[ParamConsts.LATITUDE] place.longitude = cpl_form.cleaned_data[ParamConsts.LONGTITUDE] place.radius = cpl_form.cleaned_data[ParamConsts.RADIUS] place.post_type = cpl_form.cleaned_data[ParamConsts.POSTTYPE] services.new_place(place); returnCode = errors.ERROR_SUCCESS return get_json_response(get_return_dict(returnCode, {ParamConsts.PLACEID: place.id})) else: returnCode = errors.ERROR_PARAMETER return get_json_response(get_return_dict(returnCode, message=cpl_form.errors))
def cp(request): cp_form = CpForm(request.GET) if cp_form.is_valid(): post = Post() post.user_id = cp_form.cleaned_data[ParamConsts.USERID] post.app_id = cp_form.cleaned_data[ParamConsts.APPID] post.place_id = cp_form.cleaned_data[ParamConsts.PLACEID] post.content_type = cp_form.cleaned_data[ParamConsts.CONTENT_TYPE] post.text_content = cp_form.cleaned_data[ParamConsts.TEXT_CONTENT] post.latitude = cp_form.cleaned_data[ParamConsts.LATITUDE] post.longitude = cp_form.cleaned_data[ParamConsts.LONGTITUDE] post.user_latitude = cp_form.cleaned_data[ParamConsts.USER_LATITUDE] post.user_longitude = cp_form.cleaned_data[ParamConsts.USER_LONGITUDE] services.new_post(post); returnCode = errors.ERROR_SUCCESS return get_json_response(get_return_dict(returnCode, {ParamConsts.POSTID: post.id, ParamConsts.CREATE_DATE: date2str(post.create_date)})) else: returnCode = errors.ERROR_PARAMETER return get_json_response(get_return_dict(returnCode, message=cp_form.errors))
def internal_method(request): if request.method == 'GET': in_form = InternalForm(request.GET) logger.info('[RECV] %s' % in_form.data) if in_form.is_valid(): try: method = getattr(place.api.methods, in_form.cleaned_data[MethodConsts.METHOD]) return method(request) except AllServersUnavailable: returnCode = errors.ERROR_CASSANDRA_UNAVAILABLE; logger.error('Catch exception, fail to connect to cassandra database') return get_json_response(get_return_dict(returnCode)) except Exception: returnCode = errors.ERROR_PARA_METHOD_NOT_FOUND logger.exception('%s', traceback.extract_stack()) return get_json_response(get_return_dict(returnCode)) else: returnCode = errors.ERROR_PARAMETER return get_json_response(get_return_dict(returnCode, message=in_form.errors)) else: returnCode = errors.ERROR_NOT_GET_METHOD return get_json_response(get_return_dict(returnCode))
def get(request, post_id): photos = Photo.objects.all() return get_json_response(Photo, photos)