def get_hit_count_javascript_template(context, object, **kwargs): ''' Return javascript for an object and requires jQuery. NOTE: only works on a single object, not an object list. For example: {% get_hit_count_javascript_template [object] %} ''' url = reverse('update_hit_count_ajax') ctype, object_pk = get_target_ctype_pk(object) csrf_token = unicode(context['csrf_token']) template_context = { 'ctype_pk': ctype.pk, 'object_pk': object_pk, 'csrf_token': csrf_token, 'url' : url, } if CACHED_HITCOUNT_CLIENT_CALLBACKS: template_context['client_callbacks'] = CACHED_HITCOUNT_CLIENT_CALLBACKS return template_context
def get_hit_count_javascript_template(context, object, **kwargs): ''' Return javascript for an object and requires jQuery. NOTE: only works on a single object, not an object list. For example: {% get_hit_count_javascript_template [object] %} ''' url = reverse('update_hit_count_ajax') ctype, object_pk = get_target_ctype_pk(object) csrf_token = unicode(context['csrf_token']) template_context = { 'ctype_pk': ctype.pk, 'object_pk': object_pk, 'csrf_token': csrf_token, 'url': url, } if CACHED_HITCOUNT_CLIENT_CALLBACKS: template_context['client_callbacks'] = CACHED_HITCOUNT_CLIENT_CALLBACKS return template_context
def process_object_saved(sender, **kwargs): """ Called when an object is saved. It will create an initial Hit entry with 0 hits """ object = kwargs['instance'] created = kwargs['created'] if created: ctype, object_pk = get_target_ctype_pk(object) Hit.objects.select_for_update().get_or_create(added=datetime.datetime.utcnow().date(), object_pk=object_pk, content_type=ctype) from cached_hitcount.views import _update_hit_count#prevent circular import _update_hit_count(None,object_pk, ctype.pk)
def process_object_saved(sender, **kwargs): """ Called when an object is saved. It will create an initial Hit entry with 0 hits """ object = kwargs['instance'] created = kwargs['created'] if created: ctype, object_pk = get_target_ctype_pk(object) Hit.objects.select_for_update().get_or_create( added=datetime.datetime.utcnow().date(), object_pk=object_pk, content_type=ctype) from cached_hitcount.views import _update_hit_count #prevent circular import _update_hit_count(None, object_pk, ctype.pk)
def _create_sample_model(self): self.sample_model = Hit() self.sample_model.object_pk = 435 ctype, object_pk = get_target_ctype_pk(self.sample_model) self.sample_model.content_type = ctype self.sample_model.save()