def post(self, request, id): record = get_object_or_404(Record, id=id) self.check_login() if request.user.id != record.user_id: self.raise_error('Permission denied.', status=403) with transaction.atomic(): history = History.objects.create( user=request.user, work=record.work, record=record, status=request.POST['status'], status_type=StatusType[request.POST['status_type']], comment=request.POST['comment'], contains_spoiler=request.POST.get('contains_spoiler') == 'true', ) record.status_type = history.status_type record.status = history.status record.updated_at = history.updated_at record.save() if request.POST.get('publish_twitter') == 'on': post_history_to_twitter(request.user, history) return { 'record': serialize_record(record), 'post': serialize_post(history), }
def get(self, request, name): user = get_object_or_404(User, username=name) queryset = user.history_set.order_by('-id') if 'before_id' in request.GET: queryset = queryset.filter(id__lt=request.GET['before_id']) count = min(int(request.GET.get('count', 32)), 128) return [serialize_post(post, include_record=True) for post in queryset[:count]]
def get(self, request, id): work = get_object_or_404(Work, id=id) queryset = work.history_set.select_related("user").exclude(comment="").order_by("-id") if "before_id" in request.GET: queryset = queryset.filter(id__lt=request.GET["before_id"]) if "episode" in request.GET: queryset = queryset.filter(status=request.GET["episode"]) count = min(int(request.GET.get("count", 32)), 128) return [serialize_post(post, include_user=True) for post in queryset[:count]]
def get(self, request): queryset = (History.objects.select_related('user', 'work') .exclude(comment='').order_by('-id')) if 'before_id' in request.GET: queryset = queryset.filter(id__lt=request.GET['before_id']) if 'min_record_count' in request.GET: queryset = queryset.filter(work__index__record_count__gte=request.GET['min_record_count']) count = min(int(request.GET.get('count', 32)), 128) return [serialize_post(post, include_record=True, include_user=True) for post in queryset[:count]]
def get(self, request, id): work = get_object_or_404(Work, id=id) queryset = work.history_set.exclude(comment='').order_by('-id') if 'before_id' in request.GET: queryset = queryset.filter(id__lt=request.GET['before_id']) if 'episode' in request.GET: queryset = queryset.filter(status=request.GET['episode']) count = min(int(request.GET.get('count', 32)), 128) return [serialize_post(post, include_user=True) for post in queryset[:count]]
def post_detail(request, id): post = get_object_or_404(History, id=id) preload_data = { 'post': serializers.serialize_post(post, include_user=True), 'work': serializers.serialize_work(post.work), 'current_user': serializers.serialize_user(request.user, request.user) if request.user.is_authenticated() else None, 'daum_api_key': settings.DAUM_API_KEY, 'chart': _get_chart(), } return render(request, 'post.html', { 'title': post.record.title, 'preload_data': preload_data, 'html': _call_backend('post', preload_data), })
def post(self, request, name): self.check_login() if request.user.username != name: self.raise_error('Permission denied.', status=403) title = request.POST.get('work_title') if not title: # 400 Bad Request self.raise_error(u'작품 제목을 입력하세요.', status=400) work = get_or_create_work(title) category_id = request.POST.get('category_id') if category_id: # TODO: Raise appropriate exception if not exist/no permission category = request.user.category_set.get(id=category_id) else: category = None try: record = Record.objects.get(user=request.user, work=work) # 422 Unprocessable Entity self.raise_error( u'이미 같은 작품이 "%s"로 등록되어 있습니다.' % record.title, status=422 ) except Record.DoesNotExist: pass record = Record.objects.create( user=request.user, work=work, title=title, category=category, status='', status_type=StatusType[request.POST['status_type']], ) history = History.objects.create( user=request.user, work=record.work, record=record, status=record.status, status_type=record.status_type, updated_at=record.updated_at ) return { 'record': serialize_record(record), 'post': serialize_post(history), }
def post(self, request, id): record = get_object_or_404(Record, id=id) self.check_login() if request.user.id != record.user_id: self.raise_error('Permission denied.', status=403) history = History.objects.create( user=request.user, work=record.work, status=request.POST['status'], status_type=StatusTypes.from_name(request.POST['status_type']), comment=request.POST['comment'], ) services = [] if request.POST.get('publish_twitter') == 'on': services.append('twitter') post_history(history, services) return { 'record': serialize_record(history.record), 'post': serialize_post(history), }
def _get_timeline(): return [serializers.serialize_post(post, include_record=True, include_user=True) for post in History.objects.select_related('user', 'work') .filter(work__index__record_count__gt=1) .exclude(comment='')[:10]]
def get(self, request, id): post = get_object_or_404(History, id=id) return serialize_post(post, include_record=True, include_user=True)