示例#1
0
class PersonFilter(AMYFilterSet):
    badges = django_filters.ModelMultipleChoiceFilter(
        queryset=Badge.objects.all(),
        label="Badges",
        widget=ModelSelect2MultipleWidget(
            data_view="badge-lookup",
        ),
    )
    taught_workshops = django_filters.ModelMultipleChoiceFilter(
        queryset=Tag.objects.all(),
        label="Taught at workshops of type",
        method=filter_taught_workshops,
        widget=ModelSelect2MultipleWidget(
            data_view="tag-lookup",
        ),
    )

    order_by = NamesOrderingFilter(
        fields=("email",),
    )

    class Meta:
        model = Person
        fields = [
            "badges",
            "taught_workshops",
        ]
示例#2
0
文件: filters.py 项目: mittald781/amy
class PersonFilter(AMYFilterSet):
    badges = django_filters.ModelMultipleChoiceFilter(
        queryset=Badge.objects.all(), label='Badges',
        widget=ModelSelect2MultipleWidget(
            data_view='badge-lookup',
        ),
    )
    taught_workshops = django_filters.ModelMultipleChoiceFilter(
        queryset=Tag.objects.all(), label='Taught at workshops of type',
        method=filter_taught_workshops,
        widget=ModelSelect2MultipleWidget(
            data_view='tag-lookup',
        ),
    )

    order_by = NamesOrderingFilter(
        fields=(
            'email',
        ),
    )

    class Meta:
        model = Person
        fields = [
            'badges', 'taught_workshops',
        ]
示例#3
0
文件: filters.py 项目: mittald781/amy
class EventFilter(AMYFilterSet):
    assigned_to = ForeignKeyAllValuesFilter(Person, widget=Select2Widget)
    host = ForeignKeyAllValuesFilter(Organization, widget=Select2Widget)
    administrator = ForeignKeyAllValuesFilter(Organization,
                                              widget=Select2Widget)

    STATUS_CHOICES = [
        ('', 'All'),
        ('active', 'Active'),
        ('past_events', 'Past'),
        ('ongoing_events', 'Ongoing'),
        ('upcoming_events', 'Upcoming'),
        ('unpublished_events', 'Unpublished'),
        ('published_events', 'Published'),
        ('uninvoiced_events', 'Uninvoiced'),
        ('metadata_changed', 'Detected changes in metadata'),
    ]
    state = EventStateFilter(choices=STATUS_CHOICES, label='Status',
                             widget=Select2Widget)

    invoice_status = django_filters.ChoiceFilter(
        choices=Event.INVOICED_CHOICES,
    )

    tags = django_filters.ModelMultipleChoiceFilter(
        queryset=Tag.objects.all(), label='Tags',
        widget=ModelSelect2MultipleWidget(
            data_view='tag-lookup',
        ),
    )

    country = AllCountriesFilter(widget=Select2Widget)
    continent = ContinentFilter(widget=Select2Widget, label="Continent")

    order_by = django_filters.OrderingFilter(
        fields=(
            'slug',
            'start',
            'end',
        ),
    )

    class Meta:
        model = Event
        fields = [
            'assigned_to',
            'tags',
            'host',
            'administrator',
            'invoice_status',
            'completed',
            'country',
            'continent',
        ]
示例#4
0
 class Meta:
     model = Organization
     fields = [
         "domain",
         "fullname",
         "country",
         "latitude",
         "longitude",
         "affiliated_organizations",
     ]
     widgets = {
         "affiliated_organizations":
         ModelSelect2MultipleWidget(data_view="organization-lookup"),
     }
示例#5
0
class EventFilter(AMYFilterSet):
    assigned_to = ForeignKeyAllValuesFilter(Person, widget=Select2Widget)
    host = ForeignKeyAllValuesFilter(Organization, widget=Select2Widget)
    administrator = ForeignKeyAllValuesFilter(Organization, widget=Select2Widget)

    STATUS_CHOICES = [
        ("", "All"),
        ("active", "Active"),
        ("past_events", "Past"),
        ("ongoing_events", "Ongoing"),
        ("upcoming_events", "Upcoming"),
        ("unpublished_events", "Unpublished"),
        ("published_events", "Published"),
        ("metadata_changed", "Detected changes in metadata"),
    ]
    state = EventStateFilter(
        choices=STATUS_CHOICES, label="Status", widget=Select2Widget
    )

    tags = django_filters.ModelMultipleChoiceFilter(
        queryset=Tag.objects.all(),
        label="Tags",
        widget=ModelSelect2MultipleWidget(
            data_view="tag-lookup",
        ),
    )

    country = AllCountriesFilter(widget=Select2Widget)
    continent = ContinentFilter(widget=Select2Widget, label="Continent")

    order_by = django_filters.OrderingFilter(
        fields=(
            "slug",
            "start",
            "end",
        ),
    )

    class Meta:
        model = Event
        fields = [
            "assigned_to",
            "tags",
            "host",
            "administrator",
            "completed",
            "country",
            "continent",
        ]
示例#6
0
文件: forms.py 项目: paulkahura/amy
class PersonForm(forms.ModelForm):
    airport = forms.ModelChoiceField(
        label='Airport',
        required=False,
        queryset=Airport.objects.all(),
        widget=ModelSelect2Widget(data_view='airport-lookup'))
    languages = forms.ModelMultipleChoiceField(
        label='Languages',
        required=False,
        queryset=Language.objects.all(),
        widget=ModelSelect2MultipleWidget(data_view='language-lookup'))

    helper = BootstrapHelper(add_cancel_button=False,
                             duplicate_buttons_on_top=True)

    class Meta:
        model = Person
        # don't display the 'password', 'user_permissions',
        # 'groups' or 'is_superuser' fields
        # + reorder fields
        fields = [
            'username',
            'personal',
            'middle',
            'family',
            'may_contact',
            'publish_profile',
            'lesson_publication_consent',
            'data_privacy_agreement',
            'email',
            'gender',
            'country',
            'airport',
            'affiliation',
            'github',
            'twitter',
            'url',
            'occupation',
            'orcid',
            'user_notes',
            'lessons',
            'domains',
            'languages',
        ]

        widgets = {
            'country': Select2Widget,
        }
示例#7
0
文件: forms.py 项目: mittald781/amy
class AutoUpdateProfileForm(forms.ModelForm):
    username = forms.CharField(disabled=True, required=False)
    email = forms.CharField(
        disabled=True,
        required=False,
        label=Person._meta.get_field('email').verbose_name,
        help_text=Person._meta.get_field('email').help_text,
    )
    github = forms.CharField(
        disabled=True,
        required=False,
        help_text='If you want to change your github username, please email '
        'us at <a href="mailto:[email protected]">'
        '[email protected]</a>.')

    country = CountryField().formfield(
        required=False,
        help_text='Your country of residence.',
        widget=Select2Widget,
    )

    languages = forms.ModelMultipleChoiceField(
        label='Languages',
        required=False,
        queryset=Language.objects.all(),
        widget=ModelSelect2MultipleWidget(data_view='language-lookup'))

    helper = BootstrapHelper(add_cancel_button=False)

    class Meta:
        model = Person
        fields = [
            'personal',
            'middle',
            'family',
            'email',
            'secondary_email',
            'gender',
            'gender_other',
            'may_contact',
            'publish_profile',
            'lesson_publication_consent',
            'country',
            'airport',
            'github',
            'twitter',
            'url',
            'username',
            'affiliation',
            'domains',
            'lessons',
            'languages',
            'occupation',
            'orcid',
        ]
        readonly_fields = (
            'username',
            'github',
        )
        widgets = {
            'gender': RadioSelectWithOther('gender_other'),
            'domains': forms.CheckboxSelectMultiple(),
            'lessons': forms.CheckboxSelectMultiple(),
            'airport': Select2Widget,
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # set up a layout object for the helper
        self.helper.layout = self.helper.build_default_layout(self)

        # set up `*WithOther` widgets so that they can display additional
        # fields inline
        self['gender'].field.widget.other_field = self['gender_other']

        # remove additional fields
        self.helper.layout.fields.remove('gender_other')

    def clean(self):
        super().clean()
        errors = dict()

        # 1: require "other gender" field if "other" was selected in
        # "gender" field
        gender = self.cleaned_data.get('gender', '')
        gender_other = self.cleaned_data.get('gender_other', '')
        if gender == GenderMixin.OTHER and not gender_other:
            errors['gender'] = ValidationError("This field is required.")
        elif gender != GenderMixin.OTHER and gender_other:
            errors['gender'] = ValidationError(
                'If you entered data in "Other" field, please select that '
                "option.")

        # raise errors if any present
        if errors:
            raise ValidationError(errors)
示例#8
0
class AutoUpdateProfileForm(forms.ModelForm):
    username = forms.CharField(disabled=True, required=False)
    email = forms.CharField(
        disabled=True,
        required=False,
        label=Person._meta.get_field("email").verbose_name,
        help_text=Person._meta.get_field("email").help_text,
    )
    github = forms.CharField(
        disabled=True,
        required=False,
        help_text="If you want to change your github username, please email "
        'us at <a href="mailto:[email protected]">'
        "[email protected]</a>.",
    )

    country = CountryField().formfield(
        required=False,
        help_text="Your country of residence.",
        widget=Select2Widget,
    )

    languages = forms.ModelMultipleChoiceField(
        label="Languages",
        required=False,
        queryset=Language.objects.all(),
        widget=ModelSelect2MultipleWidget(data_view="language-lookup"),
    )

    class Meta:
        model = Person
        fields = [
            "personal",
            "middle",
            "family",
            "email",
            "secondary_email",
            "gender",
            "gender_other",
            "country",
            "airport",
            "github",
            "twitter",
            "url",
            "username",
            "affiliation",
            "domains",
            "lessons",
            "languages",
            "occupation",
            "orcid",
        ]
        readonly_fields = (
            "username",
            "github",
        )
        widgets = {
            "gender": RadioSelectWithOther("gender_other"),
            "domains": forms.CheckboxSelectMultiple(),
            "lessons": forms.CheckboxSelectMultiple(),
            "airport": Select2Widget,
        }

    def __init__(self, *args, **kwargs):
        form_tag = kwargs.pop("form_tag", True)
        add_submit_button = kwargs.pop("add_submit_button", True)
        super().__init__(*args, **kwargs)
        self.helper = BootstrapHelper(
            add_cancel_button=False,
            form_tag=form_tag,
            add_submit_button=add_submit_button,
        )

        # set up a layout object for the helper
        self.helper.layout = self.helper.build_default_layout(self)

        # set up `*WithOther` widgets so that they can display additional
        # fields inline
        self["gender"].field.widget.other_field = self["gender_other"]

        # remove additional fields
        self.helper.layout.fields.remove("gender_other")

    def clean(self):
        super().clean()
        errors = dict()

        # 1: require "other gender" field if "other" was selected in
        # "gender" field
        gender = self.cleaned_data.get("gender", "")
        gender_other = self.cleaned_data.get("gender_other", "")
        if gender == GenderMixin.OTHER and not gender_other:
            errors["gender"] = ValidationError("This field is required.")
        elif gender != GenderMixin.OTHER and gender_other:
            errors["gender"] = ValidationError(
                'If you entered data in "Other" field, please select that '
                "option.")

        # raise errors if any present
        if errors:
            raise ValidationError(errors)
示例#9
0
文件: forms.py 项目: gaybro8777/amy
class PersonForm(forms.ModelForm):
    airport = forms.ModelChoiceField(
        label="Airport",
        required=False,
        queryset=Airport.objects.all(),
        widget=ModelSelect2Widget(data_view="airport-lookup"),
    )
    languages = forms.ModelMultipleChoiceField(
        label="Languages",
        required=False,
        queryset=Language.objects.all(),
        widget=ModelSelect2MultipleWidget(data_view="language-lookup"),
    )

    helper = BootstrapHelper(add_cancel_button=False,
                             duplicate_buttons_on_top=True)

    class Meta:
        model = Person
        # don't display the 'password', 'user_permissions',
        # 'groups' or 'is_superuser' fields
        # + reorder fields
        fields = [
            "username",
            "personal",
            "middle",
            "family",
            "may_contact",
            "publish_profile",
            "lesson_publication_consent",
            "data_privacy_agreement",
            "email",
            "secondary_email",
            "gender",
            "gender_other",
            "country",
            "airport",
            "affiliation",
            "github",
            "twitter",
            "url",
            "occupation",
            "orcid",
            "user_notes",
            "lessons",
            "domains",
            "languages",
        ]

        widgets = {
            "country": Select2Widget,
            "gender": RadioSelectWithOther("gender_other"),
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # set up a layout object for the helper
        self.helper.layout = self.helper.build_default_layout(self)

        # set up `*WithOther` widgets so that they can display additional
        # fields inline
        self["gender"].field.widget.other_field = self["gender_other"]

        # remove additional fields
        self.helper.layout.fields.remove("gender_other")

    def clean(self):
        super().clean()
        errors = dict()

        # 1: require "other gender" field if "other" was selected in
        # "gender" field
        gender = self.cleaned_data.get("gender", "")
        gender_other = self.cleaned_data.get("gender_other", "")
        if gender == GenderMixin.OTHER and not gender_other:
            errors["gender"] = ValidationError("This field is required.")
        elif gender != GenderMixin.OTHER and gender_other:
            errors["gender"] = ValidationError(
                'If you entered data in "Other" field, please select that '
                "option.")

        # raise errors if any present
        if errors:
            raise ValidationError(errors)
示例#10
0
文件: forms.py 项目: gaybro8777/amy
class WorkshopStaffForm(forms.Form):
    """Represent instructor matching form."""

    latitude = forms.FloatField(label="Latitude",
                                min_value=-90.0,
                                max_value=90.0,
                                required=False)
    longitude = forms.FloatField(label="Longitude",
                                 min_value=-180.0,
                                 max_value=180.0,
                                 required=False)
    airport = forms.ModelChoiceField(
        label="Airport",
        required=False,
        queryset=Airport.objects.all(),
        widget=ModelSelect2Widget(data_view="airport-lookup",
                                  attrs=SELECT2_SIDEBAR),
    )
    languages = forms.ModelMultipleChoiceField(
        label="Languages",
        required=False,
        queryset=Language.objects.all(),
        widget=ModelSelect2MultipleWidget(
            data_view="language-lookup",
            attrs=SELECT2_SIDEBAR,
        ),
    )

    country = forms.MultipleChoiceField(
        choices=list(Countries()),
        required=False,
        widget=Select2MultipleWidget,
    )

    continent = forms.ChoiceField(
        choices=continent_list,
        required=False,
        widget=Select2Widget,
    )

    lessons = forms.ModelMultipleChoiceField(
        queryset=Lesson.objects.all(),
        widget=SelectMultiple(),
        required=False,
    )

    badges = forms.ModelMultipleChoiceField(
        queryset=Badge.objects.instructor_badges(),
        widget=CheckboxSelectMultiple(),
        required=False,
    )

    is_trainer = forms.BooleanField(required=False, label="Has Trainer badge")

    GENDER_CHOICES = ((None, "---------"), ) + Person.GENDER_CHOICES
    gender = forms.ChoiceField(choices=GENDER_CHOICES, required=False)

    was_helper = forms.BooleanField(required=False,
                                    label="Was helper at least once before")
    was_organizer = forms.BooleanField(
        required=False, label="Was organizer at least once before")
    is_in_progress_trainee = forms.BooleanField(
        required=False, label="Is an in-progress instructor trainee")

    def __init__(self, *args, **kwargs):
        """Build form layout dynamically."""
        super().__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        self.helper.form_method = "get"
        self.helper.layout = Layout(
            Div(
                Div(
                    HTML('<h5 class="card-title">Location</h5>'),
                    "airport",
                    HTML("<hr>"),
                    "country",
                    HTML("<hr>"),
                    "continent",
                    HTML("<hr>"),
                    "latitude",
                    "longitude",
                    css_class="card-body",
                ),
                css_class="card",
            ),
            "badges",
            "is_trainer",
            HTML("<hr>"),
            "was_helper",
            "was_organizer",
            "is_in_progress_trainee",
            "languages",
            "gender",
            "lessons",
            Submit("", "Submit"),
        )

    def clean(self):
        cleaned_data = super().clean()
        lat = bool(cleaned_data.get("latitude"))
        lng = bool(cleaned_data.get("longitude"))
        airport = bool(cleaned_data.get("airport"))
        country = bool(cleaned_data.get("country"))
        latlng = lat and lng

        # if searching by coordinates, then there must be both lat & lng
        # present
        if lat ^ lng:
            raise ValidationError(
                "Must specify both latitude and longitude if searching by "
                "coordinates")

        # User must search by airport, or country, or coordinates, or none
        # of them. Sum of boolean elements must be equal 0 (if general search)
        # or 1 (if searching by airport OR country OR lat/lng).
        if sum([airport, country, latlng]) not in [0, 1]:
            raise ValidationError(
                "Must specify an airport OR a country, OR use coordinates, OR "
                "none of them.")
        return cleaned_data
示例#11
0
class AutoUpdateProfileForm(forms.ModelForm):
    username = forms.CharField(disabled=True, required=False)
    email = forms.CharField(
        disabled=True, required=False,
        label=Person._meta.get_field('email').verbose_name,
        help_text=Person._meta.get_field('email').help_text,
    )
    github = forms.CharField(
        disabled=True, required=False,
        help_text='If you want to change your github username, please email '
                  'us at <a href="mailto:[email protected]">'
                  '[email protected]</a>.')

    country = CountryField().formfield(
        required=False,
        help_text='Your country of residence.',
        widget=Select2Widget,
    )

    languages = forms.ModelMultipleChoiceField(
        label='Languages',
        required=False,
        queryset=Language.objects.all(),
        widget=ModelSelect2MultipleWidget(data_view='language-lookup')
    )

    helper = BootstrapHelper(add_cancel_button=False)

    class Meta:
        model = Person
        fields = [
            'personal',
            'middle',
            'family',
            'email',
            'gender',
            'may_contact',
            'publish_profile',
            'lesson_publication_consent',
            'country',
            'airport',
            'github',
            'twitter',
            'url',
            'username',
            'affiliation',
            'domains',
            'lessons',
            'languages',
            'occupation',
            'orcid',
        ]
        readonly_fields = (
            'username',
            'github',
        )
        widgets = {
            'gender': forms.RadioSelect(),
            'domains': forms.CheckboxSelectMultiple(),
            'lessons': forms.CheckboxSelectMultiple(),
            'airport': Select2Widget,
        }
示例#12
0
文件: forms.py 项目: paulkahura/amy
class WorkshopStaffForm(forms.Form):
    '''Represent instructor matching form.'''

    latitude = forms.FloatField(label='Latitude',
                                min_value=-90.0,
                                max_value=90.0,
                                required=False)
    longitude = forms.FloatField(label='Longitude',
                                 min_value=-180.0,
                                 max_value=180.0,
                                 required=False)
    airport = forms.ModelChoiceField(label='Airport',
                                     required=False,
                                     queryset=Airport.objects.all(),
                                     widget=ModelSelect2Widget(
                                         data_view='airport-lookup',
                                         attrs=SELECT2_SIDEBAR,
                                     ))
    languages = forms.ModelMultipleChoiceField(
        label='Languages',
        required=False,
        queryset=Language.objects.all(),
        widget=ModelSelect2MultipleWidget(
            data_view='language-lookup',
            attrs=SELECT2_SIDEBAR,
        ))

    country = forms.MultipleChoiceField(
        choices=list(Countries()),
        required=False,
        widget=Select2MultipleWidget,
    )

    continent = forms.ChoiceField(
        choices=continent_list,
        required=False,
        widget=Select2Widget,
    )

    lessons = forms.ModelMultipleChoiceField(
        queryset=Lesson.objects.all(),
        widget=SelectMultiple(),
        required=False,
    )

    badges = forms.ModelMultipleChoiceField(
        queryset=Badge.objects.instructor_badges(),
        widget=CheckboxSelectMultiple(),
        required=False,
    )

    is_trainer = forms.BooleanField(required=False, label='Has Trainer badge')

    GENDER_CHOICES = ((None, '---------'), ) + Person.GENDER_CHOICES
    gender = forms.ChoiceField(choices=GENDER_CHOICES, required=False)

    was_helper = forms.BooleanField(required=False,
                                    label='Was helper at least once before')
    was_organizer = forms.BooleanField(
        required=False, label='Was organizer at least once before')
    is_in_progress_trainee = forms.BooleanField(
        required=False, label='Is an in-progress instructor trainee')

    def __init__(self, *args, **kwargs):
        '''Build form layout dynamically.'''
        super().__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        self.helper.form_method = 'get'
        self.helper.layout = Layout(
            Div(
                Div(HTML('<h5 class="card-title">Location</h5>'),
                    'airport',
                    HTML('<hr>'),
                    'country',
                    HTML('<hr>'),
                    'continent',
                    HTML('<hr>'),
                    'latitude',
                    'longitude',
                    css_class='card-body'),
                css_class='card',
            ),
            'badges',
            'is_trainer',
            HTML('<hr>'),
            'was_helper',
            'was_organizer',
            'is_in_progress_trainee',
            'languages',
            'gender',
            'lessons',
            Submit('', 'Submit'),
        )

    def clean(self):
        cleaned_data = super().clean()
        lat = bool(cleaned_data.get('latitude'))
        lng = bool(cleaned_data.get('longitude'))
        airport = bool(cleaned_data.get('airport'))
        country = bool(cleaned_data.get('country'))
        latlng = lat and lng

        # if searching by coordinates, then there must be both lat & lng
        # present
        if lat ^ lng:
            raise forms.ValidationError(
                'Must specify both latitude and longitude if searching by '
                'coordinates')

        # User must search by airport, or country, or coordinates, or none
        # of them. Sum of boolean elements must be equal 0 (if general search)
        # or 1 (if searching by airport OR country OR lat/lng).
        if sum([airport, country, latlng]) not in [0, 1]:
            raise forms.ValidationError(
                'Must specify an airport OR a country, OR use coordinates, OR '
                'none of them.')
        return cleaned_data