def arrange_selection(request): if request.method == 'GET': _t_start = datetime.datetime.now() + datetime.timedelta(days=1) _year = _t_start.year _month = _t_start.month _date = _t_start.day _start_time = "%d-%d-%d 8:00:00" % (_year, _month, _date) _pending_note_count = Note.count(pending_selection=True) return render_to_response('note/arrange.html', { 'active_division': 'note', 'pending_note_count': _pending_note_count, 'start_time': _start_time }, context_instance=RequestContext(request)) else: _count = int(request.POST.get("count", None)) _start_time = request.POST.get("start_time") _start_time = datetime.datetime.strptime(_start_time, "%Y-%m-%d %H:%M:%S") _interval = int(request.POST.get("interval", None)) ArrangeSelectionTask.delay(select_count=_count, start_time=_start_time, interval_secs=_interval) return HttpResponseRedirect(request.META['HTTP_REFERER'])
def user_notes(request, user_id, template=TEMPLATE): _start_at = datetime.datetime.now() _query_user = User(user_id) _query_user_context = _query_user.read() if request.user.is_authenticated(): _request_user_id = request.user.id _request_user_context = User(_request_user_id).read() _request_user_like_entity_set = Entity.like_set_of_user(request.user.id) _relation = User.get_relation(_request_user_context['user_id'], _query_user_context['user_id']) else: _request_user_id = None _request_user_context = None _request_user_like_entity_set = [] _relation = None _page_num = int(request.GET.get('p', 1)) _paginator = Paginator(_page_num, 24, Note.count(creator_set=[user_id])) _note_id_list = Note.find(creator_set=[user_id], offset=_paginator.offset, count=_paginator.count_in_one_page) _note_list = [] for _n_id in _note_id_list: try: _note_context = Note(_n_id).read() _entity_id = _note_context['entity_id'] _creator_context = User(user_id).read() _entity_context = Entity(_entity_id).read() _is_user_already_like = True if _entity_id in _request_user_like_entity_set else False _note_list.append( { 'entity_context' : _entity_context, 'note_context' : _note_context, 'creator_context' : _creator_context, 'is_user_already_like' : _is_user_already_like } ) except Exception, e: pass
def edit_jd_entity(request, entity_id): if request.method == "GET": _code = request.GET.get("code", None) if _code == "1": _message = "京东商品已被创建至本entity" else: _message = None _entity_context = Entity(entity_id).read() _item_context_list = [] for _item_id in JDItem.find(entity_id=entity_id): _item_context = JDItem(_item_id).read() if (not _entity_context.has_key('title') or \ _entity_context['title'] == "") and \ (not _entity_context.has_key('recommend_title')): _entity_context['recommend_title'] = _item_context['title'] _item_context['commission_type'] = "unknown" _item_context['commission_rate'] = 4 #jd的佣金是根据品类来区分的 _entity_context['commission_type'] = "general" _item_context_list.append(_item_context) _note_count = Note.count(entity_id=entity_id) _users = _get_special_names(request.user.id) _mark_list = Entity.Mark.all() return render_to_response('entity/edit.html', { 'active_division': 'entity', 'entity_context': _entity_context, 'category_list': Category.find(), 'old_category_list': Old_Category.find(), 'item_context_list': _item_context_list, 'mark_list': _mark_list, 'message': _message, 'note_count': _note_count, 'users': _users }, context_instance=RequestContext(request)) elif request.method == "POST": _brand = request.POST.get("brand", None) _title = request.POST.get("title", None) _intro = request.POST.get("intro", None) _price = request.POST.get("price", None) _reset_created_time = request.POST.get("reset_created_time", "off") if _reset_created_time == "on": _reset_created_time = True else: _reset_created_time = False _weight = int(request.POST.get("weight", '0')) _mark = int(request.POST.get("mark", '0')) _chief_image_id = request.POST.get("chief_image", None) if _price: _price = float(_price) _category_id = request.POST.get("category_id", None) if _category_id: _category_id = int(_category_id) _old_category_id = request.POST.get("old_category_id", None) if _old_category_id: _old_category_id = int(_old_category_id) _entity = Entity(entity_id) _entity.update(category_id=_category_id, old_category_id=_old_category_id, brand=_brand, title=_title, intro=_intro, price=_price, chief_image_id=_chief_image_id, weight=_weight, mark=_mark, reset_created_time=_reset_created_time) _note = request.POST.get("note", None) _user_id = request.POST.get("user_id", None) if _note != None and len(_note) > 0: _add_note_and_select_delay(_entity, _user_id, _note) return HttpResponseRedirect(request.META['HTTP_REFERER'])
def edit_entity(request, entity_id): if request.method == 'GET': _code = request.GET.get("code", None) _source = request.GET.get("source", "taobao") if _source == "jd": return edit_jd_entity(request, entity_id) if _code == "1": _message = "淘宝商品已被创建至本entity" else: _message = None _entity_context = Entity(entity_id).read() _item_context_list = [] for _item_id in Item.find(entity_id=entity_id): _item_context = Item(_item_id).read() if _item_context == None: return edit_jd_entity(request, entity_id) if (not _entity_context.has_key('title') or _entity_context['title'] == "") and ( not _entity_context.has_key('recommend_title')): _entity_context['recommend_title'] = _item_context['title'] _item_context['commission_type'] = 'unknown' _item_context['commission_rate'] = -1 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: _item_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' _item_context_list.append(_item_context) _note_count = Note.count(entity_id=entity_id) _users = _get_special_names(request.user.id) _mark_list = Entity.Mark.all() if _entity_context['weight'] < 0: UpdateNovusStatImpression.delay(impression_type='edit') return render_to_response('entity/edit.html', { 'active_division': 'entity', 'entity_context': _entity_context, 'category_list': Category.find(), 'old_category_list': Old_Category.find(), 'item_context_list': _item_context_list, 'mark_list': _mark_list, 'message': _message, 'note_count': _note_count, 'users': _users }, context_instance=RequestContext(request)) elif request.method == 'POST': _brand = request.POST.get("brand", None) _title = request.POST.get("title", None) _intro = request.POST.get("intro", None) _price = request.POST.get("price", None) _weight = int(request.POST.get("weight", '0')) _mark = int(request.POST.get("mark", '0')) _chief_image_id = request.POST.get("chief_image", None) if _price: _price = float(_price) _category_id = request.POST.get("category_id", None) if _category_id: _category_id = int(_category_id) _old_category_id = request.POST.get("old_category_id", None) if _old_category_id: _old_category_id = int(_old_category_id) _entity = Entity(entity_id) _entity.update( category_id=_category_id, old_category_id=_old_category_id, brand=_brand, title=_title, intro=_intro, price=_price, chief_image_id=_chief_image_id, weight=_weight, mark=_mark, ) _note = request.POST.get("note", None) _user_id = request.POST.get("user_id", None) if _note != None and len(_note) > 0: _add_note_and_select_delay(_entity, _user_id, _note) return HttpResponseRedirect(request.META['HTTP_REFERER'])
def note_list(request): _selection = request.GET.get("selection", None) _nav_filter = 'all' _sort_by = None _para = {} _select_entity_id = request.GET.get("entity_id", None) _select_user_id = request.GET.get("user_id", None) if _selection == 'only': _selection = 1 _nav_filter = 'selection_only' _sort_by = 'selection_post_time' _para['selection'] = 'only' elif _selection == 'none': _selection = -1 _nav_filter = 'selection_none' _para['selection'] = 'none' else: _selection = 0 _freezed = request.GET.get("freeze", None) if _freezed == '1': _status = -1 _nav_filter = 'freezed' _para['freeze'] = '1' else: _status = 1 _page_num = int(request.GET.get("p", "1")) if not _select_entity_id and not _select_user_id: _note_count = Note.count(selection=_selection, status=_status) _paginator = Paginator(_page_num, 30, _note_count, _para) _note_id_list = Note.find(offset=_paginator.offset, count=_paginator.count_in_one_page, selection=_selection, status=_status, sort_by=_sort_by) else: _para['entity_id'] = _select_entity_id _note_count = Note.count(entity_id=_select_entity_id) _paginator = Paginator(_page_num, 30, _note_count, _para) _note_id_list = Note.find(entity_id=_select_entity_id, user_id=_select_user_id, offset=_paginator.offset, count=_paginator.count_in_one_page) _context_list = [] for _note_id in _note_id_list: try: _note = Note(_note_id) _note_context = _note.read() _entity_id = _note_context['entity_id'] _entity_context = Entity(_entity_id).read() _is_future = 0 if _note_context['post_time'] is not None: post_time = time.mktime(_note_context['post_time'].timetuple()) bench_time = time.mktime( datetime.datetime(2100, 1, 1).timetuple()) if post_time == bench_time: _is_future = 1 _context_list.append({ 'entity': _entity_context, 'note': _note_context, 'creator': User(_note_context['creator_id']).read(), 'is_future': _is_future, }) except Exception, e: log.error("Error: %s" % e.message)