def delete(self, id): if models.Participate.objects.filter(activity_id=id).count() > 0: raise error.MessageError( "this activity has participators, can't deleted directly") if models.Comment.objects.filter(activity_id=id).count() > 0: raise error.MessageError( "this activity has comments, can't deleted directly") cache.expire(cache_key_def.REDIS_KEY_API_ACITITY_DETAIL_ID % (id), timeout=0) return models.Activity.objects.filter(id=id).delete()
def update(self, id, **kwargs): channel_id = int(kwargs.get("channel_id", "0")) if models.ActivityChannel.objects.filter(id=channel_id).count() <= 0: raise error.MessageError("channel_id invalid") cache.expire(cache_key_def.REDIS_KEY_API_ACITITY_DETAIL_ID % (id), timeout=0) return models.Activity.objects.filter(id=id).update(**kwargs)
def returned_wrapper(request, *args, **kwargs): request_dict = { "GET": request.GET, "POST": request.POST } query_dict = request_dict.get(method, request.REQUEST) data = {} for k, v in query_dict.items(): data[k] = v request.data = data if schema: try: validate(data, schema) except exceptions.ValidationError as v: logger.error("data = %s, error = %s" %(data, v.message)) raise error.MessageError("invalid parameter") # if schema.has_key('required'): # required_list = schema['required'] # for item in required_list: # if not data.has_key(item): # raise error.MessageError(item + ' is required!') # if schema.has_key('properties'): # logging.error(str(schema['properties'])) # for k, check_schema in schema['properties'].items(): # form_schema.schema_check(k, check_schema, data.get(k)) return func(request, *args, **kwargs)
def create(self, **kwargs): name = kwargs.get("name") if models.ActivityChannel.objects.filter(name=name).count() > 0: raise error.MessageError("channel name duplicated") cache.expire(cache_key_def.REDIS_KEY_API_CHANNEL_GET_ALL, timeout=0) cache.expire(cache_key_def.REDIS_KEY_API_CHANNEL_DICT, timeout=0) ret = models.ActivityChannel.objects.create(**kwargs) return ret
def delete(self, id): if models.Activity.objects.filter(channel_id=id).count() > 0: raise error.MessageError( "this channel is configured in the activities, can't deleted directly" ) cache.expire(cache_key_def.REDIS_KEY_API_CHANNEL_GET_ALL, timeout=0) cache.expire(cache_key_def.REDIS_KEY_API_CHANNEL_DICT, timeout=0) ret = models.ActivityChannel.objects.filter(id=id).delete() return ret
def comment(self, user_id, activity_id, refer_id, content): now = time_utils.unix_time() if models.Activity.objects.filter(id=activity_id).count() <= 0: raise error.MessageError("activity_id invalid") return models.Comment.objects.create(user_id=user_id, activity_id=activity_id, refer_id=refer_id, content=content, comment_time=now)
def view_api_ops_activity_add(request): params = request.data now = time_utils.unix_time() admin_id = request.uid params["create_time"] = now params["update_time"] = now params["admin_id"] = admin_id end_time = long(params["end_time"]) if end_time < now: raise error.MessageError("end_time can not less than current time") if id in params:params.pop("id") service_di.activityService.create(**params) return response_ok(request, True)
def view_api_ops_auth_login(request): params = request.data username = params.get("username", None) password = params.get("password", None) admin = service_di.adminService.get(username) if not admin or password != admin.password: raise error.MessageError("username error or password error") ret = {"username": admin.username} response = response_ok(request, ret) session = AuthSession(request, 1) uuid_str = session.save(admin.admin_id) response.set_cookie("admid", uuid_str) return response
def join(self, user_id, activity_id, is_join): now = time_utils.unix_time() if models.Activity.objects.filter(id=activity_id).count() <= 0: raise error.MessageError("activity_id invalid") if models.Participate.objects.filter( user_id=user_id, activity_id=activity_id).count() > 0: models.Participate.objects.filter(user_id=user_id, activity_id=activity_id).update( is_join=is_join, update_time=now) else: models.Participate.objects.create(user_id=user_id, activity_id=activity_id, is_join=True, create_time=now, update_time=now)
def view_api_auth_login(request): params = request.data username = params.get("username", None) password = params.get("password", None) user = service_di.userService.get(username) if not user or password != user.password: raise error.MessageError("username error or password error") ret = { "username": user.username, "photo_url": user.photo_url, "email": user.email } response = response_ok(request, ret) session = AuthSession(request) uuid_str = session.save(user.user_id) response.set_cookie("uid", uuid_str) return response
def create(self, **kwargs): channel_id = int(kwargs.get("channel_id", "0")) if models.ActivityChannel.objects.filter(id=channel_id).count() <= 0: raise error.MessageError("channel_id invalid") return models.Activity.objects.create(**kwargs)