Ejemplo n.º 1
0
class LogEntryAdminForm(forms.ModelForm):
    user = al.ModelChoiceField("UserAutocomplete")
    content_type = al.ModelChoiceField("ContentTypeAutocomplete")

    class Meta:
        model = LogEntry
        exclude = ("user", "content_type")
Ejemplo n.º 2
0
class FOIAComposerAdminForm(forms.ModelForm):
    """Form for the FOIA composer admin"""

    user = autocomplete_light.ModelChoiceField(
        'UserAutocomplete',
        queryset=User.objects.all(),
    )
    organization = autocomplete_light.ModelChoiceField(
        'OrganizationAutocomplete',
        queryset=Organization.objects.all(),
    )
    agencies = autocomplete_light.ModelMultipleChoiceField(
        'AgencyAdminAutocomplete',
        queryset=Agency.objects.all(),
        required=False,
    )
    parent = autocomplete_light.ModelChoiceField(
        'FOIAComposerAdminAutocomplete',
        queryset=FOIAComposer.objects.all(),
        required=False,
    )

    class Meta:
        model = FOIAComposer
        fields = '__all__'
Ejemplo n.º 3
0
class FOIARequestAdminForm(forms.ModelForm):
    """Form to include custom choice fields"""

    jurisdiction = autocomplete_light.ModelChoiceField(
            'JurisdictionAdminAutocomplete',
            queryset=Jurisdiction.objects.all())
    agency = autocomplete_light.ModelChoiceField(
            'AgencyAdminAutocomplete',
            queryset=Agency.objects.all())
    user = autocomplete_light.ModelChoiceField(
            'UserAutocomplete',
            queryset=User.objects.all())
    parent = autocomplete_light.ModelChoiceField(
            'FOIARequestAdminAutocomplete',
            queryset=FOIARequest.objects.all(),
            required=False)
    read_collaborators = autocomplete_light.ModelMultipleChoiceField(
            'UserAutocomplete',
            queryset=User.objects.all(),
            required=False)
    edit_collaborators = autocomplete_light.ModelMultipleChoiceField(
            'UserAutocomplete',
            queryset=User.objects.all(),
            required=False)

    class Meta:
        # pylint: disable=too-few-public-methods
        model = FOIARequest
        fields = '__all__'
Ejemplo n.º 4
0
class AgencyMergeForm(forms.Form):
    """A form to merge two agencies"""

    good_agency = autocomplete_light.ModelChoiceField(
        'AgencyEasySearchAutocomplete',
        queryset=Agency.objects.get_approved(),
    )
    bad_agency = autocomplete_light.ModelChoiceField(
        'AgencyEasySearchAutocomplete',
        queryset=Agency.objects.get_approved(),
    )
    confirmed = forms.BooleanField(initial=False,
                                   widget=forms.HiddenInput(),
                                   required=False)

    def __init__(self, *args, **kwargs):
        confirmed = kwargs.pop('confirmed', False)
        super(AgencyMergeForm, self).__init__(*args, **kwargs)
        if confirmed:
            self.fields['confirmed'].initial = True
            self.fields['good_agency'].widget = forms.HiddenInput()
            self.fields['bad_agency'].widget = forms.HiddenInput()

    def clean(self, ):
        cleaned_data = super(AgencyMergeForm, self).clean()
        good_agency = cleaned_data.get('good_agency')
        bad_agency = cleaned_data.get('bad_agency')
        if good_agency and good_agency == bad_agency:
            raise forms.ValidationError('Cannot merge an agency into itself')
        return cleaned_data
Ejemplo n.º 5
0
class RequestForm(forms.Form):
    """This form creates new, single MuckRock requests"""

    JURISDICTION_CHOICES = [('f', 'Federal'), ('s', 'State'), ('l', 'Local')]

    title = forms.CharField(
        widget=forms.TextInput(attrs={'placeholder': 'Add a subject'}),
        max_length=255,
    )
    document_placeholder = (
        'Write one sentence describing what you\'re looking for. '
        'The more specific you can be, the better.')
    document = forms.CharField(widget=forms.Textarea(
        attrs={'placeholder': document_placeholder}))
    jurisdiction = forms.ChoiceField(choices=JURISDICTION_CHOICES,
                                     widget=forms.RadioSelect)
    state = autocomplete_light.ModelChoiceField(
        'StateAutocomplete',
        queryset=Jurisdiction.objects.filter(level='s', hidden=False),
        required=False)
    local = autocomplete_light.ModelChoiceField(
        'JurisdictionLocalAutocomplete', required=False)
    agency = forms.CharField(
        label='Agency',
        widget=autocomplete_light.TextWidget(
            'AgencySimpleAgencyAutocomplete',
            attrs={'placeholder': 'Type the agency\'s name'}),
        max_length=255)
    full_name = forms.CharField()
    email = forms.EmailField(max_length=75)

    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        super(RequestForm, self).__init__(*args, **kwargs)
        if self.request and self.request.user.is_authenticated():
            del self.fields['full_name']
            del self.fields['email']

    def clean(self):
        data = self.cleaned_data
        jurisdiction = data.get('jurisdiction')
        state = data.get('state')
        local = data.get('local')
        if jurisdiction == 's' and not state:
            error_msg = 'No state was selected.'
            self._errors['state'] = self.error_class([error_msg])
        if jurisdiction == 'l' and not local:
            error_msg = 'No locality was selected.'
            self._errors['local'] = self.error_class([error_msg])
        return self.cleaned_data

    def clean_email(self):
        """Do a case insensitive uniqueness check"""
        email = self.cleaned_data['email']
        if User.objects.filter(email__iexact=email):
            raise forms.ValidationError(
                "User with this email already exists.  Please login first.")
        return email
Ejemplo n.º 6
0
class FoiaMachineRequestAdminForm(forms.ModelForm):
    """Form to include custom choice fields"""
    jurisdiction = autocomplete_light.ModelChoiceField(
        'JurisdictionAdminAutocomplete')
    agency = autocomplete_light.ModelChoiceField('AgencyAdminAutocomplete')
    user = autocomplete_light.ModelChoiceField('UserAutocomplete')

    class Meta:
        model = models.FoiaMachineRequest
        fields = '__all__'
Ejemplo n.º 7
0
class QuestionForm(forms.ModelForm):
    """Form with autocomplete for user and foia"""
    user = autocomplete_light.ModelChoiceField('UserAutocomplete',
                                               queryset=User.objects.all())
    foia = autocomplete_light.ModelChoiceField('FOIARequestAdminAutocomplete',
                                               required=False)

    class Meta:
        model = Question
        fields = '__all__'
Ejemplo n.º 8
0
class ReplaceNewAgencyForm(forms.Form):
    """Form for rejecting and replacing a new agency"""
    replace_jurisdiction = autocomplete_light.ModelChoiceField(
        'JurisdictionAutocomplete',
        queryset=Jurisdiction.objects.all(),
    )
    replace_agency = autocomplete_light.ModelChoiceField(
        'AgencyAutocomplete',
        label='Move this agency\'s requests to:',
        queryset=Agency.objects.filter(status='approved'),
    )
Ejemplo n.º 9
0
class FOIACommunicationAdminForm(forms.ModelForm):
    """Form for comm inline"""

    from_user = autocomplete_light.ModelChoiceField(
        'UserAutocomplete',
        queryset=User.objects.all(),
    )
    to_user = autocomplete_light.ModelChoiceField(
        'UserAutocomplete',
        queryset=User.objects.all(),
    )

    class Meta:
        model = FOIACommunication
        fields = '__all__'
Ejemplo n.º 10
0
class OutboundAttachmentAdminForm(forms.ModelForm):
    """Form for outbound attachment admin"""

    foia = autocomplete_light.ModelChoiceField(
            'FOIARequestAdminAutocomplete',
            queryset=FOIARequest.objects.all(),
            )
    user = autocomplete_light.ModelChoiceField(
            'UserAutocomplete',
            queryset=User.objects.all(),
            )

    class Meta:
        model = OutboundAttachment
        fields = '__all__'
Ejemplo n.º 11
0
class ModuloSpostaPersoneManuale(ModuloSpostaPersone, forms.Form):
    sede = autocomplete_light.ModelChoiceField("SedeAutocompletamento")
    inizio_appartenenza = forms.DateField(
        label='Data di inizio appartenenza',
        widget=AdminDateWidget(format='%Y-%m-%d'))
    motivazione = forms.CharField()

    @property
    def media(self):
        extra = '' if settings.DEBUG else '.min'
        js = [
            'core.js',
            'vendor/jquery/jquery%s.js' % extra,
            'jquery.init.js',
            'admin/RelatedObjectLookups.js',
        ]
        return forms.Media(js=[static('admin/js/%s' % url)
                               for url in js]) + super(ModuloSpostaPersone,
                                                       self).media

    def mappa_persone(self, source):
        trasferimenti = []
        for persona in source.order_by('cognome', 'nome'):
            trasferimenti.append({
                'persona':
                persona,
                'sede':
                self.cleaned_data['sede'],
                'motivazione':
                self.cleaned_data['motivazione'],
                'inizio_appartenenza':
                self.cleaned_data['inizio_appartenenza']
            })
        return trasferimenti, []
Ejemplo n.º 12
0
class FormCreateDirettoreDelega(ModelForm):
    persona = autocomplete_light.ModelChoiceField(
        'CreateDirettoreDelegaAutocompletamento')
    has_nulla_osta = forms.BooleanField(
        label=
        'Responsabilità di aver ricevuto nulla osta dal presidente del comitato di appartenenza',
        initial=True)

    def clean(self):
        cd = self.cleaned_data
        corso = self.oggetto

        if corso.titolo_cri and corso.titolo_cri.cdf_livello != Titolo.CDF_LIVELLO_IV:
            if corso.direttori_corso().count() >= 1:
                self.add_error(
                    'persona',
                    'I corsi di questo livello possono avere uno ed un solo direttore'
                )

        return cd

    class Meta:
        model = Delega
        fields = [
            'persona',
            'has_nulla_osta',
        ]

    def __init__(self, *args, **kwargs):
        # These attrs are passed in anagrafica.viste.strumenti_delegati()
        for attr in ['me', 'oggetto']:
            if attr in kwargs:
                setattr(self, attr, kwargs.pop(attr))
        super().__init__(*args, **kwargs)
Ejemplo n.º 13
0
class DhcpDnsRecordForm(forms.ModelForm):
    domain = al.ModelChoiceField("DomainAutocomplete")
    host = forms.CharField()

    class Meta:
        model = DhcpDnsRecord
        fields = ("host", "domain", "ttl")
Ejemplo n.º 14
0
class InvokedExemptionAdminForm(forms.ModelForm):
    """Adds an autocomplete to the invoked exemption request field."""
    request = autocomplete_light.ModelChoiceField('FOIARequestAdminAutocomplete')

    class Meta:
        model = JurisdictionModels.InvokedExemption
        fields = '__all__'
Ejemplo n.º 15
0
class ProfileAdminForm(forms.ModelForm):
    """Form to include custom choice fields"""

    location = autocomplete_light.ModelChoiceField(
        'JurisdictionAdminAutocomplete',
        queryset=Jurisdiction.objects.all(),
        required=False,
    )
    agency = autocomplete_light.ModelChoiceField(
        'AgencyAdminAutocomplete',
        queryset=Agency.objects.filter(status='approved'),
        required=False,
    )

    class Meta:
        model = Profile
        fields = '__all__'
Ejemplo n.º 16
0
class AddressAdminForm(forms.ModelForm):
    host = al.ModelChoiceField("HostAutocomplete", required=False)

    # network = al.ModelChoiceField('NetworkAutocomplete')

    class Meta:
        model = Address
        exclude = ("changed_by", )
Ejemplo n.º 17
0
class ModuloImportPresidenti(forms.Form):
    nomina = forms.ChoiceField(
        widget=forms.Select(),
        choices=([
            ('Seleziona', ''),
            (PRESIDENTE, 'Presidente'),
            (COMMISSARIO, 'Commissario'),
            (CONSIGLIERE, 'Consigliere'),
            (CONSIGLIERE_GIOVANE, 'Consigliere giovane'),
            (VICE_PRESIDENTE, 'Vice presidente'),
        ]),
        initial='Nomina',
        required=True,
    )
    persona = autocomplete_light.ModelChoiceField(
        "PresidenteAutocompletamento")
    sede = autocomplete_light.ModelChoiceField("ComitatoAutocompletamento")
Ejemplo n.º 18
0
class AnswerForm(forms.ModelForm):
    """Form with autocomplete for users"""
    user = autocomplete_light.ModelChoiceField('UserAutocomplete',
                                               queryset=User.objects.all())

    class Meta:
        model = Answer
        fields = '__all__'
Ejemplo n.º 19
0
class TagForm(forms.Form):
    """This form allows the selection of a tag"""

    tag_select = autocomplete_light.ModelChoiceField(
        'TagSlugAutocomplete',
        label=' ',
        required=False,
    )
Ejemplo n.º 20
0
class ModuloRichiestaSupportoPersone(ModuloRichiestaSupporto):
    persona = autocomplete_light.ModelChoiceField(
        "PersonaAutocompletamento",
        help_text="Seleziona la persona per cui si richiede assistenza."
        "Nel caso la problematica impattasse più persone è necessario "
        "aprire una segnalazione per ogni persona ",
        required=False)

    field_order = ('tipo', 'oggetto', 'persona', 'descrizione')
Ejemplo n.º 21
0
class GroupObjectPermissionAdminForm(forms.ModelForm):
    group = al.ModelChoiceField("GroupAutocomplete")
    permission = PermissionModelChoiceField(
        queryset=Permission.objects.select_related("content_type").filter(
            reduce(operator.or_, PERMISSION_FILTER)
        ),
        label="Permission",
        empty_label="Select A Permssion",
    )
    object_id = forms.CharField(
        widget=al.ChoiceWidget("IPAMObjectsAutoComplete"), label="Object"
    )

    def __init__(self, *args, **kwargs):
        super(GroupObjectPermissionAdminForm, self).__init__(*args, **kwargs)
        if self.instance.pk:
            self.fields["object_id"].initial = "%s-%s" % (
                self.instance.content_type.pk,
                self.instance.object_pk,
            )

    def clean(self):
        cleaned_data = super(GroupObjectPermissionAdminForm, self).clean()

        content_type_id = (
            cleaned_data["object_id"].split("-")[0]
            if cleaned_data.get("object_id")
            else None
        )
        object_pk = (
            cleaned_data["object_id"].split("-")[1]
            if cleaned_data.get("object_id")
            else None
        )
        group = cleaned_data["group"] if cleaned_data.get("group") else None
        permission = (
            cleaned_data["permission"] if cleaned_data.get("permission") else None
        )

        if content_type_id and object_pk and group and permission:
            try:
                GroupObjectPermission.objects.get(
                    group=group,
                    permission=permission,
                    content_type_id=content_type_id,
                    object_pk=object_pk,
                )
            except GroupObjectPermission.DoesNotExist:
                pass
            else:
                raise ValidationError(
                    "Group Permission with this Group, Permission, And Object already exist."
                )

    class Meta:
        model = GroupObjectPermission
        exclude = ("content_type", "object_pk")
Ejemplo n.º 22
0
class ModuloCreazioneTrasferimento(autocomplete_light.ModelForm):
    destinazione = autocomplete_light.ModelChoiceField("SedeTrasferimentoAutocompletamento", error_messages={
        'invalid': "Non è possibile effettuare un trasferimento verso il Comitato Nazionale, verso i Comitati Regionali"
                   "e verso i comitati delle Province Autonome di Trento e Bolzano"
    })

    class Meta:
        model = Trasferimento
        fields = ['persona', 'destinazione', 'motivo']
Ejemplo n.º 23
0
class ModuloQuotaVolontario(ModuloQuotaGenerico):
    volontario = autocomplete_light.ModelChoiceField("VolontarioSedeAutocompletamento",
                                                     help_text="Seleziona il Volontario per il quale registrare"
                                                               " la quota associativa.")

    def clean(self):
        data = super(ModuloQuotaVolontario, self).clean()
        data = self.clean_quota(data)
        return data
Ejemplo n.º 24
0
class AgencyEmailAdminForm(forms.ModelForm):
    """AgencyEmail Inline admin form"""
    email = autocomplete_light.ModelChoiceField(
        'EmailAddressAutocomplete',
        queryset=EmailAddress.objects.all(),
    )

    class Meta:
        model = AgencyEmail
        fields = '__all__'
Ejemplo n.º 25
0
class AgencyAddressAdminForm(forms.ModelForm):
    """AgencyAddress Inline admin form"""
    address = autocomplete_light.ModelChoiceField(
        'AddressAutocomplete',
        queryset=Address.objects.all(),
    )

    class Meta:
        model = AgencyAddress
        fields = '__all__'
Ejemplo n.º 26
0
class AgencyPhoneAdminForm(forms.ModelForm):
    """AgencyPhone Inline admin form"""
    phone = autocomplete_light.ModelChoiceField(
        'PhoneNumberAutocomplete',
        queryset=PhoneNumber.objects.all(),
    )

    class Meta:
        model = AgencyPhone
        fields = '__all__'
Ejemplo n.º 27
0
class FOIANoteAdminForm(forms.ModelForm):
    """Form for note inline"""

    author = autocomplete_light.ModelChoiceField('UserAutocomplete',
                                                 label='Author',
                                                 queryset=User.objects.all())

    class Meta:
        model = FOIANote
        fields = '__all__'
Ejemplo n.º 28
0
class ExemptionAdminForm(forms.ModelForm):
    """Form to include a jurisdiction and contributor autocomplete"""
    jurisdiction = autocomplete_light.ModelChoiceField(
        'JurisdictionAdminAutocomplete', queryset=Jurisdiction.objects.all())
    contributors = autocomplete_light.ModelMultipleChoiceField(
        'UserAutocomplete', queryset=User.objects.all(), required=False)

    class Meta:
        model = Exemption
        fields = '__all__'
Ejemplo n.º 29
0
class CrowdfundPaymentAdminForm(forms.ModelForm):
    """Form for crowdfund payment inline"""

    user = autocomplete_light.ModelChoiceField('UserAutocomplete',
                                               label='User',
                                               queryset=User.objects.all(),
                                               required=False)

    class Meta:
        model = models.CrowdfundPayment
        fields = '__all__'
Ejemplo n.º 30
0
class CrowdsourceResponseAdminForm(forms.ModelForm):
    """Form for Crowdsource response admin"""

    user = autocomplete_light.ModelChoiceField(
        'UserAutocomplete',
        queryset=User.objects.all(),
    )

    class Meta:
        model = CrowdsourceResponse
        fields = '__all__'