def post_details(request, post_id): """ patching django-planet's post_detail view so it would update the hitcount and redirect to the post's url """ from hitcount.views import _update_hit_count from hitcount.models import HitCount from planet.models import Post # update the it count ctype = ContentType.objects.get(app_label="planet", model="post") hitcount, created = HitCount.objects.get_or_create(content_type=ctype, object_pk=post_id) result = _update_hit_count(request, hitcount) post = get_object_or_404(Post, pk=post_id) return HttpResponseRedirect(post.url)
def post_details(request, post_id): ''' patching django-planet's post_detail view so it would update the hitcount and redirect to the post's url ''' from hitcount.views import _update_hit_count from hitcount.models import HitCount from planet.models import Post # update the it count ctype = ContentType.objects.get(app_label="planet", model="post") hitcount, created = HitCount.objects.get_or_create(content_type=ctype, object_pk=post_id) result = _update_hit_count(request, hitcount) post = get_object_or_404(Post, pk=post_id) return HttpResponseRedirect(post.url)
def minus_download(request, author, id): minus = get_object_or_404(MinusRecord, id=int(id)) hitcount, c = HitCount.objects.get_or_create( object_pk=minus.pk, content_type=ContentType.objects.get_for_model(MinusRecord)) if _update_hit_count(request, hitcount): stat, c = MinusStats.objects.get_or_create(minus=minus, date=datetime.date.today) stat.rate = F('rate') + 1 stat.save() minus.rating.score += 1 minus.save() create_rating(sender=MinusRecord, instance=minus.user) #call signal to recount rating return redirect(minus.file.url, permanent=True) #attachment is handled by ngnix
def test_get_hit_count_warning(self): with warnings.catch_warnings(record=True) as w: _update_hit_count(self.request_post, self.hit_count) self.assertTrue(issubclass(w[-1].category, RemovedInHitCount13Warning))
def test_get_hit_count_warning(self): with warnings.catch_warnings(record=True) as w: _update_hit_count(self.request_post, self.hit_count) self.assertTrue( issubclass(w[-1].category, RemovedInHitCount13Warning))