Ejemplo n.º 1
0
def delete_ding_news_by_id(request, company_id=''):
    """
    对一个记录发出顶的操作
    by:王健 at:2015-2-25
    删除点赞
    by:王健 at:2015-05-28
    修改错误提示语
    by:王健 at:2015-05-28
    解决enginecheck 没有title的bug
    by:王健 at:2015-06-01
    删除赞
    by:王健 at:2015-06-25
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = del_zan_news_by_id(request.user.id, news_id, False)
            else:
                result = del_zan_news_by_id(request.user.id, news_id, True)
            news.add_zan_num(-1)
            if result is None or (isinstance(result, dict)
                                  and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'成功对 %s 取消了赞。' % news.title, result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 2
0
def delete_ding_news_by_id(request, company_id=''):
    """
    对一个记录发出顶的操作
    by:王健 at:2015-2-25
    删除点赞
    by:王健 at:2015-05-28
    修改错误提示语
    by:王健 at:2015-05-28
    解决enginecheck 没有title的bug
    by:王健 at:2015-06-01
    删除赞
    by:王健 at:2015-06-25
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = del_zan_news_by_id(request.user.id, news_id, False)
            else:
                result = del_zan_news_by_id(request.user.id, news_id, True)
            news.add_zan_num(-1)
            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'成功对 %s 取消了赞。' % news.title, result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 3
0
    def delete_ding_news_by_id(self, news_id, company_id, user_id):
        """
        单元测试
        by:尚宗凯 at:2015-07-02
        """
        resonse = self.client.post('/cp/%s/delete_ding_news_by_id' % str(company_id), {"id":news_id})
        if news_id:
            if company_id:
                news = CompanyNews.objects.get(pk=news_id)
            else:
                news = SysNews.objects.get(pk=news_id)
            if news:
                if company_id:
                    result = del_zan_news_by_id(user_id, news_id, False)
                else:
                    result = del_zan_news_by_id(user_id, news_id, True)
                news.add_zan_num(-1)

        self.assertEqual(200, resonse.status_code, u'错误')
        self.assertJSONEqual(resonse.content, getTestResult(True, u'成功对 %s 取消了赞。' % news.title, result),
                             u'错误')