예제 #1
0
def ding_news_by_id(request, company_id=''):
    """
    赞系统新闻
    by:王健 at:2015-06-18
    增加赞数量+1
    by:尚宗凯 at:2015-06-22
    修复栏目id错误的bug
    by:王健 at:2015-06-22
    适应性优化,公司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 = zan_news_by_id(request.user.id, company_id,
                                        news_id, news.company_column_id,
                                        int(time.time()), False)
            else:
                result = zan_news_by_id(request.user.id, company_id,
                                        news_id, news.sys_column_id,
                                        int(time.time()), True)
            news.add_zan_num()
            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'请提供正确的参数')
예제 #2
0
def ding_news_by_id(request, company_id=''):
    """
    赞系统新闻
    by:王健 at:2015-06-18
    增加赞数量+1
    by:尚宗凯 at:2015-06-22
    修复栏目id错误的bug
    by:王健 at:2015-06-22
    适应性优化,公司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 = zan_news_by_id(request.user.id, company_id, news_id, news.company_column_id, int(time.time()), False)
            else:
                result = zan_news_by_id(request.user.id, company_id, news_id, news.sys_column_id, int(time.time()), True)
            news.add_zan_num()
            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'请提供正确的参数')
예제 #3
0
파일: test.py 프로젝트: appleface2050/ESNS
 def ding_news_by_id(self, news_id, company_id, user_id):
     """
     单元测试
     by:尚宗凯 at:2015-07-02
     """
     resonse = self.client.post('/cp/%s/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 = zan_news_by_id(user_id, company_id, news_id, news.company_column_id, int(time.time()), False)
             else:
                 result = zan_news_by_id(user_id, company_id, news_id, news.sys_column_id, int(time.time()), True)
             news.add_zan_num()
             # return getResult(True, u'成功对 %s 点了个赞。' % news.title, result)
     self.assertEqual(200, resonse.status_code, u'错误')
     self.assertJSONEqual(resonse.content, getTestResult(True, u'成功对 %s 点了个赞。' % news.title, result),
                          u'错误')