Ejemplo n.º 1
0
def topic_list(request, mark=0):
    is_ajax = request.is_ajax()
    try:
        topic_result = api_list.get_feature_topic_list(request, mark)
        if topic_result['error'] == 0:
            process_topic_data(topic_result)
            next_request_url = ""
            if str(topic_result['mark']) != "0":
                next_request_url = reverse(
                    'topic:topic_list', kwargs={"mark": topic_result['mark']})
            meta_data = {
                'featureTopicList': topic_result["featureTopicList"],
                'url': next_request_url,
                'nav': 'topic'
            }
            if is_ajax:
                context = RequestContext(request, meta_data)
                template = loader.get_template('topic/topic_list.html')
                response_json = {
                    'html': template.render(context),
                    'url': next_request_url
                }
                return HttpResponse(json.dumps(response_json),
                                    content_type="application/json")
            else:
                meta_data = response_data_utils.pack_data(request, meta_data)
                return render(request, 'topic/topic_index.html', meta_data)
    except Exception, e:
        return response_data_utils.error_response(request, "服务器忙,请稍后重试!",
                                                  __name__, e)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def products_index(request):
    data = static_data.get_products_index_data()
    meta_data = response_data_utils.pack_data(request, {
        'data': data,
        'nav': 'products'
    })
    return render(request, 'products/products_index.html', meta_data)
Ejemplo n.º 4
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) 
Ejemplo n.º 5
0
def cart_index(request):
    #return render(request,'cart/cart.html',{})
    user_info = weixin_auth_utils.get_user_info(request)
    authuri = user_info.get('redirect')
    session = user_info.get('session')
    if authuri:
        return HttpResponseRedirect(authuri)
    item_list_json = api_list.get_shopping_cart(request, session)
    try:
        if item_list_json and item_list_json['error'] == 0:
            process_cartinfo_data(item_list_json)
            meta_data = {
                'search_btn': 1,
                'navTitle': '购物车',
                'cart_info_list': item_list_json['validCartItemList'],
                'invalid_cart_info_list': item_list_json['invalidCartItemList']
            }
            if len(item_list_json['validCartItemList']) == 0 and len(
                    item_list_json['invalidCartItemList']) == 0:
                return response_data_utils.error_response(
                    request, "您的购物车空空如也", __name__, "购物车为空")
            meta_data = response_data_utils.pack_data(request, meta_data)
            return weixin_auth_utils.fp_render(request, 'cart/cart.html',
                                               meta_data, session)
    except Exception, e:
        return response_data_utils.error_response(request, None, __name__, e,
                                                  session)
Ejemplo n.º 6
0
def change(request, sessionKey='', mark=0):
    is_ajax = request.is_ajax()
    if not is_ajax:
        sessionKey = request.META.get("HTTP_SESSIONKEY")
    if not sessionKey:
        sessionKey = request.REQUEST.get("sessionKey")
    if not sessionKey:
        return response_data_utils.error_response(request, None, __name__,
                                                  " not find sessionKey")
    channel = request.REQUEST.get("channel")
    udid = request.REQUEST.get("UDID")
    union_key = ""
    if channel and udid and channel == "360super":
        union_key = channel + udid

    try:
        change_info = None
        if not is_ajax:
            change_info = api_list.get_user_change_info(request, sessionKey)
        logs = api_list.get_user_change_log(request, sessionKey, union_key,
                                            mark)
        exchange_code_url = reverse("ucenter:exchangeCode")
        if logs['error'] == 0:
            next_page_url = ''  # for next page ajax loading
            if int(logs['mark']) > 0:
                next_page_url = reverse('ucenter:change_log_list',
                                        kwargs={
                                            "sessionKey": sessionKey,
                                            "mark": logs['mark']
                                        })
            process_log_data(logs["userChangeLogList"])
            meta_data = {
                'change_info': change_info,
                'userChangeLogList': logs["userChangeLogList"],
                'url': next_page_url,
                'session': sessionKey,
                "exchange_code_url": exchange_code_url
            }
            if is_ajax:
                context = RequestContext(request, meta_data)
                template = loader.get_template('ucenter/change_log_list.html')
                response_json = {
                    'html': template.render(context),
                    'url': next_page_url
                }
                return HttpResponse(json.dumps(response_json),
                                    content_type="application/json")
            else:
                meta_data = response_data_utils.pack_data(request, meta_data)
                return render(request, 'ucenter/change.html', meta_data)
        else:
            return response_data_utils.error_response(request, "找不到这个页面!",
                                                      __name__, logs)
    except Exception as e:
        print e
        return response_data_utils.error_response(request, "找不到这个页面!",
                                                  __name__, e)
Ejemplo n.º 7
0
def search(request, keyword):
  search_json = api_list.search(request, keyword)
  try:
    if search_json == None or search_json == "" or search_json['error'] != 0:
      return response_data_utils.error_response(request,"服务器忙,请稍后重试!", __name__, search_json)
    process_search_data(search_json)
    next_request_url = reverse('search:question_list', kwargs = {"keyword":keyword, "mark":search_json['mark']})
    meta_data = response_data_utils.pack_data(request, {'search':search_json, 'url':next_request_url, 'keyword':keyword })
    return render(request, 'search/search.html', meta_data)
  except Exception,e:
    return response_data_utils.error_response(request,"服务器忙,请稍后重试!", __name__, e)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
def index(request):
    try:
        feed_obj = api_list.get_product_feeds(request)
        nav_list = static_data.get_nav_data() 
        if feed_obj['error'] == 0 :
            process_feed_data(feed_obj)
            next_request_url = reverse('feed:feed_list', kwargs ={"categoryid" : 0, "mark": feed_obj['mark']}) 
            meta = response_data_utils.pack_data(request, {'feeds' : feed_obj['feedList'],'nav_list' : nav_list , 'url' : next_request_url, "nav": "index"})
            return render(request, 'feed/feeds.html', meta)
        else:
            return response_data_utils.error_response(request, None, __name__, feed_obj)
    except Exception,e:
        return response_data_utils.error_response(request, None, __name__, e)
Ejemplo n.º 10
0
def productlist_by_category(request,
                            type=0,
                            category_id=0,
                            order=5,
                            filter=0,
                            mark=0):
    is_ajax = request.is_ajax()
    try:
        products_result = api_list.get_product_by_category(
            request, type, order, category_id, filter, 10, mark)
        if products_result['error'] == 0:
            process_product_data(products_result)
            next_request_url = ""
            if str(products_result['mark']) != "0":
                next_request_url = reverse('products:query_by_all',
                                           kwargs={
                                               "type": type,
                                               "category_id": category_id,
                                               "order": order,
                                               "filter": filter,
                                               "mark": products_result['mark']
                                           })
            meta_data = {
                'productList': products_result["productList"],
                'url': next_request_url,
                'nav': 'products'
            }
            if is_ajax:
                context = RequestContext(request, meta_data)
                template = loader.get_template('products/product_list.html')
                response_json = {
                    'html': template.render(context),
                    'url': next_request_url
                }
                return HttpResponse(json.dumps(response_json),
                                    content_type="application/json")
            else:
                meta_data = dict(
                    meta_data.items() + {
                        "type": type,
                        "category_id": category_id,
                        "order": str(order),
                        "filter": filter
                    }.items())
                meta_data = response_data_utils.pack_data(request, meta_data)
                return render(request, 'products/products.html', meta_data)
    except Exception, e:
        return response_data_utils.error_response(request, "该分类下没有产品!",
                                                  __name__, e)
Ejemplo n.º 11
0
def product_official(request, product_id):
    has_product_info = 1
    try:
        product_json = api_list.get_product_info_by_id(request, product_id)
        if product_json == None or product_json == "" or product_json[
                'error'] != 0:
            return response_data_utils.error_response(request, "找不到这个产品的详情!",
                                                      __name__, product_json)
        process_product_link(product_json['product'])
        meta = response_data_utils.pack_data(
            request, {'product': product_json['product']})
        return render(request, 'product/product_official.html', meta)
    except Exception, e:
        return response_data_utils.error_response(request, "找不到这个产品的详情!",
                                                  __name__, e)
Ejemplo n.º 12
0
def cart_index(request):
    #return render(request,'cart/cart.html',{})
    user_info = weixin_auth_utils.get_user_info(request)
    authuri = user_info.get('redirect')
    session = user_info.get('session')
    if authuri:
        return HttpResponseRedirect(authuri)
    item_list_json = api_list.get_shopping_cart(request,session)
    try:
        if item_list_json and item_list_json['error']==0:
            process_cartinfo_data(item_list_json)
            meta_data = {'search_btn':1,'navTitle':'购物车', 'cart_info_list':item_list_json['validCartItemList'],'invalid_cart_info_list':item_list_json['invalidCartItemList']}
            if len(item_list_json['validCartItemList']) == 0 and len(item_list_json['invalidCartItemList']) == 0:
                return response_data_utils.error_response(request,"您的购物车空空如也", __name__, "购物车为空")
            meta_data = response_data_utils.pack_data(request,meta_data)
            return weixin_auth_utils.fp_render(request,'cart/cart.html',meta_data, session) 
    except Exception,e:
        return response_data_utils.error_response(request,None, __name__, e, session)
Ejemplo n.º 13
0
def topic_list(request, mark=0):
    is_ajax = request.is_ajax()
    try:
        topic_result = api_list.get_feature_topic_list(request, mark)
        if topic_result['error'] == 0 :
            process_topic_data(topic_result)
            next_request_url = ""
            if str(topic_result['mark']) != "0":
                next_request_url = reverse('topic:topic_list', kwargs ={"mark":topic_result['mark']})
            meta_data = {'featureTopicList' : topic_result["featureTopicList"], 'url':next_request_url ,'nav':'topic'}
            if is_ajax:
                context = RequestContext(request, meta_data)
                template = loader.get_template('topic/topic_list.html')
                response_json = {'html':template.render(context), 'url':next_request_url}
                return HttpResponse(json.dumps(response_json), content_type="application/json")
            else:
                meta_data = response_data_utils.pack_data(request, meta_data)
                return render(request, 'topic/topic_index.html', meta_data)
    except Exception,e:
        return response_data_utils.error_response(request,"服务器忙,请稍后重试!", __name__, e)
Ejemplo n.º 14
0
def product_list(request, keyword, type, mark):
   is_ajax = request.is_ajax()
   try:
      search_result = api_list.search(request, keyword, 1, 10, mark)
      if search_result['error'] == 0 :
          process_search_data(search_result)
          next_request_url = ""
          if str(search_result['mark']) != "0":
              next_request_url = reverse('search:product_list', kwargs ={"type":type, "keyword":keyword,  "mark":search_result['mark']})
          meta_data = {'productList' : search_result["productList"], 'url':next_request_url, "keyword":keyword, 'from': 'search' }
          if is_ajax:
             context = RequestContext(request, meta_data)
             template = loader.get_template('products/product_effect_list.html')
             response_json = {'html':template.render(context), 'url':next_request_url}
             return HttpResponse(json.dumps(response_json), content_type="application/json")
          else:
             meta_data = response_data_utils.pack_data(request, meta_data)
             return render(request, 'products/products.html', meta_data)
   except Exception,e:
     return response_data_utils.error_response(request,"服务器忙,请稍后重试!", __name__, e)
Ejemplo n.º 15
0
def question_list(request,mark=0):                                     
    is_ajax = request.is_ajax()
    question_list_json = api_list.get_product_feeds(request,0,20,mark)
    try:
        if question_list_json and question_list_json['error']==0:
            process_question_time(question_list_json)
            next_page_url = ""
            if question_list_json['mark']!=0:
                next_page_url = reverse("question:question_list_choice",kwargs={'mark':question_list_json['mark']})
            meta_data = {'questionList':question_list_json['feedList'],'url':next_page_url, 'nav':'question'}
            if is_ajax:
                template = loader.get_template("question/questionList.html")
                context = RequestContext(request,meta_data)
                response_json = {'html':template.render(context),'url':next_page_url}
                response_json = json.dumps(response_json)
                return HttpResponse(response_json,content_type="application/json")
            else:
                meta_data = response_data_utils.pack_data(request,meta_data)
                return render(request,'question/questionIndex.html',meta_data) 
    except Exception,e:
        return response_data_utils.error_response(request,None, __name__, e)
Ejemplo n.º 16
0
def change(request, sessionKey = '', mark = 0):
    is_ajax = request.is_ajax()
    if not is_ajax:
       sessionKey = request.META.get("HTTP_SESSIONKEY")
    if not sessionKey:
       sessionKey = request.REQUEST.get("sessionKey")
    if not sessionKey:
       return response_data_utils.error_response(request, None,  __name__, " not find sessionKey")
    channel = request.REQUEST.get("channel")
    udid = request.REQUEST.get("UDID")
    union_key = ""
    if channel and udid  and channel == "360super" :
        union_key = channel + udid

    try:
        change_info = None
        if not is_ajax:
            change_info = api_list.get_user_change_info(request, sessionKey)
        logs = api_list.get_user_change_log(request, sessionKey, union_key, mark)
        exchange_code_url = reverse("ucenter:exchangeCode")
        if logs['error'] == 0:
           next_page_url = ''  # for next page ajax loading
           if int(logs['mark']) > 0:
               next_page_url = reverse('ucenter:change_log_list', kwargs ={"sessionKey": sessionKey, "mark": logs['mark']})
           process_log_data(logs["userChangeLogList"])
           meta_data = {'change_info' : change_info,'userChangeLogList' : logs["userChangeLogList"], 'url':next_page_url,'session':sessionKey,"exchange_code_url":exchange_code_url}
           if is_ajax:
              context = RequestContext(request, meta_data)
              template = loader.get_template('ucenter/change_log_list.html')
              response_json = {'html':template.render(context), 'url':next_page_url}
              return HttpResponse(json.dumps(response_json), content_type="application/json")
           else:
              meta_data = response_data_utils.pack_data(request, meta_data)
              return render(request, 'ucenter/change.html', meta_data)
        else:
           return response_data_utils.error_response(request, "找不到这个页面!",  __name__, logs)
    except Exception as e:
        print e
        return response_data_utils.error_response(request,"找不到这个页面!", __name__, e)
Ejemplo n.º 17
0
def index(request):
    try:
        feed_obj = api_list.get_product_feeds(request)
        nav_list = static_data.get_nav_data()
        if feed_obj['error'] == 0:
            process_feed_data(feed_obj)
            next_request_url = reverse('feed:feed_list',
                                       kwargs={
                                           "categoryid": 0,
                                           "mark": feed_obj['mark']
                                       })
            meta = response_data_utils.pack_data(
                request, {
                    'feeds': feed_obj['feedList'],
                    'nav_list': nav_list,
                    'url': next_request_url,
                    "nav": "index"
                })
            return render(request, 'feed/feeds.html', meta)
        else:
            return response_data_utils.error_response(request, None, __name__,
                                                      feed_obj)
    except Exception, e:
        return response_data_utils.error_response(request, None, __name__, e)
Ejemplo n.º 18
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)
Ejemplo n.º 19
0
def activity(request, activity_id):
    session = None
    session = request.COOKIES.get("session")
    ticket = None
    user_activity_info = {}
    user_info = {}

    view_uid = get_view_uid(request)
    request_from = get_request_from(request)
    base_uri = weixin_utils.get_base_uri(request)
    path_uri = reverse("activities:activity",
                       kwargs={'activity_id': activity_id})
    query_str = request.META['QUERY_STRING']
    if query_str and len(query_str) > 0:
        query_str = "?" + query_str
    else:
        query_str = ''
    share_uri = base_uri + path_uri
    self_uri = share_uri + query_str

    authuri = weixin_utils.build_auth_uri(self_uri)
    if not session:
        code = request.REQUEST.get("code")
        user_info = {}
        if code:
            user_info = api_list.check_login(request, code)
            if user_info:
                user_info = user_info.get("userInfo")
            if user_info:
                session = user_info.get("sessionKey")

    if not session:
        return HttpResponseRedirect(authuri)

    if session:
        user_activity_info = api_list.get_activity_info(
            request, session, activity_id, view_uid)

    if user_activity_info.get("error") == None or str(
            user_activity_info["error"]) != "0":
        user_activity_info["shareActivity"] = 0
        user_activity_info["bonus"] = 0
    else:
        ticket = user_activity_info.get("ticket")

    user_uid = user_activity_info.get("uID")
    if not user_uid:
        user_uid = 0
    share_uri = base_uri + path_uri + "?fromuid=" + str(user_uid)

    meta_data = get_sign_info(request, ticket, self_uri)
    meta_data['session'] = session
    meta_data['appid'] = weixin_utils.get_appid()
    meta_data['share_activity_fee'] = user_activity_info.get("shareActivity")
    meta_data['bonus_fee'] = user_activity_info.get("bonus")
    meta_data['nickName'] = user_activity_info.get("nickName")
    meta_data['shareUserName'] = user_activity_info.get("shareUserName")
    if not meta_data.get('shareUserName'):
        meta_data['shareUserName'] = '******'
    if not meta_data.get('nickName'):
        meta_data['nickName'] = '粉扑'
    if not meta_data.get('avatarURL'):
        meta_data[
            'avatarURL'] = 'http://static.fenpuwang.com/[email protected]'
    meta_data['avatarURL'] = user_activity_info.get("avatarURL")
    meta_data[
        'total_fee'] = meta_data['bonus_fee'] + meta_data['share_activity_fee']
    meta_data['view'] = 'share_bonus'
    if request_from == 'weixin':
        if meta_data['share_activity_fee'] > 0:
            meta_data['view'] = 'view_result'
        else:
            meta_data['view'] = 'share_bonus'
    else:
        if meta_data['share_activity_fee'] > 0 and meta_data['bonus_fee'] > 0:
            meta_data['view'] = 'view_result'
        elif meta_data['bonus_fee'] == 0:
            meta_data['view'] = 'open_bonus'
        else:
            meta_data['view'] = 'opened'

    bonus_num = "两"
    if meta_data.get('bonus_fee') == 0 or meta_data.get(
            'share_activity_fee') == 0:
        bonus_num = "一"

    meta_data['base_uri'] = base_uri
    meta_data['bonus_num'] = bonus_num
    meta_data['request_from'] = request_from
    meta_data['activity_id'] = activity_id
    meta_data['share_uri'] = share_uri
    response_data_utils.pack_data(request, meta_data)
    return render(request, 'activities/activity.html', meta_data)
Ejemplo n.º 20
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)