示例#1
0
文件: signals.py 项目: ugoertz/pybbm
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()
示例#2
0
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()
示例#3
0
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()
示例#4
0
文件: models.py 项目: eculver/pybbm
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()
示例#5
0
文件: signals.py 项目: ugoertz/pybbm
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()
示例#6
0
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()
示例#7
0
文件: forms.py 项目: victorx98/pybbm
 class Meta(object):
     model = util.get_pybb_profile_model()
     fields = ['signature', 'time_zone', 'language', 'show_signatures', 'avatar']
示例#8
0
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)
示例#9
0
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()
示例#10
0
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()
示例#11
0
         ),
        )


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)
示例#12
0
 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)
示例#13
0
 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)