コード例 #1
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))
コード例 #2
0
ファイル: ustation.py プロジェクト: guoku/Raspberry
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
コード例 #3
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
コード例 #4
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)