Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def home(request):
timestamp = get_request_timestamp(request)
if timestamp == 0:
latest_items = Post.accepted.filter(show_in_default=1)\
.order_by('-is_ads', '-timestamp')[:20]
else:
latest_items = Post.accepted.filter(show_in_default=1)\
.extra(where=['timestamp<%s'], params=[timestamp])\
.order_by('-timestamp')[:20]
if request.is_ajax():
if latest_items.exists():
return render(request,
'pin/_items.html',
{'latest_items': latest_items})
else:
return HttpResponse(0)
else:
return render(request, 'pin/home.html', {'latest_items': latest_items})
def delete_all_user_posts(self, request, queryset):
for obj in queryset:
user = obj.user
user.is_active = False
user.save()
Post.objects.filter(user=obj.user).delete()
Comments.objects.filter(user=obj.user).delete()
comment = models.ForeignKey(Comments)
user = models.ForeignKey(User, related_name='comment_like_user')
score = models.IntegerField(default=0, blank=True)
class Report(models.Model):
user = models.ForeignKey(User, related_name='report_user')
post = models.ForeignKey(Post, related_name='report_post')
class Meta:
unique_together = (("post", "user"),)
post_save.connect(Stream.add_post, sender=Post)
post_save.connect(Likes.user_like_post, sender=Likes)
#post_delete.connect(Likes.user_unlike_post, sender=Likes)
post_save.connect(Post.change_tag_slug, sender=Tag)
post_save.connect(Notif.add_comment, sender=Comments)
def get_absolute_url(self):
return ('pin-item', [str(self.object_pk_id)])
def admin_link(self):
return '<a href="%s">مشاهده</a>' % (self.get_absolute_url())
admin_link.allow_tags = True
class Comments_score(models.Model):
comment = models.ForeignKey(Comments)
user = models.ForeignKey(User, related_name='comment_like_user')
score = models.IntegerField(default=0, blank=True)
class Report(models.Model):
user = models.ForeignKey(User, related_name='report_user')
post = models.ForeignKey(Post, related_name='report_post')
class Meta:
unique_together = (("post", "user"),)
post_save.connect(Stream.add_post, sender=Post)
post_save.connect(Likes.user_like_post, sender=Likes)
#post_delete.connect(Likes.user_unlike_post, sender=Likes)
post_save.connect(Post.change_tag_slug, sender=Tag)
post_save.connect(Notif.add_comment, sender=Comments)
admin_link.allow_tags = True
class Comments_score(models.Model):
comment = models.ForeignKey(Comments)
user = models.ForeignKey(User, related_name='comment_like_user')
score = models.IntegerField(default=0, blank=True)
class Report(models.Model):
user = models.ForeignKey(User, related_name='report_user')
post = models.ForeignKey(Post, related_name='report_post')
class Meta:
unique_together = (("post", "user"),)
post_save.connect(Stream.add_post, sender=Post)
post_save.connect(Likes.user_like_post, sender=Likes)
#post_delete.connect(Likes.user_unlike_post, sender=Likes)
post_save.connect(Post.change_tag_slug, sender=Tag)
post_save.connect(Notif.add_comment, sender=Comments)
user.is_active = False
user.save()
obj.delete()
delete_and_deactive_user.short_description = 'حذف و غیر فعال کردن کاربر'
def delete_all_user_comments(self, request, queryset):
for obj in queryset:
user = obj.user
user.is_active = False
user.save()
Comments.objects.filter(user=obj.user).delete()
delete_all_user_comments.short_description = 'حذف تمام کامنت های این کاربر و غیر فعال کردن کاربر'
admin.site.register(Post, PinAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Profile, ProfileAdmin)
admin.site.register(App_data, AppAdmin)
admin.site.register(Comments, CommentsAdmin)