Esempio n. 1
0
def question_details(request, question_id):
    dp = request.REQUEST.get('dp')
    #微信中用户信息获取及授权处理
    user_info = weixin_auth_utils.get_user_info(request)
    authuri = user_info.get('redirect')
    session = user_info.get('session')

    user_agent = request.META.get('HTTP_USER_AGENT')
 
    is_mm = None
    user_agent = user_agent.lower()
    if "micromessenger" in user_agent:
      is_mm = 1

    if authuri and is_mm == 1 and dp != None and dp != "":
      return HttpResponseRedirect(authuri)

    if dp != "" and dp != None:
      api_list.bind_user(request, session, dp)
    else:
      dp = None
    # end 
    try:
        question_obj = api_list.get_question_detail(request, question_id, 1, 1, 0)
        if question_obj['error'] == 0:
            process_question_data(question_obj)
            next_page_url = ''  # for next page ajax loading
            if int(question_obj['mark']) > 0:
                next_page_url = reverse('question:answer_list', kwargs = {'question_id' : question_id, 'mark' : question_obj['mark']})
            meta_data = response_data_utils.pack_data(request, {'navTitle':'问答详情', 'question':question_obj, 'question_id':question_id, 'url' : next_page_url})
            return weixin_auth_utils.fp_render(request, 'question/question.html', meta_data, session)
        else:
            return response_data_utils.error_response(request, "找不到这个问题!",  __name__, question_obj, session)
    except Exception as e:
        return response_data_utils.error_response(request,"找不到这个问题!", __name__, e, session)
Esempio n. 2
0
def topic_info(request, topic_id):
    dp = request.REQUEST.get('dp')
    #微信中用户信息获取及授权处理
    user_info = weixin_auth_utils.get_user_info(request)
    authuri = user_info.get('redirect')
    session = user_info.get('session')
    user_agent = request.META.get('HTTP_USER_AGENT')
    is_mm = None
    user_agent = user_agent.lower()
    if "micromessenger" in user_agent:
      is_mm = 1

    if authuri and is_mm == 1 and dp != None and dp != "":
      return HttpResponseRedirect(authuri)
    from_user_name = None;
    if dp != "" and dp != None:
      api_list.bind_user(request, session, dp)
      from_user_info = api_list.get_user_info_by_uid(request, dp)
      if from_user_info != None:
        from_user_name = from_user_info.get("userInfo").get('userName')
    # end 
    try:
        topic_json = api_list.get_feature_topic_info(request, topic_id)
        if topic_json == None or topic_json == "" or topic_json['error'] != 0:
          return response_data_utils.error_response(request,"找不到这个专题", __name__, topic_json, session)
        uid = request.GET.get('dp')
        bottom_download = request.GET.get('bottom_download')
        process_topic_data(topic_json)
        process_topic_url(uid, topic_json)
        topic_comments_json = topic_comments(request,topic_id)
        next_page_url = reverse("topic:topic_info_comments",kwargs={"topic_id":topic_id,"mark":topic_comments_json["mark"]})
        meta = response_data_utils.pack_data(request, {'featureTopic': topic_json['featureTopic'],'commentsTopic':topic_comments_json,'nav':'topic','navTitle':'笔记详情','bottom_download':bottom_download, 'fromUserName':from_user_name,'url':next_page_url})
        return weixin_auth_utils.fp_render(request,'topic/topic.html', meta, session)
    except Exception,e:
       return response_data_utils.error_response(request,"服务器忙,请稍后重试!", __name__, e, session) 
Esempio n. 3
0
def topic_info(request, topic_id):
    dp = request.REQUEST.get('dp')
    #微信中用户信息获取及授权处理
    user_info = weixin_auth_utils.get_user_info(request)
    authuri = user_info.get('redirect')
    session = user_info.get('session')
    user_agent = request.META.get('HTTP_USER_AGENT')
    is_mm = None
    user_agent = user_agent.lower()
    if "micromessenger" in user_agent:
        is_mm = 1

    if authuri and is_mm == 1 and dp != None and dp != "":
        return HttpResponseRedirect(authuri)
    from_user_name = None
    if dp != "" and dp != None:
        api_list.bind_user(request, session, dp)
        from_user_info = api_list.get_user_info_by_uid(request, dp)
        if from_user_info != None:
            from_user_name = from_user_info.get("userInfo").get('userName')
    # end
    try:
        topic_json = api_list.get_feature_topic_info(request, topic_id)
        if topic_json == None or topic_json == "" or topic_json['error'] != 0:
            return response_data_utils.error_response(request, "找不到这个专题",
                                                      __name__, topic_json,
                                                      session)
        uid = request.GET.get('dp')
        bottom_download = request.GET.get('bottom_download')
        process_topic_data(topic_json)
        process_topic_url(uid, topic_json)
        topic_comments_json = topic_comments(request, topic_id)
        next_page_url = reverse("topic:topic_info_comments",
                                kwargs={
                                    "topic_id": topic_id,
                                    "mark": topic_comments_json["mark"]
                                })
        meta = response_data_utils.pack_data(
            request, {
                'featureTopic': topic_json['featureTopic'],
                'commentsTopic': topic_comments_json,
                'nav': 'topic',
                'navTitle': '笔记详情',
                'bottom_download': bottom_download,
                'fromUserName': from_user_name,
                'url': next_page_url
            })
        return weixin_auth_utils.fp_render(request, 'topic/topic.html', meta,
                                           session)
    except Exception, e:
        return response_data_utils.error_response(request, "服务器忙,请稍后重试!",
                                                  __name__, e, session)
Esempio n. 4
0
def album_detail(request, albumId):  #kim
    dp = request.REQUEST.get('dp')
    #微信中用户信息获取及授权处理
    user_info = weixin_auth_utils.get_user_info(request)
    authuri = user_info.get('redirect')
    session = user_info.get('session')
    user_agent = request.META.get('HTTP_USER_AGENT')

    is_mm = None
    user_agent = user_agent.lower()
    if "micromessenger" in user_agent:
        is_mm = 1

    if authuri and is_mm == 1 and dp != None and dp != "":
        return HttpResponseRedirect(authuri)

    if dp != "" and dp != None:
        api_list.bind_user(request, session, dp)
    else:
        dp = None
    # end
    album_info = api_list.get_list_product_album_info(request, albumId)
    cart_num_json = api_list.get_goods_num_in_cart(request, session)
    cartNum = 0
    if not album_info and album_info["error"] != 0:
        return response_data_utils.error_response(request, "合集产品不存在!",
                                                  __name__, e, session)
    if cart_num_json and cart_num_json["error"] == 0:
        cartNum = cart_num_json["totalNum"]
    try:
        if album_info and album_info["error"] == 0:
            meta_data = {
                "cartNum": cartNum,
                "album_description": album_info["album"],
                "album_info": album_info["albumInfos"],
                "navTitle": album_info["album"]["title"]
            }
            return render(request, "products/album_info.html", meta_data)
    except Exception, e:
        print "============="
        print e
        print "============="
Esempio n. 5
0
def product_detail(request, product_id):
    #微信中用户信息获取及授权处理
    dp = request.REQUEST.get('dp')
    user_info = weixin_auth_utils.get_user_info(request)
    authuri = user_info.get('redirect')
    session = user_info.get('session')

    user_agent = request.META.get('HTTP_USER_AGENT')

    is_mm = 0
    user_agent = user_agent.lower()
    if "micromessenger" in user_agent:
        is_mm = 1

    if authuri and is_mm == 1 and dp != None and dp != "":
        return HttpResponseRedirect(authuri)
    from_user_name = None
    if dp != "" and dp != None:
        api_list.bind_user(request, session, dp)
        from_user_info = api_list.get_user_info_by_uid(request, dp)
        if from_user_info != None:
            from_user_name = from_user_info.get("userInfo").get('userName')
    # end

    has_product_info = 1
    try:
        product_json = api_list.get_product_info_by_id(request, product_id)
        question_json = api_list.get_related_question_by_product_id(
            request, product_id, 0)
        cart_num_json = api_list.get_goods_num_in_cart(request, session)
        if product_json == None or product_json == "" or product_json[
                'error'] != 0:
            return response_data_utils.error_response(request, "找不到这个产品!",
                                                      __name__, product_json)
        product_json["mark"] = 0
        if question_json and question_json['error'] == 0 and question_json.get(
                "contentList"):
            product_json["contentList"] = question_json["contentList"]
            product_json["mark"] = question_json["mark"]
            product_json["totalNumber"] = question_json["totalNumber"]

        product_json["cartNum"] = 0
        if cart_num_json and cart_num_json['error'] == 0:
            product_json["cartNum"] = cart_num_json["totalNum"]
        process_product_data(product_json)
        next_request_url = reverse('product:question_list',
                                   kwargs={
                                       "product_id": product_id,
                                       "mark": product_json['mark']
                                   })
        meta = response_data_utils.pack_data(
            request, {
                'navTitle': '产品详情',
                'product': product_json,
                'url': next_request_url,
                'fromUserName': from_user_name,
                'is_mm': is_mm
            })
        return weixin_auth_utils.fp_render(request, 'product/product.html',
                                           meta, session)
    except Exception, e:
        print e
        return response_data_utils.error_response(request, "找不到这个产品!",
                                                  __name__, e, session)
Esempio n. 6
0
def products_recommend(request):  #kim
    dp = request.REQUEST.get('dp')
    #微信中用户信息获取及授权处理
    user_info = weixin_auth_utils.get_user_info(request)
    authuri = user_info.get('redirect')
    session = user_info.get('session')

    user_agent = request.META.get('HTTP_USER_AGENT')

    is_mm = None
    user_agent = user_agent.lower()
    if "micromessenger" in user_agent:
        is_mm = 1

    if authuri and is_mm == 1 and dp != None and dp != "":
        return HttpResponseRedirect(authuri)

    if dp != "" and dp != None:
        api_list.bind_user(request, session, dp)
    else:
        dp = None
    # end

    flash_activity = api_list.get_flash_banner(request)
    products_feature_result = api_list.get_feature_product_list(request)
    cart_num_json = api_list.get_goods_num_in_cart(request, session)
    album_list = api_list.get_list_product_album(request)
    if (not flash_activity) or flash_activity['error'] != 0:
        return response_data_utils.error_response(request, "秒杀产品不存在", __name__,
                                                  flash_activity, session)
    if (not products_feature_result) or products_feature_result['error'] != 0:
        return response_data_utils.error_response(request, "推荐产品不存在", __name__,
                                                  products_feature_result,
                                                  session)
    if (not album_list) or album_list["error"] != 0:
        return response_data_utils.error_response(request, "产品合集不存在", __name__,
                                                  album_list, session)
    try:
        process_products_feature(products_feature_result)
        next_request_url = ""
        if str(products_feature_result['mark']) != "0":
            next_request_url = reverse(
                'products:products_recommend_list',
                kwargs={"mark": products_feature_result['mark']})

        cartNum = 0
        if cart_num_json and cart_num_json['error'] == 0:
            cartNum = cart_num_json["totalNum"]
        if album_list and album_list["error"] == 0:
            for letter in album_list["result"]:
                if letter["type"] == 0:
                    album_list_little = letter["albums"]
                if letter["type"] == 1:
                    album_list_more = letter["albums"]
        meta_data = {
            'cartNum': cartNum,
            'url': next_request_url,
            'nav': 'products',
            "flash_activity": flash_activity.get('activityList'),
            "products_feature_list":
            products_feature_result.get('productList'),
            "album_list_little": album_list_little,
            "album_list_more": album_list_more
        }
        meta_data = response_data_utils.pack_data(request, meta_data)
        return weixin_auth_utils.fp_render(request,
                                           'products/products_recommend.html',
                                           meta_data, session)
    except Exception, e:
        return response_data_utils.error_response(request, "推荐产品不存在!",
                                                  __name__, e, session)