def post_deleted(instance, **kwargs): Profile = util.get_pybb_profile_model() User = compat.get_user_model() try: profile = util.get_pybb_profile(instance.user) except (Profile.DoesNotExist, User.DoesNotExist) as e: #When we cascade delete an user, profile and posts are also deleted pass else: profile.post_count = instance.user.posts.count() profile.save()
def user_saved(instance, created, **kwargs): if not created: return try: add_post_permission = Permission.objects.get_by_natural_key('add_post', 'pybb', 'post') add_topic_permission = Permission.objects.get_by_natural_key('add_topic', 'pybb', 'topic') except (Permission.DoesNotExist, ContentType.DoesNotExist): return instance.user_permissions.add(add_post_permission, add_topic_permission) instance.save() if get_pybb_profile_model() == Profile: Profile(user=instance).save()
def user_saved(instance, created, **kwargs): if not created: return try: add_post_permission = Permission.objects.get_by_natural_key("add_post", "pybb", "post") add_topic_permission = Permission.objects.get_by_natural_key("add_topic", "pybb", "topic") except Permission.DoesNotExist: return instance.user_permissions.add(add_post_permission, add_topic_permission) instance.save() if get_pybb_profile_model() == Profile: Profile(user=instance).save()
def user_saved(instance, created, **kwargs): if not created: return try: add_post_permission = Permission.objects.get_by_natural_key('add_post', 'pybb', 'post') add_topic_permission = Permission.objects.get_by_natural_key('add_topic', 'pybb', 'topic') except (Permission.DoesNotExist, ContentType.DoesNotExist): return instance.user_permissions.add(add_post_permission, add_topic_permission) instance.save() if defaults.PYBB_PROFILE_RELATED_NAME: ModelProfile = util.get_pybb_profile_model() profile = ModelProfile() setattr(instance, defaults.PYBB_PROFILE_RELATED_NAME, profile) profile.save()
class Meta(object): model = util.get_pybb_profile_model() fields = ['signature', 'time_zone', 'language', 'show_signatures', 'avatar']
class AttachmentAdmin(admin.ModelAdmin): list_display = ['file', 'size', 'admin_view_post', 'admin_edit_post'] def admin_view_post(self, obj): return '<a href="%s">view</a>' % obj.post.get_absolute_url() admin_view_post.allow_tags = True admin_view_post.short_description = _('View post') def admin_edit_post(self, obj): return '<a href="%s">edit</a>' % reverse('admin:pybb_post_change', args=[obj.post.pk]) admin_edit_post.allow_tags = True admin_edit_post.short_description = _('Edit post') admin.site.register(Category, CategoryAdmin) admin.site.register(Forum, ForumAdmin) admin.site.register(Topic, TopicAdmin) admin.site.register(Post, PostAdmin) admin.site.register(Attachment, AttachmentAdmin) if util.get_pybb_profile_model() == Profile: admin.site.register(Profile, ProfileAdmin) # This can be used to debug read/unread trackers #admin.site.register(TopicReadTracker, TopicReadTrackerAdmin) #admin.site.register(ForumReadTracker, ForumReadTrackerAdmin)
def pybb_get_profile(*args, **kwargs): try: return util.get_pybb_profile(kwargs.get('user') or args[0]) except: return util.get_pybb_profile_model().objects.none()
), ) class AttachmentAdmin(admin.ModelAdmin): list_display = ['file', 'size', 'admin_view_post', 'admin_edit_post'] def admin_view_post(self, obj): return '<a href="%s">view</a>' % obj.post.get_absolute_url() admin_view_post.allow_tags = True admin_view_post.short_description = _('View post') def admin_edit_post(self, obj): return '<a href="%s">edit</a>' % reverse('admin:pybb_post_change', args=[obj.post.pk]) admin_edit_post.allow_tags = True admin_edit_post.short_description = _('Edit post') admin.site.register(Category, CategoryAdmin) admin.site.register(Forum, ForumAdmin) admin.site.register(Topic, TopicAdmin) admin.site.register(Post, PostAdmin) admin.site.register(Attachment, AttachmentAdmin) if util.get_pybb_profile_model() == Profile: admin.site.register(Profile, ProfileAdmin) # This can be used to debug read/unread trackers #admin.site.register(TopicReadTracker, TopicReadTrackerAdmin) #admin.site.register(ForumReadTracker, ForumReadTrackerAdmin)
def get_results(self, request, term, page, context): username_field = get_username_field() lookup = {'user__{}__icontains'.format(username_field): term} results = get_pybb_profile_model().objects.filter(**lookup)\ .values_list('user__id', 'user__{}'.format(username_field)) return ('nil', False, results)