Esempio n. 1
0
def freeze_note(request, note_id):
    if request.method == 'GET':
        _note = Note(note_id)
        _entity_id = _note.get_entity_id()
        _entity = Entity(_entity_id)
        _entity.update_note(note_id=note_id, weight=-1)
        return HttpResponseRedirect(request.META['HTTP_REFERER'])
Esempio n. 2
0
 def run(self, user_id):
     _user_id = int(user_id)
     for _note_id in Note.find(user_id=_user_id, status=1):
         try:
             _note = Note(_note_id)
             _entity_id = _note.get_entity_id()
             _entity = Entity(_entity_id)
             _entity.update_note(note_id=_note_id, weight=-1)
         except Exception, e:
             pass
         logger.info("entity note [%d] of [%d] freezed..." %
                     (_note_id, _user_id))
Esempio n. 3
0
def add_comment(request, note_id, template='note/note_comment.html'):
    if request.method == 'POST':
        _user_context = User(request.user.id).read()
        _creator_id = request.user.id
        _comment_text = request.POST.get('comment_text', None)
        _reply_to_user_id = request.POST.get('reply_to_user_id', None)
        _reply_to_comment_id = request.POST.get('reply_to_comment_id', None)

        _ret = {
            'status' : '0',
            'msg' : ''
        }

        if _comment_text is not None and len(_comment_text) > 0:
            if _reply_to_comment_id is not None:
                if len(_reply_to_user_id) > 0:
                    _reply_to_comment_id = int(_reply_to_comment_id)
                else:
                    _reply_to_comment_id = None

            if _reply_to_user_id is not None:
                if len(_reply_to_user_id) > 0:
                    _reply_to_user_id = int(_reply_to_user_id)
                else:
                    _reply_to_user_id = None

            _note = Note(int(note_id))
            _new_comment_id = _note.add_comment(_comment_text, _creator_id, reply_to_comment_id=_reply_to_comment_id,
                                                reply_to_user_id=_reply_to_user_id)
            _comment_context = _note.read_comment(_new_comment_id)

            if _reply_to_user_id is not None:
                _nickname = User(_reply_to_user_id).read()['nickname']
                _comment_context['reply_to_user_nickname'] = _nickname

            _creator_context = User(_creator_id).read()

            _t = loader.get_template(template)
            _c = RequestContext(request, {
                'comment_context': _comment_context,
                'creator_context': _creator_context,
                'user_context': _user_context
            })
            _data = _t.render(_c)

            _ret = {
                'status': '1',
                'data': _data
            }
        return JSONResponse(_ret)
Esempio n. 4
0
def note_comment_list(request):
    _page_num = int(request.GET.get("p", "1"))
    _comment_count = Note.comment_count()
    _paginator = Paginator(_page_num, 30, _comment_count)

    _context_list = []
    for _comment in Note.find_comment(offset=_paginator.offset,
                                      count=_paginator.count_in_one_page):
        try:
            _comment_context = Note(_comment[0]).read_comment(_comment[1])
            _comment_context['creator'] = User(
                _comment_context['creator_id']).read()
            _context_list.append(_comment_context)
        except Exception, e:
            pass
Esempio n. 5
0
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'])
Esempio n. 6
0
def get_comments(request, note_id, template='note/note_comment_list.html'):
    # _user_context = User(request.user.id)

    if request.user.is_authenticated():
        _user_context = User(request.user.id)
    else:
        _user_context = None
    _note = Note(note_id)
    _note_context = _note.read()


    _comment_id_list = _note_context['comment_id_list']
    _comment_list = []

    for _c_id in _comment_id_list:
        _comment_context = _note.read_comment(_c_id)
        _creator_id = _comment_context['creator_id']
        _creator_context = User(_creator_id).read()
        _reply_to_user_id = _comment_context['reply_to_user_id']

        if _reply_to_user_id is not None:
            _nickname = User(_reply_to_user_id).read()['nickname']
            _comment_context['reply_to_user_nickname'] = _nickname

        _comment_list.append(
            {
                'comment_context' : _comment_context,
                'creator_context' : _creator_context,
                'note_context' : _note_context,
                'user_context' : _user_context
            }
        )

    _t = loader.get_template(template)
    _c = RequestContext(request, {
        'comment_list': _comment_list,
        'note_context': _note_context,
    })
    _data = _t.render(_c)
    _ret = {
        # 'status': '1',
        'data': _data
    }
    if len( _note_context['comment_id_list'] ) < 1:
        # raise Http404
        return JSONResponse(_ret, status=404)
    return JSONResponse(_ret)
Esempio n. 7
0
def sync_ustation(request):
    _entity_context_list = _available_ustation_list()
    _rslt = []
    for _entity_context in _entity_context_list:
        try:
            _note_id = Note.find(entity_id=_entity_context['entity_id'],
                                 selection=1)[0]
            _note_context = Note(_note_id).read()
            _item_context = Item(_entity_context['item_id_list'][0]).read()
            _shop_nick = _item_context['shop_nick']
            _rslt.append({
                'item_id': _entity_context['taobao_id'],
                'cid': _entity_context['old_root_category_id'],
                'note': _note_context['content'],
                'is_global': TaobaoShop.is_global_shop(_shop_nick)
            })
        except Exception, e:
            pass
Esempio n. 8
0
def display_feed_item(obj):
    _note_id = obj.note_id
    _note_context = Note(_note_id).read()
    _creator_context = User(_note_context['creator_id']).read()
    _entity_id = obj.entity_id
    _entity_context = Entity(_entity_id).read()

    return {
        'note_context': _note_context,
        'entity_context': _entity_context,
        'creator_context': _creator_context,
    }
Esempio n. 9
0
def edit_note(request, note_id):
    if request.method == 'GET':
        _note_context = Note(note_id).read()
        _entity_context = Entity(_note_context['entity_id']).read()
        return render_to_response(
            'note/edit.html', {
                'active_division': 'note',
                'entity_context': _entity_context,
                'note_context': _note_context,
                'creator': User(_note_context['creator_id']).read()
            },
            context_instance=RequestContext(request))
    elif request.method == 'POST':
        _note_text = request.POST.get("note", None)
        _weight = int(request.POST.get("weight", '0'))
        _note = Note(note_id)
        _entity_id = _note.get_entity_id()
        _entity = Entity(_entity_id)
        _entity.update_note(note_id=note_id,
                            note_text=_note_text,
                            weight=_weight)
        return HttpResponseRedirect(request.META['HTTP_REFERER'])
Esempio n. 10
0
def tencent_selection(request, template='tencent/selection.html'):
    _start_at = datetime.now()
    if request.user.is_authenticated():
        _request_user_id = request.user.id
    else:
        _request_user_id = None
    _agent = 'iphone'
    if 'Android' in request.META['HTTP_USER_AGENT']:
        _agent = 'android'

    _page_num = int(request.GET.get('p', 1))
    _hdl = NoteSelection.objects.filter(post_time__lt=datetime.now())
    _paginator = Paginator(_page_num, 30, _hdl.count())
    _hdl = _hdl.order_by('-post_time')
    _selection_list = []
    _entity_id_list = []
    for _note_selection in _hdl[_paginator.offset:_paginator.offset +
                                _paginator.count_in_one_page]:
        _selection_note_id = _note_selection['note_id']
        _entity_id = _note_selection['entity_id']
        _entity_context = Entity(_entity_id).read()
        _note_context = Note(_selection_note_id).read()
        _creator_context = User(_note_context['creator_id']).read()

        _selection_list.append({
            'entity_context': _entity_context,
            'note_context': _note_context,
            'creator_context': _creator_context,
        })
        _entity_id_list.append(_entity_id)

    _duration = datetime.now() - _start_at
    WebLogTask.delay(
        entry='tencent',
        duration=_duration.seconds * 1000000 + _duration.microseconds,
        page='SELECTION',
        request=request.REQUEST,
        ip=get_client_ip(request),
        log_time=datetime.now(),
        request_user_id=_request_user_id,
        appendix={
            'result_entities': _entity_id_list,
        },
    )

    return render_to_response(template, {
        'agent': _agent,
        'selection_list': _selection_list,
        'next_page_num': _page_num + 1,
    },
                              context_instance=RequestContext(request))
Esempio n. 11
0
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
Esempio n. 12
0
def delete_comment(request, note_id, comment_id):
    if request.method == 'POST':
        _note = Note(note_id)
        _note_context = _note.read()
        _comment_context = _note.read_comment(comment_id)
        _user_id = request.user.id

        # 判断当前用户是否具有删除权限
        if _comment_context['creator_id'] == _user_id or _note_context['creator_id'] == _user_id:
            _note.del_comment(comment_id)

            return HttpResponse('1')
Esempio n. 13
0
def user_tag_entity_list(request, user_id, tag):
    _page_num = int(request.GET.get("p", "1"))
    _entity_id_list = Tag.find_user_tag_entity(user_id, tag)
    _paginator = Paginator(_page_num, 30, len(_entity_id_list))
    _category_title_dict = Category.get_category_title_dict()
    _user_context = User(user_id).read()
    
    _entity_context_list = []
    for _entity_id in _entity_id_list[_paginator.offset : _paginator.offset + _paginator.count_in_one_page]:
        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()
                _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
Esempio n. 14
0
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)
Esempio n. 15
0
def selection(request, template='main/selection.html'):

    _user_agent = request.META['HTTP_USER_AGENT']
    if _user_agent == None:
        log.error(
            "[selection] Remote Host [%s] access selection without user agent"
            % (request.META['REMOTE_ADDR']))
        raise Http404

    _agent = request.GET.get('agent', 'default')
    if _agent == 'default':
        if 'iPhone' in _user_agent:
            _agent = 'iphone'
        if 'Android' in _user_agent:
            _agent = 'android'
    if _agent == 'iphone' or _agent == 'android':
        return HttpResponseRedirect(reverse('wap_selection'))

    _start_at = datetime.now()
    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)
    else:
        _request_user_id = None
        _request_user_context = None
        _request_user_like_entity_set = []

    _old_category_list = Old_Category.find()[0:11]

    _page_num = 1
    _time_filter = request.GET.get('t', datetime.now())
    _category_id = request.GET.get('c', None)

    _hdl = NoteSelection.objects.filter(post_time__lt=_time_filter)
    if _category_id != None:
        _category_id = int(_category_id)
        _hdl = _hdl.filter(root_category_id=_category_id)
    else:
        _category_id = 0
    _hdl.order_by('-post_time')

    _paginator = Paginator(_page_num, 30, _hdl.count())
    _note_selection_list = _hdl[_paginator.offset:_paginator.offset +
                                _paginator.count_in_one_page]
    _selection_list = []
    _entity_id_list = []
    for _note_selection in _note_selection_list:
        try:
            _selection_note_id = _note_selection['note_id']
            _entity_id = _note_selection['entity_id']
            _entity_context = Entity(_entity_id).read()
            _note = Note(_selection_note_id)
            _note_context = _note.read()
            _creator_context = User(_note_context['creator_id']).read()
            _is_user_already_like = True if _entity_id in _request_user_like_entity_set else False
            _selection_list.append({
                'is_user_already_like': _is_user_already_like,
                'entity_context': _entity_context,
                'note_context': _note_context,
                'creator_context': _creator_context,
            })
            _entity_id_list.append(_entity_id)
        except Exception, e:
            log.error(e.message)
Esempio n. 16
0
 def run(self, note_id, request_user_id=None):
     _note_id = int(note_id)
     _request_user_id = int(request_user_id)
     Note(note_id).depoke(_request_user_id)
Esempio n. 17
0
def web_message(request, template='account/message.html'):
    _start_at = datetime.now()
    if request.method == "GET":
        _request_user_id = request.user.id
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.fromtimestamp(float(_timestamp))
        else:
            _timestamp = datetime.now()
        _count = int(request.GET.get('count', 30))

        _recommend_tag_list = Tag.get_recommend_user_tag_list()

        _popular_list = popularity.read_popular_user_context()
        _popular_list_detail = []
        if _popular_list != None:
            for _popular_user in _popular_list["data"]:
                try:
                    _popu_context = {
                        "user_id":
                        _popular_user["user_id"],
                        "user_context":
                        User(_popular_user["user_id"]).read(),
                        "relation":
                        User.get_relation(_request_user_id,
                                          _popular_user["user_id"])
                    }
                    _popular_list_detail.append(_popu_context)
                except Exception, e:
                    print e
                    pass
        _rslt = []
        for _message in NeoMessage.objects.filter(
                user_id=_request_user_id,
                created_time__lt=_timestamp).order_by(
                    '-created_time')[0:_count]:
            try:
                if isinstance(_message, UserFollowMessage):
                    _context = {
                        'type':
                        'user_follow',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'follower':
                            User(_message.follower_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NotePokeMessage):
                    _context = {
                        'type':
                        'note_poke_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'note':
                            Note(_message.note_id).read(_request_user_id),
                            'poker':
                            User(_message.poker_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NoteCommentMessage):
                    _context = {
                        'type':
                        'note_comment_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'note':
                            Note(_message.note_id).read(_request_user_id),
                            'comment':
                            Note(_message.note_id).read_comment(
                                _message.comment_id),
                            'comment_user':
                            User(_message.comment_creator_id).read(
                                _request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NoteCommentReplyMessage):
                    _context = {
                        'type':
                        'note_comment_reply_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'note':
                            Note(_message.note_id).read(_request_user_id),
                            'comment':
                            Note(_message.note_id).read_comment(
                                _message.comment_id),
                            'replying_comment':
                            Note(_message.note_id).read_comment(
                                _message.replying_comment_id),
                            'replying_user':
                            User(_message.replying_user_id).read(
                                _request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, EntityLikeMessage):
                    _context = {
                        'type':
                        'entity_like_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'liker':
                            User(_message.liker_id).read(_request_user_id),
                            'entity':
                            Entity(_message.entity_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, EntityNoteMessage):
                    _context = {
                        'type':
                        'entity_note_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'note':
                            Note(_message.note_id).read(_request_user_id),
                            'entity':
                            Entity(_message.entity_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NoteSelectionMessage):
                    _context = {
                        'type':
                        'note_selection_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'note':
                            Note(_message.note_id).read(_request_user_id),
                            'entity':
                            Entity(_message.entity_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
            except Exception, e:
                print e
                pass
Esempio n. 18
0
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))
Esempio n. 19
0
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'])
Esempio n. 20
0
 def item_author_name(self, item):
     _note_id = item.note_id
     _note_context = Note(_note_id).read()
     _creator_context = User(_note_context['creator_id']).read()
     return _creator_context['nickname']
Esempio n. 21
0
 def run(self, note_id, comment_id):
     _note = Note(note_id)
     _note.del_comment(comment_id)
Esempio n. 22
0
def delete_note_comment(request, note_id, comment_id):
    _note = Note(note_id)
    _note.del_comment(comment_id)
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
Esempio n. 23
0
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'])
Esempio n. 24
0
 def item_pubdate(self, item):
     _note_id = item.note_id
     _note_context = Note(_note_id).read()
     return _note_context['post_time']