def category_list(request): _group_id = request.GET.get("gid", None) if _group_id != None: _group_id = int(_group_id) _status = request.GET.get("status", None) if _status != None: _status = int(_status) _all_count = len(Category.find(group_id=_group_id)) _normal_count = len(Category.find(group_id=_group_id, status=1)) _freeze_count = _all_count - _normal_count _category_groups = Category.allgroups() _categories = Category.find(group_id=_group_id, status=_status, order_by='-status') for _category in _categories: _category["group_title"] = Category_Group( _category["group_id"]).read()["title"] return render_to_response('category/list.html', { 'active_division': 'category', 'category_groups': _category_groups, 'categories': _categories, 'selected_group_id': _group_id, 'status': _status, 'all_count': _all_count, 'normal_count': _normal_count, 'freeze_count': _freeze_count }, context_instance=RequestContext(request))
def edit_category(request, category_id): if request.method == 'GET': _category_groups = Category.allgroups() _category_context = Category(category_id).read() _category_entity_count = Entity.count(category_id) return render_to_response( 'category/edit.html', { 'active_division': 'category', 'category_groups': _category_groups, 'category_context': _category_context, 'category_entity_count': _category_entity_count }, context_instance=RequestContext(request)) elif request.method == 'POST': _group_id = request.POST.get("group_id", None) _title = request.POST.get("title", None) _status = request.POST.get("status", None) _image_file = request.FILES.get("image_file", None) _image_data = None if _image_file != None: if hasattr(_image_file, 'chunks'): _image_data = ''.join(chunk for chunk in _image_file.chunks()) else: _image_data = _image_file.read() Category(category_id).update(title=_title, group_id=_group_id, image_data=_image_data, status=_status) return HttpResponseRedirect( reverse('management_edit_category', kwargs={"category_id": category_id}))
def create_category(request): if request.method == 'GET': _group_id = request.GET.get("gid", None) if _group_id != None: _group_id = int(_group_id) _category_groups = Category.allgroups() return render_to_response('category/create.html', { 'active_division': 'category', 'category_groups': _category_groups, 'selected_group_id': _group_id, }, context_instance=RequestContext(request)) elif request.method == 'POST': _group_id = request.POST.get("group_id", None) _title = request.POST.get("title", None) _category = Category.create(title=_title, group_id=_group_id) return HttpResponseRedirect( reverse('management_entity_list') + '?cid=' + str(_category.category_id))
def search_entity(request): if request.method == 'POST': _query = request.POST.get("query", None) elif request.method == 'GET': _query = request.GET.get("q", None) _category_groups = Category.allgroups() # _entity_id_list = Entity.find(like_word = _query) _entity_context_list = [] _category_title_dict = Category.get_category_title_dict() # for _entity_id in _entity_id_list: # _entity = Entity(_entity_id) # _entity_context = _entity.read() # _entity_context['category_title'] = _category_title_dict[_entity_context['category_id']] # if _entity_context.has_key('item_id_list') and len(_entity_context['item_id_list']): # _item_context = Item(_entity_context['item_id_list'][0]).read() # _entity_context['buy_link'] = _item_context['buy_link'] # _entity_context['taobao_title'] = _item_context['title'] # else: # _entity_context['buy_link'] = '' # _entity_context['taobao_title'] = '' # _entity_context_list.append(_entity_context) _category_context_list = Category.find(like_word=_query) return render_to_response( 'entity/search.html', { 'active_division': 'entity', 'query': _query, 'category_groups': _category_groups, #'entity_context_list' : _entity_context_list, 'entity_context_list': [], 'category_context_list': _category_context_list, }, context_instance=RequestContext(request))
def entity_list(request): _group_id = request.GET.get("gid", None) if _group_id == None: _status = request.GET.get("status", "select") _para = {"status": _status} _page_num = int(request.GET.get("p", "1")) _category_id = request.GET.get("cid", None) if _category_id != None: _category_id = int(_category_id) _category_context = Category(_category_id).read() _category_group_id = _category_context['group_id'] _categories = Category.find(group_id=_category_context['group_id']) for _category in _categories: _category['entity_count'] = Entity.count( _category['category_id']) _para['cid'] = _category_id else: _category_context = None _category_group_id = None _categories = None _category_groups = Category.allgroups() _select_entity_count = Entity.count(category_id=_category_id, status='select') _novus_entity_count = Entity.count(category_id=_category_id, status='novus') _freeze_entity_count = Entity.count(category_id=_category_id, status='freeze') _recycle_entity_count = Entity.count(category_id=_category_id, status='recycle') _sort_by = request.GET.get("sort_by", "time") _reverse = request.GET.get("reverse", None) if _sort_by: _para["sort_by"] = _sort_by _para["reverse"] = _reverse if _reverse == '1': _reverse = True else: _reverse = False _entity_count = Entity.count(category_id=_category_id, status=_status) if _sort_by == 'random': _paginator = None _entity_id_list = Entity.random(status=_status, count=30) else: _paginator = Paginator(_page_num, 30, _entity_count, _para) _entity_id_list = Entity.find(category_id=_category_id, status=_status, offset=_paginator.offset, count=_paginator.count_in_one_page, sort_by=_sort_by, reverse=_reverse) _entity_context_list = [] _category_title_dict = Category.get_category_title_dict() for _entity_id in _entity_id_list: try: _entity = Entity(_entity_id) _entity_context = _entity.read() _entity_context['category_title'] = _category_title_dict[ _entity_context['category_id']] _entity_context['commission_rate'] = -1 _entity_context['commission_type'] = 'unknown' if _entity_context.has_key('item_id_list') and len( _entity_context['item_id_list']): _item_context = Item( _entity_context['item_id_list'][0]).read() if _item_context == None: #jd items _item_context = JDItem( _entity_context['item_id_list'][0]).read() _entity_context['buy_link'] = _item_context['buy_link'] _entity_context['jd_title'] = _item_context['title'] _entity_context['jd_id'] = _item_context['jd_id'] _entity_context['_jd_shop_nick'] = _item_context[ 'shop_nick'] _entity_context['commission_rate'] = 4 #默认设为4 _entity_context['commission_type'] = 'general' else: _entity_context['buy_link'] = _item_context['buy_link'] _entity_context['taobao_title'] = _item_context[ 'title'] _entity_context['taobao_id'] = _item_context[ 'taobao_id'] _entity_context['taobao_shop_nick'] = _item_context[ 'shop_nick'] if _item_context.has_key('shop_nick'): _shop_context = TaobaoShop( _item_context['shop_nick']).read() if _shop_context != None: if _shop_context['extended_info'][ 'commission'] == True: _entity_context[ 'commission_rate'] = _shop_context[ 'extended_info']['commission_rate'] if _shop_context['extended_info'][ 'orientational']: _entity_context[ 'commission_type'] = 'orientational' else: _entity_context[ 'commission_type'] = 'general' else: _entity_context['buy_link'] = '' _entity_context['taobao_title'] = '' _entity_context['taobao_id'] = '' _entity_context['is_selected'] = False if _entity_context.has_key('note_id_list') and len( _entity_context['note_id_list']): for _note_id in _entity_context['note_id_list']: _note_context = Note(_note_id).read() if _note_context['is_selected']: _entity_context['is_selected'] = True break _entity_context_list.append(_entity_context) except Exception, e: pass if _status == 'freeze': UpdateNovusStatImpression.delay(impression_type='list') return render_to_response('entity/list.html', { 'active_division': 'entity', 'status_filter': _status, 'category_context': _category_context, 'category_groups': _category_groups, 'categories': _categories, 'category_group_id': _category_group_id, 'select_entity_count': _select_entity_count, 'novus_entity_count': _novus_entity_count, 'freeze_entity_count': _freeze_entity_count, 'recycle_entity_count': _recycle_entity_count, 'entity_context_list': _entity_context_list, 'paginator': _paginator, 'sort_by': _sort_by, 'reverse': _reverse }, context_instance=RequestContext(request))
'category_groups': _category_groups, 'categories': _categories, 'category_group_id': _category_group_id, 'select_entity_count': _select_entity_count, 'novus_entity_count': _novus_entity_count, 'freeze_entity_count': _freeze_entity_count, 'recycle_entity_count': _recycle_entity_count, 'entity_context_list': _entity_context_list, 'paginator': _paginator, 'sort_by': _sort_by, 'reverse': _reverse }, context_instance=RequestContext(request)) else: _categories = Category.find(group_id=int(_group_id)) _category_groups = Category.allgroups() if len(_categories) == 0: _normal_entity_count = 0 _freeze_entity_count = 0 return render_to_response('entity/list.html', { 'active_division': 'entity', 'category_context': None, 'category_groups': _category_groups, 'categories': _categories, 'category_group_id': int(_group_id), 'normal_entity_count': _normal_entity_count, 'freeze_entity_count': _freeze_entity_count, 'entity_context_list': [], }, context_instance=RequestContext(request)) else: