コード例 #1
0
class RecommendGoodsHandler(object):
    def __init__(self):
        self.goods_handler = GoodsHandler()
        self.common_handler = CommonHandler()

    def get_recommend_by_id(self, goods_id):
        goods_style = Goods.objects.get(id=goods_id).style
        style_list = self.get_style_list(goods_style)
        score_dict = self.get_score_dict(style_list, goods_id)
        score_list = self.get_score_list(score_dict)
        recommend_list = self.get_recommend_list(score_list)
        return recommend_list

    def get_style_list(self, goods_style):
        goods_style = self.common_handler.utf_to_unicode(goods_style)
        style_list = goods_style.split(',')
        return style_list

    def get_score_dict(self, style_list, goods_id):
        score_dict = {}
        for style in style_list:
            self.get_score_by_style(style, score_dict, goods_id)
        return score_dict

    def get_score_by_style(self, style, score_dict, goods_id):
        all_goods = Goods.objects.all().exclude(id=goods_id)
        for goods in all_goods:
            goods_style = goods.style.replace('u\'', '\'')
            goods_style.decode('unicode-escape')
            if goods_style.find(style) >= 0:
                self.add_dict_value(score_dict, goods.id)
            elif not score_dict.has_key(goods_id):
                score_dict[goods_id] = 0

    def add_dict_value(self, score_dict, goods_id):
        if score_dict.has_key(goods_id):
            score_dict[goods_id] += 1
        else:
            score_dict[goods_id] = 1

    def get_score_list(self, score_dict):
        score_list = []
        for key in score_dict:
            temp = (score_dict[key], key)
            score_list.append(temp)
        return score_list

    def get_recommend_list(self, score_list):
        recommend_number = 4
        recommend_list = heapq.nlargest(recommend_number, score_list)
        goods_id_list = []
        for recommend_id in recommend_list:
            goods_id_list.append(recommend_id[1])
        return goods_id_list
コード例 #2
0
from django.shortcuts import render
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.db import transaction
from django.views.decorators.csrf import csrf_exempt

from configuration.models import Bills, Goods, Goods_Bills, Vender_Goods
from configuration.website import file_server_path
from utils.BillsHandler import BillsManager
from utils import alipay, tenpay
from utility.common_handler import CommonHandler

import json

bm = BillsManager()
ch = CommonHandler()

# Create your views here.


@login_required
@transaction.atomic
def build_bills(request):
    '''
    descriptions:生成订单
    params: user,goods_list<id>
    return:
    '''
    if request.method == 'POST':
        bm = BillsManager()
        user = request.user
コード例 #3
0
from django.http import HttpResponseRedirect

from configuration.models import Vender_User
from configuration.models import Bills
from configuration.models import Goods_Bills
from configuration.models import Designer_User
from configuration.models import Vender_Goods
from configuration.models import Goods
from configuration.models import Vender_Designer

from conf import website

from utility.common_handler import CommonHandler

common_handler = CommonHandler()


def test(request):
    return render(request, website.test)


@login_required
def vender_center(request):
    class VenderBills(object):
        def __init__(self):
            self.goods_id = None
            self.goods_name = None
            self.goods_price = None
            self.goods_img = None
            self.description = None
コード例 #4
0
 def __init__(self):
     self.goods_handler = GoodsHandler()
     self.common_handler = CommonHandler()
コード例 #5
0
 def __init__(self):
     self.common_handler = CommonHandler()
コード例 #6
0
class GoodsHandler(object):
    def __init__(self):
        self.common_handler = CommonHandler()

    def get_goods_by_id(self, goods_id):
        try:
            goods = Goods.objects.get(id=goods_id)
        except ObjectDoesNotExist:
            goods = None
        return goods

    def get_all_goods_by_style(self, style):
        goods_style = self.common_handler.utf_to_unicode(style)
        all_goods_list = Goods.objects.all()
        goods_list = self.get_match_list(all_goods_list, goods_style)
        return goods_list

    def get_goods_by_style(self, goods_list, goods_style):
        goods_style = self.common_handler.utf_to_unicode(goods_style)
        style_goods_list = self.get_match_list(goods_list, goods_style)
        return style_goods_list

    def get_match_list(self, goods_list, style):
        match_list = []
        for goods in goods_list:
            goods_style = goods.style.replace('u\'', '\'')
            goods_style.decode("unicode-escape")
            if goods_style.find(style) >= 0:
                match_list.append(goods)
        return match_list

    def get_all_goods_by_tags(self, goods_tags):
        goods_tags = self.common_handler.utf_to_unicode(goods_tags)
        goods_list = Goods.objects.filter(tags=goods_tags)
        return goods_list

    def get_goods_by_tags(self, goods_list, goods_tags):
        goods_tags = self.common_handler.utf_to_unicode(goods_tags)
        tags_goods_list = goods_list.filter(tags=goods_tags)
        return tags_goods_list

    def get_goods_by_designer(self, designer_id):
        goods_list = Goods.objects.filter(designer_id=designer_id)
        return goods_list

    def set_collected_count(self, goods, count):
        goods.collected_count += count
        goods.save()

    def get_other_goods(self, designer_id, goods_id):
        goods_list = Goods.objects.filter(designer_id=designer_id).exclude(
            id=goods_id)
        return goods_list

    def sort_by_download(self, goods_list, order=True):
        return_list = sorted(goods_list,
                             key=attrgetter('download_count'),
                             reverse=order)
        return return_list

    def sort_by_collect(self, goods_list, order=True):
        return_list = sorted(goods_list,
                             key=attrgetter('collected_count'),
                             reverse=order)
        return return_list

    def sort_by_time(self, goods_list, order=True):
        return_list = sorted(goods_list,
                             key=attrgetter('approval_time'),
                             reverse=order)
        return return_list

    def comprehension_sort(self, goods_list):
        return_list = sorted(goods_list,
                             key=attrgetter('download_count',
                                            'collected_count',
                                            'approval_time'))
        return return_list
コード例 #7
0
 def __init__(self):
     self.goods_handler = GoodsHandler()
     self.common_handler = CommonHandler()
コード例 #8
0
class RecommendGoodsHandler(object):

    def __init__(self):
        self.goods_handler = GoodsHandler()
        self.common_handler = CommonHandler()


    def get_recommend_by_id(self,goods_id):
        goods_style = Goods.objects.get(id=goods_id).style
        style_list = self.get_style_list(goods_style)
        score_dict = self.get_score_dict(style_list, goods_id)
        score_list = self.get_score_list(score_dict)
        recommend_list = self.get_recommend_list(score_list)
        return  recommend_list


    def get_style_list(self,goods_style):
        goods_style = self.common_handler.utf_to_unicode(goods_style)
        style_list = goods_style.split(',')
        return style_list


    def get_score_dict(self,style_list, goods_id):
        score_dict = {}
        for style in style_list:
            self.get_score_by_style(style,score_dict, goods_id)
        return score_dict


    def get_score_by_style(self, style, score_dict, goods_id):
        all_goods = Goods.objects.all().exclude(id=goods_id)
        for goods in all_goods:
            goods_style = goods.style.replace('u\'','\'')
            goods_style.decode('unicode-escape')
            if goods_style.find(style) >= 0:
                self.add_dict_value(score_dict, goods.id)
            elif not score_dict.has_key(goods_id):
                score_dict[goods_id] = 0


    def add_dict_value(self, score_dict, goods_id):
        if score_dict.has_key(goods_id):
            score_dict[goods_id] += 1
        else:
            score_dict[goods_id] = 1


    def get_score_list(self,score_dict):
        score_list = []
        for key in score_dict:
            temp = (score_dict[key],key)
            score_list.append(temp)
        return score_list


    def get_recommend_list(self,score_list):
        recommend_number = 4
        recommend_list = heapq.nlargest(recommend_number, score_list)
        goods_id_list = []
        for recommend_id in recommend_list:
            goods_id_list.append(recommend_id[1])
        return goods_id_list
コード例 #9
0
class GoodsHandler(object):

    def __init__(self):
        self.common_handler = CommonHandler()

    def get_goods_by_id(self,goods_id):
        try:
            goods = Goods.objects.get(id = goods_id)
        except ObjectDoesNotExist:
            goods = None
        return goods


    def get_all_goods_by_style(self,style):
        goods_style = self.common_handler.utf_to_unicode(style)
        all_goods_list = Goods.objects.all()
        goods_list = self.get_match_list(all_goods_list,goods_style)
        return goods_list


    def get_goods_by_style(self,goods_list,goods_style):
        goods_style = self.common_handler.utf_to_unicode(goods_style)
        style_goods_list = self.get_match_list(goods_list,goods_style)
        return style_goods_list


    def get_match_list(self,goods_list,style):
        match_list = []
        for goods in goods_list:
            goods_style = goods.style.replace('u\'','\'')
            goods_style.decode("unicode-escape")
            if goods_style.find(style) >= 0:
                match_list.append(goods)
        return match_list


    def get_all_goods_by_tags(self,goods_tags):
        goods_tags = self.common_handler.utf_to_unicode(goods_tags)
        goods_list = Goods.objects.filter(tags = goods_tags)
        return goods_list


    def get_goods_by_tags(self, goods_list, goods_tags):
        goods_tags = self.common_handler.utf_to_unicode(goods_tags)
        tags_goods_list = goods_list.filter(tags=goods_tags)
        return tags_goods_list


    def get_goods_by_designer(self,designer_id):
        goods_list = Goods.objects.filter(designer_id = designer_id)
        return goods_list


    def set_collected_count(self,goods,count):
        goods.collected_count += count
        goods.save()


    def get_other_goods(self, designer_id, goods_id):
        goods_list = Goods.objects.filter(designer_id=designer_id).exclude(id=goods_id)
        return goods_list


    def sort_by_download(self, goods_list, order=True):
        return_list = sorted(goods_list, key=attrgetter('download_count'), reverse=order)
        return return_list


    def sort_by_collect(self, goods_list, order=True):
        return_list = sorted(goods_list, key=attrgetter('collected_count'), reverse=order)
        return return_list


    def sort_by_time(self, goods_list, order=True):
        return_list = sorted(goods_list, key=attrgetter('approval_time'), reverse=order)
        return return_list


    def comprehension_sort(self, goods_list):
        return_list = sorted(goods_list, key=attrgetter('download_count', 'collected_count', 'approval_time'))
        return return_list
コード例 #10
0
 def __init__(self):
     self.common_handler = CommonHandler()