class UserSettingsForm(BaseBooktypeForm, forms.ModelForm): email = forms.EmailField(label=_('Email')) first_name = forms.CharField( label=_('Full name'), required=False ) # profile fields aboutyourself = forms.CharField( label=_('About yourself'), widget=forms.Textarea(attrs={'rows': '20', 'cols': '40'}), required=False ) profile_pic = forms.FileField( label=_('Profile image'), required=False, widget=RemovableImageWidget(attrs={ 'label_class': 'checkbox-inline', 'input_class': 'group-image-removable' }) ) notification = forms.CharField( label=_('Notification filter'), required=False ) class Meta: model = User fields = ['email', 'first_name']
class EditPersonInfoForm(BaseControlForm, forms.ModelForm): username = forms.CharField( label=_('Username'), required=True, max_length=100, error_messages={ 'required': _('Username is required.'), 'ivalid': _("Illegal characters in username.") }, validators=[ RegexValidator(r"^[\w\d\@\.\+\-\_]+$", message=_("Illegal characters in username.")), MinLengthValidator(3) ]) first_name = forms.CharField( label=_('Full name'), required=True, error_messages={'required': _('Full name is required.')}, max_length=32) email = forms.EmailField( label=_('Email'), required=True, error_messages={'required': _('Email is required.')}, max_length=100) profile = forms.ImageField(label=_('Profile picture'), required=False, widget=RemovableImageWidget( attrs={ 'label_class': 'checkbox-inline', 'input_class': 'group-image-removable' })) description = forms.CharField(label=_("User description"), required=False, widget=forms.Textarea) is_superuser = forms.BooleanField(label=_("This person is a superuser"), required=False) is_active = forms.BooleanField( label=_("Active account"), required=False, help_text=_("Indicate whether user's account is archived or active.")) def __init__(self, *args, **kwargs): super(EditPersonInfoForm, self).__init__(*args, **kwargs) self.fields.keyOrder = [ 'username', 'first_name', 'email', 'description', 'is_superuser' ] class Meta: model = User exclude = [ 'password', 'last_login', 'groups', 'user_permissions', 'date_joined', 'is_staff', 'last_name' ] def get_cancel_url(self): return "{0}#list-of-people".format(self.cancel_url)
class FrontpageForm(BaseControlForm, forms.Form): description = forms.CharField(label=_('Welcome message'), required=False, widget=forms.Textarea(attrs={ 'rows': 20, 'cols': 40 })) show_changes = forms.BooleanField(label=_('Show activity'), required=False) use_anonymous_page = forms.BooleanField( label=_('Use anonymous page'), required=False, help_text=_('Use separate page for anonymous users without books, ' 'people, groups and recent activity blocks.')) anonymous_message = forms.CharField( label=_('Anonymous page message'), required=False, widget=forms.Textarea(attrs={ 'rows': 8, 'cols': 40 }), help_text=_('Message for displaying on anonymous page.')) anonymous_email = forms.EmailField( label=_('Anonymous page email'), required=False, help_text=_('Email for displaying on anonymous page.')) anonymous_image = forms.ImageField( label=_("Anonymous page image"), required=False, help_text=_("Use image/png files."), widget=RemovableImageWidget( attrs={ 'label_class': 'checkbox-inline', 'input_class': 'group-image-removable' })) def clean_anonymous_image(self): data = self.cleaned_data['anonymous_image'] if data and data.content_type not in ['image/png']: raise forms.ValidationError("Wrong file content type.") return data @classmethod def initial_data(cls): _dict = {} try: f = open( '%s/templates/portal/welcome_message.html' % settings.BOOKTYPE_ROOT, 'r') _dict['description'] = unicode(f.read(), 'utf8') f.close() except IOError: _dict['description'] = '' _dict['show_changes'] = config.get_configuration( 'BOOKTYPE_FRONTPAGE_HISTORY', True) _dict['use_anonymous_page'] = config.get_configuration( 'BOOKTYPE_FRONTPAGE_USE_ANONYMOUS_PAGE') _dict['anonymous_message'] = config.get_configuration( 'BOOKTYPE_FRONTPAGE_ANONYMOUS_MESSAGE') _dict['anonymous_email'] = config.get_configuration( 'BOOKTYPE_FRONTPAGE_ANONYMOUS_EMAIL') _dict['anonymous_image'] = config.get_configuration( 'BOOKTYPE_FRONTPAGE_ANONYMOUS_IMAGE') return _dict def save_settings(self, request): static_root = settings.BOOKTYPE_ROOT config.set_configuration('BOOKTYPE_FRONTPAGE_HISTORY', self.cleaned_data['show_changes']) config.set_configuration('BOOKTYPE_FRONTPAGE_USE_ANONYMOUS_PAGE', self.cleaned_data['use_anonymous_page']) config.set_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_MESSAGE', self.cleaned_data['anonymous_message']) config.set_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_EMAIL', self.cleaned_data['anonymous_email']) # anonymous page image destination_filename = 'anonymous_image.png' destination_dir = '{0}/portal/frontpage/'.format(settings.MEDIA_ROOT) destination_file_path = '{dir}{filename}'.format( dir=destination_dir, filename=destination_filename) if 'anonymous_image_remove' in request.POST: os.remove(destination_file_path) config.del_configuration('BOOKTYPE_FRONTPAGE_ANONYMOUS_IMAGE') elif 'anonymous_image' in self.files: try: fh, fname = misc.save_uploaded_as_file( self.files['anonymous_image']) if not os.path.exists(destination_dir): os.makedirs(destination_dir) shutil.move(fname, destination_file_path) config.set_configuration( 'BOOKTYPE_FRONTPAGE_ANONYMOUS_IMAGE', '{0}portal/frontpage/anonymous_image.png'.format( settings.MEDIA_URL)) except: pass # welcome message if not os.path.exists('%s/templates/portal/' % static_root): os.makedirs('%s/templates/portal/' % static_root) try: f = open('%s/templates/portal/welcome_message.html' % static_root, 'w') text_data = self.cleaned_data.get('description', '') for ch in ['{%', '%}', '{{', '}}']: text_data = text_data.replace(ch, '') f.write(text_data.encode('utf8')) f.close() config.save_configuration() except IOError as err: raise err except config.ConfigurationError as err: raise err