def ajax_delete_comment(request): comment_id = int(request.POST['comment_id']) msg = delete_comment_action(request.user.pk, comment_id) if isinstance(msg, long): return HttpResponse(json_msg()) else: return HttpResponse(json_msg(code='1', msg=msg))
def set_video_channel(request): """ Modify the group of video in top_video page """ item_id = int(request.POST['item_id']) channel_id = int(request.POST['channel_id']) current_channel_id = int(request.POST['current_channel_id']) channel_feeds = Channel_Feed.objects.filter(item=item_id, channel=current_channel_id) if len(channel_feeds)==0: return HttpResponse(json_msg({'code':'1', 'msg':'当前未作更改'})) channel_feed = channel_feeds[0] if channel_id == -1: channel_feed.delete() else: try: Channel_Feed.objects.get(item=item_id, channel=channel_id) except: channel_feed.channel_id = channel_id channel_feed.save() else: channel_feed.delete() item = Item.objects.get(pk=item_id) channels = item.channels channels_array = channels.split(',') channels_array.remove(str(current_channel_id)) if channel_id != -1: channels_array.append(str(channel_id)) item.channels = ','.join(list(set(channels_array))) item.save() return HttpResponse(json_msg())
def update_user_channel_weight(request): """ Change the weight of a channel for a user """ if not request.user.is_authenticated() and not (not request.user.is_active and request.session.has_key('status') and (request.session['status'] == 'register' or request.session['status'] == 'complete_profile')): return HttpResponse(json_msg('2', '非法用户')) if not request.user.is_active and request.session.has_key('status') and (request.session['status'] == 'register' or request.session['status'] == 'complete_profile'): user_id = request.session['uid'] else: user_id = request.user.pk channel_id = int(request.POST['channel_id']) new_weight = int(request.POST['weight']) if new_weight > 10 or new_weight < 1: return HttpResponse(json_msg({'code':'1', 'msg':'权值超出限制'})) user_channels = User_Channel.objects.filter(user=user_id, channel=channel_id) if len(user_channels) == 0: return HttpResponse(json_msg({'code':'1', 'msg':'您并未订阅该频道'})) user_channel = user_channels[0] user_channel.weight = new_weight user_channel.save() redis_client = redis.Redis(host=settings.REDIS_HOST, port=6379, db=0) redis_client.delete('news_feeds_' + str(user_id)) return HttpResponse(json_msg())
def set_user_group(request): """ This function group a new followed user to a specified private group """ if not request.user.is_authenticated() and not (not request.user.is_active and request.session.has_key('status') and (request.session['status'] == 'register' or request.session['status'] == 'complete_profile')): return HttpResponse(json_msg('1', msg='请先登录')) try: if not request.user.is_active and request.session.has_key('status') and (request.session['status'] == 'register' or request.session['status'] == 'complete_profile'): user_id = int(request.session['uid']) else: user_id = request.user.pk except: return HttpResponse(json_msg('1', msg='请先登录')) target_id = int(request.POST['target_id']) groups = request.POST.getlist('groups[]') for group in groups: group = UserGroup.objects.get(pk=int(group)) if not group or group.owner_id != user_id: return HttpResponse(json_msg('2', msg='你不能把用户添加到不属于你的分组')) for group in groups: user_group = UserGroup_Membership() user_group.user_id = target_id user_group.group_id = int(group) user_group.save() return HttpResponse(json_msg())
def ajax_add_comment(request): """ """ item_id = int(request.POST['item_id']) comment = request.POST['comment'] comment = comment.strip() if len(comment) == 0 or len(comment) > 300: return HttpResponse(json_msg(code='1', msg='评论为空或长度超过限制')) reply_to = int(request.POST['reply_to']) reply_to_comment = int(request.POST['reply_to_comment']) msg = add_comment_action(item_id, request.user.pk, comment, reply_to, reply_to_comment) if isinstance(msg, Comment): return HttpResponse(json_msg(data=serializers.serialize('python', [msg]))) else: return HttpResponse(json_msg(code='1', msg=msg))
def delete_feedgroup_or_channel(request): """ """ try: ids = [ int(a) for a in request.POST.getlist('ids[]')] type = request.POST['type'] except: return HttpResponse(json_msg(code='1', msg='参数错误')) if type == 'f': delete_feedgroups_action(request.user.pk, ids) elif type == 'c': delete_user_channel_action(request.user.pk, ids) else: return HttpResponse(json_msg(code='1', msg='删除失败')) return HttpResponse(json_msg())
def channel_un_subscribe(request): if not request.user.is_authenticated() and not (not request.user.is_active and request.session.has_key('status') and (request.session['status'] == 'register' or request.session['status'] == 'complete_profile')): return HttpResponse(json_msg('2', '非法用户')) if not request.user.is_active and request.session.has_key('status') and (request.session['status'] == 'register' or request.session['status'] == 'complete_profile'): user_id = request.session['uid'] else: user_id = request.user.pk try: channel_id = int(request.POST['channel_id']) except: return HttpResponse(json_msg()) msg_or_id = delete_user_channel(user_id, channel_id) if isinstance(msg_or_id, long): return HttpResponse(json_msg()) else: return HttpResponse(json_msg('2', msg_or_id))