Пример #1
0
class PHPListForm(SaaSPasswordForm):
    admin_username = forms.CharField(label=_("Admin username"),
                                     required=False,
                                     widget=SpanWidget(display='admin'))
    database = forms.CharField(
        label=_("Database"),
        required=False,
        help_text=_("Database dedicated to this phpList instance."),
        widget=SpanWidget(display=settings.SAAS_PHPLIST_DB_NAME.replace(
            '%(', '<').replace(')s', '>')))
    mailbox = forms.CharField(
        label=_("Bounces mailbox"),
        required=False,
        help_text=_("Dedicated mailbox used for reciving bounces."),
        widget=SpanWidget(
            display=settings.SAAS_PHPLIST_BOUNCES_MAILBOX_NAME.replace(
                '%(', '<').replace(')s', '>')))

    def __init__(self, *args, **kwargs):
        super(PHPListForm, self).__init__(*args, **kwargs)
        self.fields['name'].label = _("Site name")
        context = {
            'site_name': '<site_name>',
            'name': '<site_name>',
        }
        domain = self.plugin.site_domain % context
        help_text = _("Admin URL http://{}/admin/").format(domain)
        self.fields['site_url'].help_text = help_text
        validator = validators.MaxLengthValidator(
            settings.SAAS_PHPLIST_NAME_MAX_LENGTH)
        self.fields['name'].validators.append(validator)
Пример #2
0
 def __init__(self, *args, **kwargs):
     super(PHPListChangeForm, self).__init__(*args, **kwargs)
     site_domain = self.instance.get_site_domain()
     admin_url = "http://%s/admin/" % site_domain
     help_text = _("Admin URL <a href={0}>{0}</a>").format(admin_url)
     self.fields['site_url'].help_text = help_text
     # DB link
     db = self.instance.database
     db_url = reverse('admin:databases_database_change', args=(db.pk, ))
     db_link = mark_safe('<a href="%s">%s</a>' % (db_url, db.name))
     self.fields['database'].widget = SpanWidget(original=db.name,
                                                 display=db_link)
     # Mailbox link
     mailbox_id = self.instance.data.get('mailbox_id')
     if mailbox_id:
         try:
             mailbox = Mailbox.objects.get(id=mailbox_id)
         except Mailbox.DoesNotExist:
             pass
         else:
             mailbox_url = reverse('admin:mailboxes_mailbox_change',
                                   args=(mailbox.pk, ))
             mailbox_link = mark_safe('<a href="%s">%s</a>' %
                                      (mailbox_url, mailbox.name))
             self.fields['mailbox'].widget = SpanWidget(
                 original=mailbox.name, display=mailbox_link)
Пример #3
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     initial = kwargs.get('initial')
     if 'to' in initial:
         self.fields['to'].widget = SpanWidget(original=initial['to'])
     else:
         self.fields.pop('to')
Пример #4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     if self.instance:
         for field in self.declared_fields:
             initial = self.fields[field].initial
             self.fields[field].initial = self.instance.data.get(
                 field, initial)
         if self.instance.pk:
             # Admin Readonly fields are not availeble in self.fields, so we use Meta
             plugin = getattr(self.instance, '%s_class' % self.plugin_field)
             plugin_help_text = getattr(plugin, 'help_text', '')
             model_help_text = self.instance._meta.get_field(
                 self.plugin_field).help_text
             self._meta.help_texts = {
                 self.plugin_field: plugin_help_text or model_help_text
             }
             for field in self.plugin.get_change_readonly_fields():
                 value = getattr(self.instance, field,
                                 None) or self.instance.data.get(field)
                 display = value
                 foo_display = getattr(self.instance,
                                       'get_%s_display' % field, None)
                 if foo_display:
                     display = foo_display()
                 self.fields[field].required = False
                 self.fields[field].widget = SpanWidget(original=value,
                                                        display=display)
Пример #5
0
 def __init__(self, *args, **kwargs):
     super(RouteForm, self).__init__(*args, **kwargs)
     if self.instance:
         self.fields['backend'].required = False
         try:
             backend_class = self.instance.backend_class
         except KeyError:
             self.fields['backend'].widget = SpanWidget(
                 display='<span style="color:red">%s NOT AVAILABLE</span>' %
                 self.instance.backend)
         else:
             self.fields['backend'].widget = SpanWidget()
             actions = backend_class.actions
             self.fields[
                 'async_actions'].widget = paddingCheckboxSelectMultiple(45)
             self.fields['async_actions'].choices = ((action, action)
                                                     for action in actions)
Пример #6
0
 def __init__(self, *args, **kwargs):
     super(PluginForm, self).__init__(*args, **kwargs)
     if self.plugin_field in self.fields:
         # Provide a link to the related DB object change view
         value = self.plugin.related_instance.pk
         link = admin_link()(self.plugin.related_instance)
         display = '%s <a href=".">change</a>' % link
         self.fields[self.plugin_field].widget = SpanWidget(original=value,
                                                            display=display)
         help_text = self.fields[self.plugin_field].help_text
Пример #7
0
 def __init__(self, *args, **kwargs):
     super(CMSAppForm, self).__init__(*args, **kwargs)
     if self.instance:
         data = self.instance.data
         # DB link
         db_name = data.get('db_name')
         db_id = data.get('db_id')
         db_url = reverse('admin:databases_database_change', args=(db_id, ))
         db_link = mark_safe('<a href="%s">%s</a>' % (db_url, db_name))
         self.fields['db_name'].widget = SpanWidget(original=db_name,
                                                    display=db_link)
         # DB user link
         db_user = data.get('db_user')
         db_user_id = data.get('db_user_id')
         db_user_url = reverse('admin:databases_databaseuser_change',
                               args=(db_user_id, ))
         db_user_link = mark_safe('<a href="%s">%s</a>' %
                                  (db_user_url, db_user))
         self.fields['db_user'].widget = SpanWidget(original=db_user,
                                                    display=db_user_link)
Пример #8
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     if self.plugin_field in self.fields:
         value = self.plugin.get_name()
         display = '%s <a href=".">change</a>' % force_text(
             self.plugin.verbose_name)
         self.fields[self.plugin_field].widget = SpanWidget(original=value,
                                                            display=display)
         help_text = self.fields[self.plugin_field].help_text
         self.fields[self.plugin_field].help_text = getattr(
             self.plugin, 'help_text', help_text)
Пример #9
0
class SaaSPasswordForm(SaaSBaseForm):
    password = forms.CharField(
        label=_("Password"),
        required=False,
        widget=SpanWidget(display='<strong>Unknown password</strong>'),
        validators=[
            validators.validate_password,
            RegexValidator(
                r'^[^"\'\\]+$',
                _('Enter a valid password. '
                  'This value may contain any ascii character except for '
                  ' \'/"/\\/ characters.'), 'invalid'),
        ],
        help_text=_(
            "Passwords are not stored, so there is no way to see this "
            "service's password, but you can change the password using "
            "<a href=\"../password/\">this form</a>."))
    password1 = forms.CharField(
        label=_("Password"),
        widget=forms.PasswordInput(attrs={'autocomplete': 'off'}),
        validators=[validators.validate_password])
    password2 = forms.CharField(
        label=_("Password confirmation"),
        widget=forms.PasswordInput,
        help_text=_("Enter the same password as above, for verification."))

    def __init__(self, *args, **kwargs):
        super(SaaSPasswordForm, self).__init__(*args, **kwargs)
        if self.is_change:
            self.fields['password1'].required = False
            self.fields['password1'].widget = forms.HiddenInput()
            self.fields['password2'].required = False
            self.fields['password2'].widget = forms.HiddenInput()
        else:
            self.fields['password'].widget = forms.HiddenInput()
            self.fields['password1'].help_text = _(
                "Suggestion: %s") % random_ascii(10)

    def clean_password2(self):
        if not self.is_change:
            password1 = self.cleaned_data.get("password1")
            password2 = self.cleaned_data.get("password2")
            if password1 and password2 and password1 != password2:
                msg = _("The two password fields didn't match.")
                raise forms.ValidationError(msg)
            return password2

    def save(self, commit=True):
        obj = super(SaaSPasswordForm, self).save(commit=commit)
        if not self.is_change:
            obj.set_password(self.cleaned_data["password1"])
        return obj
Пример #10
0
 def __init__(self, *args, **kwargs):
     self.resource = kwargs.pop('resource', None)
     if self.resource:
         initial = kwargs.get('initial', {})
         initial.update({
             'verbose_name': self.resource.get_verbose_name(),
             'unit': self.resource.unit,
         })
         kwargs['initial'] = initial
     super(ResourceForm, self).__init__(*args, **kwargs)
     if self.resource:
         if self.resource.on_demand:
             self.fields['allocated'].required = False
             self.fields['allocated'].widget = SpanWidget(original=None,
                                                          display='')
         else:
             self.fields['allocated'].required = True
             self.fields[
                 'allocated'].initial = self.resource.default_allocation
Пример #11
0
class SaaSBaseForm(PluginDataForm):
    site_url = forms.CharField(label=_("Site URL"),
                               widget=SpanWidget(),
                               required=False)

    class Meta:
        exclude = ('database', )
        readonly_fields = ('site_url', )

    def __init__(self, *args, **kwargs):
        super(SaaSBaseForm, self).__init__(*args, **kwargs)
        self.is_change = bool(self.instance and self.instance.pk)
        if self.is_change:
            site_domain = self.instance.get_site_domain()
            if self.instance.custom_url:
                try:
                    website = self.instance.service_instance.get_website()
                except ObjectDoesNotExist:
                    link = (
                        '<br><span style="color:red"><b>Warning:</b> '
                        'Related website directive does not exist for %s URL !</span>'
                        % self.instance.custom_url)
                else:
                    url = change_url(website)
                    link = '<br>Related website: <a href="%s">%s</a>' % (
                        url, website.name)
                self.fields['custom_url'].help_text += link
        else:
            site_domain = self.plugin.site_domain
        context = {
            'site_name': '&lt;site_name&gt;',
            'name': '&lt;site_name&gt;',
        }
        site_domain = site_domain % context
        if '&lt;site_name&gt;' in site_domain:
            site_link = site_domain
        else:
            site_link = '<a href="http://%s">%s</a>' % (site_domain,
                                                        site_domain)
        self.fields['site_url'].widget.display = site_link
        self.fields['name'].label = _(
            "Site name") if '%(' in self.plugin.site_domain else _("Username")
Пример #12
0
 def __init__(self, *args, **kwargs):
     super(TicketForm, self).__init__(*args, **kwargs)
     ticket = kwargs.get('instance', False)
     users = self.fields['owner'].queryset
     self.fields['owner'].queryset = users.filter(is_superuser=True)
     if not ticket:
         # Provide default ticket queue for new ticket
         try:
             self.initial['queue'] = Queue.objects.get(default=True).id
         except Queue.DoesNotExist:
             pass
     else:
         description = markdown(ticket.description)
         # some hacks for better line breaking
         description = description.replace('>\n', '#Ha9G9-?8')
         description = description.replace('\n', '<br>')
         description = description.replace('#Ha9G9-?8', '>\n')
         description = '<div style="padding-left: 95px;">%s</div>' % description
         widget = SpanWidget(display=description)
         self.fields['display_description'].widget = widget
Пример #13
0
class ResourceForm(ReadOnlyFormMixin, forms.ModelForm):
    verbose_name = forms.CharField(label=_("Name"),
                                   required=False,
                                   widget=SpanWidget(tag='<b>'))
    allocated = forms.DecimalField(label=_("Allocated"))
    unit = forms.CharField(label=_("Unit"), required=False)

    class Meta:
        fields = ('verbose_name', 'used', 'last_update', 'allocated', 'unit')
        readonly_fields = ('verbose_name', 'unit')

    def __init__(self, *args, **kwargs):
        self.resource = kwargs.pop('resource', None)
        if self.resource:
            initial = kwargs.get('initial', {})
            initial.update({
                'verbose_name': self.resource.get_verbose_name(),
                'unit': self.resource.unit,
            })
            kwargs['initial'] = initial
        super(ResourceForm, self).__init__(*args, **kwargs)
        if self.resource:
            if self.resource.on_demand:
                self.fields['allocated'].required = False
                self.fields['allocated'].widget = SpanWidget(original=None,
                                                             display='')
            else:
                self.fields['allocated'].required = True
                self.fields[
                    'allocated'].initial = self.resource.default_allocation

#    def has_changed(self):
#        """ Make sure resourcedata objects are created for all resources """
#        if not self.instance.pk:
#            return True
#        return super(ResourceForm, self).has_changed()

    def save(self, *args, **kwargs):
        self.instance.resource_id = self.resource.pk
        return super(ResourceForm, self).save(*args, **kwargs)
Пример #14
0
 def __init__(self, *args, **kwargs):
     super(MessageInlineForm, self).__init__(*args, **kwargs)
     self.fields['created_on'].widget = SpanWidget(display='')
Пример #15
0
class MoodleForm(SaaSPasswordForm):
    admin_username = forms.CharField(label=_("Admin username"),
                                     required=False,
                                     widget=SpanWidget(display='admin'))