def get_noticeapp_profile_model(): from noticeapp import defaults if defaults.PYBB_PROFILE_RELATED_NAME: return getattr(get_user_model(), defaults.PYBB_PROFILE_RELATED_NAME).related.model else: return get_user_model()
def handle(self, *args, **kwargs): if len(args) != 2: raise CommandError("Enter action {add|del} and username") action, username = args assert action in ('add', 'del') user = compat.get_user_model().objects.get(**{compat.get_username_field(): username}) notices = Notice.objects.all() for notice in notices: notice.moderators.remove(user) if action == 'add': notice.moderators.add(user)
def get_noticeapp_profile(user): from noticeapp import defaults if not user.is_authenticated(): if defaults.PYBB_ENABLE_ANONYMOUS_POST: user = get_user_model().objects.get(**{get_username_field(): defaults.PYBB_ANONYMOUS_USERNAME}) else: raise ValueError(_('Can\'t get profile for anonymous user')) if defaults.PYBB_PROFILE_RELATED_NAME: return getattr(user, defaults.PYBB_PROFILE_RELATED_NAME) else: return user
def get_noticeapp_profile(user): from noticeapp import defaults if not user.is_authenticated(): if defaults.PYBB_ENABLE_ANONYMOUS_POST: user = get_user_model().objects.get( **{get_username_field(): defaults.PYBB_ANONYMOUS_USERNAME}) else: raise ValueError(_('Can\'t get profile for anonymous user')) if defaults.PYBB_PROFILE_RELATED_NAME: return getattr(user, defaults.PYBB_PROFILE_RELATED_NAME) else: return user
from __future__ import unicode_literals import re import inspect from django import forms from django.core.exceptions import FieldError from django.forms.models import inlineformset_factory, BaseInlineFormSet from django.utils.translation import ugettext, ugettext_lazy from django.utils.timezone import now as tznow from noticeapp import compat, defaults, util from noticeapp.models import Course, Post, Attachment, PollAnswer User = compat.get_user_model() username_field = compat.get_username_field() class AttachmentForm(forms.ModelForm): class Meta(object): model = Attachment fields = ('file', ) def clean_file(self): if self.cleaned_data['file'].size > defaults.PYBB_ATTACHMENT_SIZE_LIMIT: raise forms.ValidationError(ugettext('Attachment is too big')) return self.cleaned_data['file'] AttachmentFormSet = inlineformset_factory(Post, Attachment, extra=1, form=AttachmentForm)
def setup(): post_save.connect(post_saved, sender=Post) post_delete.connect(post_deleted, sender=Post) if defaults.PYBB_AUTO_USER_PERMISSIONS: post_save.connect(user_saved, sender=compat.get_user_model())