Esempio n. 1
0
class RepositoryForm(forms.Form):
    location = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'text-wide'}), )
    enable_polling = forms.BooleanField(
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'checkbox'}),
    )
    forward_pinger_mail = forms.BooleanField(
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'checkbox'}),
    )
    poll_frequency = forms.IntegerField(
        widget=forms.TextInput(attrs={'class': 'text'}), )
    revision_url = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'class': 'text-wide'}),
    )
    path_regexes = forms.CharField(
        required=False,
        widget=forms.Textarea,
    )

    def clean_location(self):
        # On success, this will set up internal state in the
        # model but *not* set the location itself. That will
        # be done during apply(), so that it's included in
        # the changeset.

        location = self.cleaned_data['location']
        # XXX - Bear hack: Unconditionally probe, so if we reactivated
        # the repository we don't pull all revisions since way back when.
        # Also makes sure the location is still valid.
        #if location != self.data.model.location:
        if location:  # shouldn't be neccessary, required = True
            self.data.model.get_client().probe(location)
        return location

    def clean_revision_url(self):
        return self.cleaned_data.get('revision_url') or None

    def clean_path_regexes(self):
        # Remove extra whitespace and blank lines, then parse the resulting regexes.
        regexes = []
        line_no = 1
        for line in self.cleaned_data.get('path_regexes', '').split('\n'):
            line = line.strip()
            if line:
                try:
                    re.compile(line, re.VERBOSE)
                except re.error, e:
                    raise forms.ValidationError("Syntax error on line %d: %s" %
                                                (line_no, e))
                regexes.append(line)
            line_no += 1
        if regexes:
            return '\n'.join(regexes)
Esempio n. 2
0
class EditPostForm(forms.Form):
    title = forms.CharField()
    listed = forms.BooleanField(
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'checkbox'}),
    )
    content = forms.CharField(widget=forms.Textarea, )
Esempio n. 3
0
class ProjectForm(forms.Form):
    use_repository = forms.BooleanField(
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'checkbox'}),
    )

    def apply(self, cset, request, repos):
        use_repository = bool(self.cleaned_data.get('use_repository'))
        if cset.asset.repos and cset.asset.repos.is_active and not use_repository:
            # Deactivate repository

            cset.set_field('repos.is_active', False)

        elif use_repository:
            # Activate repository, using either the asset's existing
            # repository or a temporary repository we created before
            # we knew it would definitely be needed.

            if repos.id is None:
                repos.save()
            cset.set_field('repos', repos, quiet=True)
            cset.set_field('repos.is_active', True)

            # If we're activating an old repository, re-probe() it.
            # This will make sure the server still exists, but more
            # importantly it will update our latest-rev. Otherwise,
            # we'll soon start downloading all the revisions we missed
            # while the repository was inactive!
            #
            # Note that probe() does not explicitly save() the
            # repository, but these changes will be saved automatically
            # by our changeset since we touched repos.is_active.

            if repos.location:
                repos.get_client().probe()
Esempio n. 4
0
    def __init__(self, *args, **kwargs):
        products = kwargs.pop('products', None)

        super(ProductExportForm, self).__init__(*args, **kwargs)

        self.fields['format'] = forms.ChoiceField(label=_('export format'),
                                                  choices=export_choices(),
                                                  required=True)
        self.fields['include_images'] = forms.BooleanField(
            label=_('Include Images'), initial=True, required=False)

        if not products:
            products = Product.objects.all().order_by('slug')

        for product in products:
            subtypes = product.get_subtypes()
            expclasses = ('export', ) + subtypes
            extclasses = " ".join(expclasses)

            kw = {
                'label': product.slug,
                'help_text': product.name,
                'initial': False,
                'required': False,
                'widget': forms.CheckboxInput(attrs={'class': extclasses})
            }

            chk = forms.BooleanField(**kw)
            chk.slug = product.slug
            chk.product_id = product.id
            chk.subtypes = " ".join(subtypes)
            self.fields['export__%s' % product.slug] = chk
Esempio n. 5
0
    def __init__(self, *args, **kwargs):
        products = kwargs.pop('products', None)

        super(InventoryForm, self).__init__(*args, **kwargs)

        if not products:
            products = Product.objects.all().order_by('slug')

        for product in products:
            subtypes = product.get_subtypes()
            qtyclasses = ('text', 'qty') + subtypes
            qtyclasses = " ".join(qtyclasses)

            kw = {
                'label': product.slug,
                'help_text': product.name,
                'initial': product.items_in_stock,
                'widget': forms.TextInput(attrs={'class': qtyclasses})
            }

            qty = forms.IntegerField(**kw)
            self.fields['qty__%s' % product.slug] = qty
            qty.slug = product.slug
            qty.product_id = product.id
            qty.subtypes = " ".join(subtypes)

            kw['initial'] = product.unit_price
            kw['required'] = False
            kw['widget'] = forms.TextInput(attrs={'class': "text price"})
            price = forms.DecimalField(**kw)
            price.slug = product.slug
            self.fields['price__%s' % product.slug] = price

            kw['initial'] = product.active
            kw['widget'] = forms.CheckboxInput(
                attrs={'class': "checkbox active"})
            active = forms.BooleanField(**kw)
            active.slug = product.slug
            self.fields['active__%s' % product.slug] = active

            kw['initial'] = product.featured
            kw['widget'] = forms.CheckboxInput(
                attrs={'class': "checkbox featured"})
            featured = forms.BooleanField(**kw)
            featured.slug = product.slug
            self.fields['featured__%s' % product.slug] = featured
Esempio n. 6
0
class EditBotForm(forms.Form):
    filter_mode = forms.ChoiceField(
        choices = models.filter_mode_choices,
        widget = forms.RadioSelect,
        )
    project_list = forms.CharField(
        required = False,
        widget = forms.Textarea,
        )
    show_project_names = forms.BooleanField(
        required = False,
        widget = forms.CheckboxInput(attrs = {'class': 'checkbox'}),
        )

    def __init__(self, data=None):
        forms.Form.__init__(self, data)
        self.filter_modes = formtools.RadioChoices(self['filter_mode'], models.FILTER)

    def clean_filter_mode(self):
        return int(self.cleaned_data['filter_mode'])

    def clean_project_list(self):
        # Remove extra whitespace, split into individual projects.
        projects = []
        for line in self.cleaned_data['project_list'].split('\n'):
            line = line.strip()
            if line:
                projects.append(line)

        # Is the project list required?
        if int(self.data['filter_mode']) == models.FILTER.PROJECT_LIST and not projects:
            raise forms.ValidationError("Please enter at least one project.")

        return '\n'.join(projects)

    custom_ruleset = forms.CharField(
        required = False,
        widget = forms.Textarea,
        )

    def clean_custom_ruleset(self):
        # Empty rulesets are okay if we aren't using them. We never
        # allow a ruleset to be stored if it isn't well-formed and
        # valid.
        allow_empty = int(self.data['filter_mode']) != models.FILTER.CUSTOM

        # Use LibCIA to validate the ruleset. It would be nice to
        # hilight errors, or even interactively validate rulesets on
        # the client side.. but this is sufficient for now.
        return models.validate_ruleset(self.cleaned_data['custom_ruleset'], allow_empty)

    def apply(self, cset):
        cset.set_field_dict(self.cleaned_data)
        cset.asset.syncToServer()
Esempio n. 7
0
class RegistrationForm(forms.Form):
    """The basic account registration form."""
    email = forms.EmailField(label=_('Email address'),
                             max_length=30,
                             required=True)
    password2 = forms.CharField(label=_('Password (again)'),
                                max_length=30,
                                widget=forms.PasswordInput(),
                                required=True)
    password = forms.CharField(label=_('Password'),
                               max_length=30,
                               widget=forms.PasswordInput(),
                               required=True)
    first_name = forms.CharField(label=_('First name'),
                                 max_length=30,
                                 required=True)
    last_name = forms.CharField(label=_('Last name'),
                                max_length=30,
                                required=True)
    newsletter = forms.BooleanField(label=_('Newsletter'),
                                    widget=forms.CheckboxInput(),
                                    required=False)

    def clean_password(self):
        """Enforce that password and password2 are the same."""
        p1 = self.cleaned_data.get('password')
        p2 = self.cleaned_data.get('password2')
        if not (p1 and p2 and p1 == p2):
            raise forms.ValidationError(
                ugettext("The two passwords do not match."))

        # note, here is where we'd put some kind of custom validator to enforce "hard" passwords.
        return p1

    def clean_email(self):
        """Prevent account hijacking by disallowing duplicate emails."""
        email = self.cleaned_data.get('email', None)
        if email and User.objects.filter(email=email).count() > 0:
            raise forms.ValidationError(
                ugettext("That email address is already in use."))

        return email
Esempio n. 8
0
class ProjectForm(forms.Form):
    use_repository = forms.BooleanField(
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'checkbox'}),
    )

    def apply(self, cset, request, repos):
        use_repository = bool(self.cleaned_data.get('use_repository'))
        if cset.asset.repos and cset.asset.repos.is_active and not use_repository:
            # Deactivate repository

            cset.set_field('repos.is_active', False)

        elif use_repository:
            # Activate repository, using either the asset's existing
            # repository or a temporary repository we created before
            # we knew it would definitely be needed.

            if repos.id is None:
                repos.save()
            cset.set_field('repos', repos, quiet=True)
            cset.set_field('repos.is_active', True)
Esempio n. 9
0
class ExtendedContactInfoForm(ContactInfoForm):
    """Contact form which includes birthday and newsletter."""
    dob = forms.DateField(required=False)
    newsletter = forms.BooleanField(label=_('Newsletter'), widget=forms.CheckboxInput(), required=False)