Esempio n. 1
0
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),
    })
Esempio n. 2
0
def _render(request, template_name, period, exclude_continuous=False):
    indexes = WorkPeriodIndex.objects.filter(period=str(period)).all()
    if exclude_continuous:
        # Only include new or split-cour animes
        prev_period = str(period.prev())
        indexes = filter(lambda i: prev_period not in i.work.metadata["periods"], indexes)
    data = [serializers.serialize_work(index.work, request.user) for index in indexes]
    return render(
        request,
        template_name,
        {
            "period": period,
            "preload_data": {
                "period": str(period),
                "current_user": serializers.serialize_user(request.user, request.user)
                if request.user.is_authenticated()
                else None,
                "schedule": data,
            },
        },
    )
Esempio n. 3
0
 def get(self, request, period):
     period = Period.parse(period)
     cache_key = "table:%s" % period
     only_first_period = request.GET.get("only_first_period") == "true"
     if only_first_period:
         cache_key += ":first_only"
     data = cache.get(cache_key)
     if data is None:
         indexes = WorkPeriodIndex.objects.select_related("work", "work__index").filter(period=str(period))
         if only_first_period:
             indexes = indexes.exclude(is_first_period=False)
         data = [serialize_work(index.work) for index in indexes]
         cache.set(cache_key, data, 60 * 60)
     if request.user.is_authenticated():
         records = {}
         work_ids = [work["id"] for work in data]
         for record in request.user.record_set.filter(work_id__in=work_ids):
             records[record.work_id] = serialize_record(record)
         for work in data:
             if work["id"] in records:
                 work["record"] = records[work["id"]]
     return data
Esempio n. 4
0
def detail(request, title):
    work = _get_work(title)
    preload_data = {
        'title': title,
        'work': serializers.serialize_work(work, request.user),
        '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(),
    }
    content_data = {
        'title': title,
        'preload_data': preload_data,
        'html': _call_backend('work', preload_data),
    }
    try:
        studios = u','.join(preload_data['work']['metadata']['studios'])
        content_data.update({
            'meta_description': u'{} 제작'.format(studios),
            'meta_keywords': u','.join([title, studios]),
        })
    except KeyError:
        pass
    return render(request, "work.html", content_data)
Esempio n. 5
0
 def _serialize(item):
     work = item['object']
     item['object'] = serialize_work(work)
     return item
Esempio n. 6
0
 def get(self, request, id, title=None):
     if id == '_':
         id = get_object_or_404(TitleMapping, title=title).work_id
     work = get_object_or_404(Work, id=id)
     return serialize_work(work, request.user, full=True)
Esempio n. 7
0
 def post(self, request):
     payload = json.loads(request.body)
     work = get_or_create_work(payload['title'])
     return serialize_work(work)
Esempio n. 8
0
 def _serialize(item):
     item['object'] = serializers.serialize_work(item['object'])
     return item