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')
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)
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)
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)