예제 #1
0
파일: cbvviews.py 프로젝트: trofi4/dj
 def get_context_data(self, **kwargs):
     context = super(DetailItem, self).get_context_data(**kwargs)
     if self.object.__class__.__name__ == 'Serial':
         votes = Voting(self.object, self.request.user)
         context['watched'] = False
         context['truecomment'] = 0
         context['actors'] = self.object.actor_set.all()[:10]
         context['seasons'] = self.object.season_set.all()
         context['reviews'] = self.object.review_set.all()[:3]
         context['has_review'] = True
         context['votes'] = votes
         context['vote_succes'] = False
         if context['reviews'] == 0:
             context['has_review'] = False
         if self.request.user.is_authenticated():
             profile = self.request.user.get_profile()
             if profile.watched(self.object):
                 context['watched'] = True
         if 'postcomment' in self.request.POST and self.request.POST['comment'] is not None:
             type = ContentType.objects.get(app_label='sdata', model='serial')
             site = Site.objects.get(id=1)
             comments_count = str(Comment.objects.all().count())
             comment = Comment(content_type=type, content_object=self.object, object_pk=comments_count, site=site, user=self.request.user, comment=self.request.POST['comment'])
             comment.save()
             context['truecomment'] = 1
         if 'watch' in self.request.GET:
             profile.watch.add(serial)
             profile.save()
             context['watched'] = True
         if 'vote' in self.request.POST:
             votes.set_votes(self.request.POST['vote'])
             context['vote_succes'] = True
     return context
     
예제 #2
0
파일: views.py 프로젝트: trofi4/dj
def obj_by_id(request, id, model=None, template_name=None):
    obj = model.objects.get(id=id)
    votes = Voting(obj, request.user)
    vote_succes = False
    if 'vote' in request.POST:
        votes.set_votes(request.POST['vote'])
        vote_succes = True
    return render_to_response(template_name, {'obj': obj, 'votes': votes, 'vote_succes': vote_succes}, context_instance=RequestContext(request, processors=[_context]))
예제 #3
0
파일: views.py 프로젝트: trofi4/dj
def serial(request, _name=''):
    name = ' '.join(_name.split('_'))
    try:
        profile = request.user.get_profile()
        dd = True
    except:
        dd = None
    serial = Serial.objects.get(original_name__iexact=name)
    truecomment = 0
    if 'postcomment' in request.POST and request.POST['comment'] is not None:
        type = ContentType.objects.get(app_label='sdata', model='serial')
        site = Site.objects.get(id=1)
        comments_count = str(Comment.objects.all().count())
        comment = Comment(content_type=type, content_object=serial, object_pk=comments_count, site=site, user=request.user, comment=request.POST['comment'])
        comment.save()
        truecomment = 1
    watched = False
    if 'watch' in request.GET:
        profile.watch.add(serial)
        profile.save()
        watched = True
    if dd and profile.watched(serial):
        watched = True
    actors = serial.actor_set.all()[:10]
    seasons = Season.objects.filter(serial__original_name__iexact=name)
    reviews = Review.objects.filter(serial__original_name__iexact=name)[0:3]
    genres = serial.genre.all()
    countries = serial.country.all()
    votes = Voting(serial, request.user)
    vote_succes = False
    has_review = True
    if len(reviews) == 0:
        has_review = False
    if 'vote' in request.POST:
        votes.set_votes(request.POST['vote'])
        vote_succes = True
    return render_to_response('serial.html', {'watched': watched, 'serial': serial, 'seasons': seasons, 'vote_succes': vote_succes, 'reviews': reviews, 'has_review': has_review, 'genres': genres, 'countries': countries, 'actors': actors, 'votes': votes, 'truecomment': truecomment}, context_instance=RequestContext(request, processors=[_context]))