Best Python code snippet using lisa_python
signals.py
Source:signals.py
...60def comment_on_delete(sender, instance, **kwargs):61 if instance.content_object and isinstance(instance.content_object, Post):62 try:63 if not instance.parent:64 instance.content_object.update_summary()65 instance.content_object.save()66 else:67 instance.parent.update_summary()68 instance.parent.save()69 except ObjectDoesNotExist:70 pass71@receiver(post_save, sender=Comment)72def comment_on_create_or_update(sender, created, instance, **kwargs):73 if created:74 if instance.content_object and isinstance(instance.content_object, Post):75 if not instance.parent:76 instance.content_object.update_summary()77 instance.content_object.save()78 else:79 instance.parent.update_summary()80 instance.parent.save()81@receiver(post_delete, sender=View)82def view_on_delete(sender, instance, **kwargs):83 if instance.post:84 instance.post.update_summary()85 instance.post.save()86@receiver(post_save, sender=View)87def view_on_create_or_update(sender, created, instance, **kwargs):88 if created and instance.post:89 instance.post.update_summary()90 instance.post.save()91@receiver(post_delete, sender=GroupUser)92def groupuser_on_delete(sender, instance, **kwargs):93 if instance.group:94 instance.group.update_summary()95 instance.group.save()96@receiver(post_save, sender=GroupUser)97def groupuser_on_create_or_update(sender, created, instance, **kwargs):98 if instance.group:99 instance.group.update_summary()100 instance.group.save()101@receiver(post_save, sender=Approval)102def approval_on_create_or_update(sender, created, instance, **kwargs):103 instance.update_public_code()104@receiver(post_delete, sender=Approval)105def approval_on_delete(sender, instance, **kwargs):106 pass107@receiver(post_delete, sender=Post)108def post_on_delete(sender, instance, **kwargs):109 if instance.group:110 instance.group.update_summary()111 instance.group.save()112@receiver(post_save, sender=Post)113def post_on_create_or_update(sender, created, instance, **kwargs):114 if instance.group:115 instance.group.update_summary()116 instance.group.save()117@receiver(pre_save, sender=Link)118def link_on_pre_save(sender, instance, **kwargs):119 extraction = extraction_link(instance.link)120 instance.title = extraction['title']121 instance.description = extraction['description']122 instance.picture = extraction['picture']...
admin.py
Source:admin.py
...8class UserCourseSummaryAdmin(admin.ModelAdmin):9 list_display = ('user', 'course', 'points', 'total_downloads', 'total_activity', 'quizzes_passed',10 'badges_achieved', 'pretest_score', 'media_viewed', 'completed_activities')11 actions = ['update_summary']12 def update_summary(self, request, queryset):13 for course_summary in queryset:14 course_summary.update_summary()15 message_user(self, request, "User-course", queryset.count())16 update_summary.short_description = "Update summary"17class CourseDailyStatsAdmin(admin.ModelAdmin):18 list_display = ('course', 'day', 'type', 'total')19 date_hierarchy = 'day'20 ordering = '-day',21 actions = ['update_summary']22 def update_summary(self, request, queryset):23 for daily_stats in queryset:24 CourseDailyStats.update_daily_summary(daily_stats.course.id, daily_stats.day)25 message_user(self, request, "Daily stats", queryset.count())26 update_summary.short_description = "Update summary"27class UserPointsAdmin(admin.ModelAdmin):28 list_display = ('user', 'points', 'badges')29 ordering = '-points',30 actions = ['update_summary']31 def update_summary(self, request, queryset):32 for user_points in queryset:33 user_points.update_points()34 message_user(self, request, "User points", queryset.count())35 update_summary.short_description = "Update summary"36admin.site.register(UserCourseSummary, UserCourseSummaryAdmin)37admin.site.register(CourseDailyStats, CourseDailyStatsAdmin)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!