Example #1
0
class ReleaseForm(ModelForm):
    class Meta:
        model = Release

    #           args:  this model, fieldname on this model, lookup_channel_name
    group = make_ajax_field(Release, 'group', 'group')

    # no help text at all
    label = make_ajax_field(Release, 'label', 'label', help_text=None)

    # any extra kwargs are passed onto the field, so you may pass a custom help_text here
    songs = make_ajax_field(Release,
                            'songs',
                            'song',
                            help_text=u"Search for song by title")

    # if you are creating a form for use outside of the django admin to specify show_m2m_help=True :
    # label  = make_ajax_field(Release,'label','label',show_m2m_help=True)
    # so that it will show the help text in manytomany fields

    title = make_ajax_field(
        Release,
        'title',
        'cliche',
        help_text=
        u"Autocomplete will search the database for clichés about cats.")
Example #2
0
class BidForm(djforms.ModelForm):
    speedrun = make_ajax_field(models.Bid, 'speedrun', 'run')
    event = make_ajax_field(models.Bid,
                            'event',
                            'event',
                            initial=latest_event_id)
    biddependency = make_ajax_field(models.Bid, 'biddependency', 'allbids')
Example #3
0
class GASConfigForm(forms.ModelForm):

    default_withdrawal_place = make_ajax_field(
        gas_models.GASConfig,
        model_fieldname='default_withdrawal_place',
        channel='placechannel',
        #help_text="Search for place by name"
    )
    default_delivery_place = make_ajax_field(
        gas_models.GASConfig,
        model_fieldname='default_delivery_place',
        channel='placechannel',
        #help_text="Search for place by name"
    )

    class Meta:
        model = gas_models.GASConfig
        exclude = ()

    def __init__(self, *args, **kwargs):
        super(GASConfigForm, self).__init__(*args, **kwargs)
        if kwargs.has_key('instance'):
            gas = kwargs['instance'].gas
            self.fields[
                'intergas_connection_set'].queryset = GAS.objects.exclude(
                    pk=gas.pk)
Example #4
0
File: forms.py Project: Hyask/Sith
class PagePropForm(forms.ModelForm):
    error_css_class = "error"
    required_css_class = "required"

    class Meta:
        model = Page
        fields = [
            "parent", "name", "owner_group", "edit_groups", "view_groups"
        ]

    edit_groups = make_ajax_field(Page,
                                  "edit_groups",
                                  "groups",
                                  help_text="",
                                  label=_("edit groups"))
    view_groups = make_ajax_field(Page,
                                  "view_groups",
                                  "groups",
                                  help_text="",
                                  label=_("view groups"))

    def __init__(self, *arg, **kwargs):
        super(PagePropForm, self).__init__(*arg, **kwargs)
        self.fields["edit_groups"].required = False
        self.fields["view_groups"].required = False
Example #5
0
class DonorPrizeEntryForm(djforms.ModelForm):
    donor = make_ajax_field(models.DonorPrizeEntry, 'donor', 'donor')
    prize = make_ajax_field(models.DonorPrizeEntry, 'prize', 'prize')

    class Meta:
        model = models.DonorPrizeEntry
        exclude = ('', '')
 def __init__(self, *args, **kwargs):
     super(forms.ModelForm, self).__init__(*args, **kwargs)
     self.fields['users'] = make_ajax_field(Task, 'users', 'userlookup', help_text="")
     self.fields['groups'] = make_ajax_field(Task, 'groups', 'grouplookup', help_text="")
     self.fields['details_file'].widget.attrs = {'class': 'btn btn-sm'}
     self.fields['due_date'].widget = DateTimePicker(options={"format": "YYYY-MM-DD",
                                                              "pickTime": False})
Example #7
0
class ProjectAdminForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        forms.ModelForm.__init__(self, *args, **kwargs)
        self.fields['people'].queryset = Person.objects.distinct(
            'institutionEmail')

    class Meta:
        model = Project
        fields = [
            'code', 'title', 'principalInvestigator', 'altAdmins', 'summary',
            'people'
        ]

    altAdmins = make_ajax_field(
        Project,
        'altAdmins',
        'person',
    )
    people = make_ajax_field(
        Project,
        'people',
        'person',
    )
    principalInvestigator = make_ajax_field(
        Project,
        'principalInvestigator',
        'principalInvestigator',
    )
Example #8
0
class CIRelationEditForm(forms.ModelForm):
    class Meta:
        model = models.CIRelation
        fields = (
            'id',
            'parent',
            'child',
            'type',
        )

    icons = {}

    parent = make_ajax_field(
        models.CIRelation,
        'parent',
        ('ralph.cmdb.models', 'CILookup'),
        help_text=None,
        required=True,
    )
    child = make_ajax_field(
        models.CIRelation,
        'child',
        ('ralph.cmdb.models', 'CILookup'),
        help_text=None,
        required=True,
    )

    def __init__(self, *args, **kwargs):
        super(CIRelationEditForm, self).__init__(*args, **kwargs)
        if self.data:
            self.data = self.data.copy()
Example #9
0
class BaseSupplierForm(forms.ModelForm):

    seat = make_ajax_field(
        Supplier,
        label=_("seat").capitalize(),
        model_fieldname='seat',
        channel='placechannel',
        help_text=_("Search for place by name, by address, or by city"))
    contact_set = MultiContactField(n=3, label=_('Contacts'))

    frontman = make_ajax_field(Supplier,
                               label=_("frontman").capitalize(),
                               model_fieldname='frontman',
                               channel='personchannel',
                               help_text=_("Search for person by name"))

    def __init__(self, request, *args, **kw):
        super(BaseSupplierForm, self).__init__(*args, **kw)

        #TODO: fero to refactory and move in GF Form baseclass...
        self._messages = {
            'error': [],
            'info': [],
            'warning': [],
        }

    def write_down_messages(self):
        """Used to return messages related to form.

        Usually called:
        * in request.method == "GET"
        * when it is "POST" but form is invalid
        """

        # Write down messages only if we are GETting the form
        for level, msg_list in self._messages.items():
            for msg in msg_list:
                getattr(messages, level)(self.request, msg)

    @transaction.commit_on_success
    def save(self, *args, **kw):
        """Save related objects and then save model instance"""

        for contact in self.cleaned_data['contact_set']:

            if contact.value:
                contact.save()
            elif contact.pk:
                self.cleaned_data['contact_set'].remove(contact)

        return super(BaseSupplierForm, self).save(*args, **kw)

    class Meta:
        model = Supplier
        fields = ('name', 'seat', 'website', 'contact_set', 'logo', 'frontman',
                  'flavour', 'vat_number', 'certifications')
        gf_fieldsets = [(None, {
            'fields': ('name', 'seat', 'website', 'contact_set', 'logo',
                       'frontman', 'flavour', 'vat_number', 'certifications')
        })]
Example #10
0
class ReleaseForm(ModelForm):
    class Meta:
        model = Release

    #           args:  this model, fieldname on this model, lookup_channel_name
    group = make_ajax_field(Release, 'group', 'group', show_help_text=True)

    label = make_ajax_field(Release,
                            'label',
                            'label',
                            help_text="Search for label by name")

    # any extra kwargs are passed onto the field, so you may pass a custom help_text here
    #songs = make_ajax_field(Release,'songs','song', help_text=u"Search for song by title")

    # testing bug with no help text supplied
    songs = make_ajax_field(Release,
                            'songs',
                            'song',
                            help_text="",
                            show_help_text=True)

    # these are from a fixed array defined in lookups.py
    title = make_ajax_field(
        Release,
        'title',
        'cliche',
        help_text=u"Autocomplete will suggest clichés about cats.")
Example #11
0
class ContentForm(forms.ModelForm):
    class Meta:
        model = Content
        fields = '__all__'

    contributors = make_ajax_field(Content, 'contributors', 'contributor')
    tags = make_ajax_field(Content, 'tags', 'tag')
Example #12
0
class PrizeWinnerForm(djforms.ModelForm):
    winner = make_ajax_field(models.PrizeWinner, 'winner', 'donor')
    prize = make_ajax_field(models.PrizeWinner, 'prize', 'prize')

    class Meta:
        model = models.PrizeWinner
        exclude = ('', '')
Example #13
0
class DonorForm(djforms.ModelForm):
    addresscountry = make_ajax_field(models.Donor, 'addresscountry', 'country')
    user = make_ajax_field(models.Donor, 'user', 'user')

    class Meta:
        model = models.Donor
        exclude = ('', '')
Example #14
0
class MeasuredValueForm(ModelForm):
    specimen = make_ajax_field(measured_values, "specimen", "specimenLookup")
    reference = make_ajax_field(measured_values, "reference",
                                "referenceLookup")

    class Meta:
        model = measured_values
        fields = "__all__"
Example #15
0
class StudentForm(forms.ModelForm):
    class Meta:
        model = Student
    
    ssn = USSocialSecurityNumberField(required=False)
    state = USStateField()
    zip = USZipCodeField(required=False)
    siblings  = make_ajax_field(Student,'siblings','all_student',help_text=None)
    emergency_contacts  = make_ajax_field(Student,'emergency_contacts','emergency_contact',help_text=None)
Example #16
0
class AlbumEditForm(forms.ModelForm):
    class Meta:
        model = Album
        fields = ["name", "date", "file", "parent", "edit_groups"]

    date = forms.DateField(label=_("Date"), widget=SelectDate, required=True)
    parent = make_ajax_field(Album, "parent", "files", help_text="")
    edit_groups = make_ajax_field(Album, "edit_groups", "groups", help_text="")
    recursive = forms.BooleanField(label=_("Apply rights recursively"),
                                   required=False)
Example #17
0
class SpeedRunAdminForm(djforms.ModelForm):
    event = make_ajax_field(models.SpeedRun,
                            'event',
                            'event',
                            initial=latest_event_id)
    runners = make_ajax_field(models.SpeedRun, 'runners', 'runner')

    class Meta:
        model = models.SpeedRun
        exclude = ('', '')
Example #18
0
class OccurrenceForm(ModelForm):
    taxon = make_ajax_field(occurrence, "taxon", "taxonLookup")
    ref = make_ajax_field(occurrence, "ref", "referenceLookup")
    location = make_ajax_field(occurrence, "location", "locationLookup")
    notes = forms.CharField(widget=forms.Textarea, required=False)
    issue = forms.BooleanField(required=False, initial=False)

    class Meta:
        model = occurrence
        fields = "__all__"
Example #19
0
class DonationForm(djforms.ModelForm):
    donor = make_ajax_field(models.Donation, 'donor', 'donor')
    event = make_ajax_field(models.Donation,
                            'event',
                            'event',
                            initial=latest_event_id)

    class Meta:
        model = models.Donation
        exclude = ('', '')
Example #20
0
class EventForm(djforms.ModelForm):
    allowed_prize_countries = make_ajax_field(models.Event,
                                              'allowed_prize_countries',
                                              'country')
    disallowed_prize_regions = make_ajax_field(models.Event,
                                               'disallowed_prize_regions',
                                               'countryregion')
    prizecoordinator = make_ajax_field(models.Event, 'prizecoordinator',
                                       'user')

    class Meta:
        model = models.Event
        exclude = ('', '')
Example #21
0
class RepositoryForm(forms.ModelForm):
    attributes = make_ajax_field(Repository, 'attributes', 'attribute')
    packages = make_ajax_field(Repository, 'packages', 'package')
    excludes = make_ajax_field(Repository, 'excludes', 'attribute')

    class Meta:
        model = Repository

    def __init__(self, *args, **kwargs):
        super(RepositoryForm, self).__init__(*args, **kwargs)
        try:
            self.fields['version'].initial = UserProfile.objects.get(
                pk=threadlocals.get_current_user().id).version.id
        except UserProfile.DoesNotExist:
            pass
Example #22
0
class RevisionTemplateMetricForm(Form):
    """
    Mimics the adminform.
    """
    def __init__(self, *args, **kwargs):
        super(RevisionTemplateMetricForm, self).__init__(*args, **kwargs)
        self.fields['group'].empty_label = None
        self.fields['tag'].empty_label = None
        self.fields['mtype'].empty_label = None

    name = CharField(max_length=255,
                     label='Name',
                     help_text='Metric name',
                     widget=TextInput(attrs={'class': 'metricautocomplete'}))
    probeversion = make_ajax_field(Metric,
                                   'probeversion',
                                   'hintsprobes',
                                   label='Probe',
                                   help_text='Probe name and version',
                                   required=False)
    qs = Tags.objects.all()
    tag = ModelChoiceField(queryset=qs,
                           label='Tag',
                           help_text='Select one of the tags available.')
    qs = MetricType.objects.all()
    mtype = ModelChoiceField(queryset=qs,
                             widget=Select(),
                             label='Type',
                             help_text='Metric is of given type')
    qs = GroupOfMetrics.objects.all()
    group = ModelChoiceField(queryset=qs,
                             widget=Select(),
                             help_text='Metric is member of selected group')
Example #23
0
class PersonForm(forms.ModelForm):

    place = make_ajax_field(
        Person,
        label=_("address"),
        model_fieldname='place',
        channel='placechannel',
        help_text=_("Search for place by name, by address, or by city"))
    contact_set = MultiContactField(n=3, label=_('Contacts'))

    #    def __init__(self, request, *args, **kw):
    def __init__(self, *args, **kw):
        super(PersonForm, self).__init__(*args, **kw)
        model = self._meta.model
#        autoselect_fields_check_can_add(self,model,request.user)

    @transaction.commit_on_success
    def save(self, *args, **kw):
        """Save related objects and then save model instance"""

        for contact in self.cleaned_data['contact_set']:
            if contact.value:
                contact.save()
            elif contact.pk:
                self.cleaned_data['contact_set'].remove(contact)

        return super(PersonForm, self).save(*args, **kw)

    class Meta:
        model = Person
        fields = ('name', 'surname', 'contact_set', 'place')
        gf_fieldsets = [(None, {
            'fields': (('name', 'surname'), 'address', 'contact_set'),
        })]
Example #24
0
class MetricParentForm(ModelForm):
    value = make_ajax_field(Metric, 'name', 'hintsmetricsall')

    def clean(self):
        update_field('parent', self.cleaned_data, MetricParent)

        return super(MetricParentForm, self).clean()
Example #25
0
class ForumForm(forms.ModelForm):
    class Meta:
        model = Forum
        fields = [
            "name",
            "parent",
            "number",
            "owner_club",
            "is_category",
            "edit_groups",
            "view_groups",
        ]

    edit_groups = make_ajax_field(Forum, "edit_groups", "groups", help_text="")
    view_groups = make_ajax_field(Forum, "view_groups", "groups", help_text="")
    parent = ForumNameField(Forum.objects.all())
Example #26
0
class ProfileForm(ModelForm):
    """
    Connects profile attributes to autocomplete widget (:py:mod:`poem.widgets`). Also
    adds media and does basic sanity checking for input.
    """

    name = CharField(help_text='Namespace and name of this profile.',
                           max_length=128,
                           widget=widgets.NamespaceTextInput(
                                           attrs={'maxlength': 128, 'size': 45}),
                           label='Profile name'
                           )
    vo = make_ajax_field(Profile, 'name', 'hintsvo', \
                         help_text='Virtual organization that owns this profile.', \
                         plugin_options = {'minLength' : 2}, label='Virtual organization')
    description = CharField(help_text='Free text description outlining the purpose of this profile.',
                                  widget=Textarea(attrs={'style':'width:480px;height:100px'}))

    def clean_vo(self):
        clean_values = []
        clean_values = check_cache('/poem/admin/lookups/ajax_lookup/hintsvo', VO, 'name')
        form_vo = self.cleaned_data['vo']
        if form_vo not in clean_values:
            raise ValidationError("Unable to find virtual organization %s." % (str(form_vo)))
        return form_vo
Example #27
0
class RevisionForm(forms.ModelForm):
    class Meta:
        model = Revision
        fields = '__all__'

    tool = make_ajax_field(Revision, 'tool', 'Tool', help_text=None)
    field_order = ['tool', 'date', 'test_engineer', 'result']
    date = forms.DateField(
        widget=forms.DateInput(format=settings.DATE_INPUT_FORMATS[0]),
        input_formats=settings.DATE_INPUT_FORMATS)
    result = forms.ChoiceField(
        required=False,
        widget=forms.RadioSelect,
        choices=[(1, 'Pass'), (2, 'Fail')],
    )
    visual_check = forms.ChoiceField(
        required=False,
        widget=forms.RadioSelect,
        choices=[(1, 'Pass'), (2, 'Fail')],
    )
    function_check = forms.ChoiceField(
        required=False,
        widget=forms.RadioSelect,
        choices=[(1, 'Pass'), (2, 'Fail')],
    )
class CardForm(ModelForm):
    class Meta:
        model = Card
        fields = ('card_type', 'number', 'card_security_code',
                  'activation_date', 'expiration_date',
                  'card_security_code_blocked_until', 'owner', 'status')

    number = make_ajax_field(CardNumber, 'number', 'number')
Example #29
0
class ReleaseForm(QuerySetMixin, ModelForm):
    manager = make_ajax_field(Release, 'manager', 'user')
    reviewer = make_ajax_field(Release, 'reviewer', 'user')
    bug_manager = make_ajax_field(Release, 'bug_manager', 'user')
    translation_manager = make_ajax_field(Release, 'translation_manager',
                                          'user')

    def __init__(self, *args, **kwargs):
        super(ReleaseForm, self).__init__(*args, **kwargs)
        if 'release_notes' in self.fields:
            self.fields['release_notes'].widget = TextEditorWidget()

    def parent_queryset(self, qs):
        qs = qs.filter(parent__isnull=True)
        if self.instance.pk:
            qs = qs.exclude(id=self.instance.pk)
        return qs
Example #30
0
class LogAdminForm(djforms.ModelForm):
    event = make_ajax_field(models.Log,
                            'event',
                            'event',
                            initial=latest_event_id)

    class Meta:
        model = models.Log
        exclude = ('', '')
Example #31
0
class PostbackURLForm(djforms.ModelForm):
    event = make_ajax_field(models.PostbackURL,
                            'event',
                            'event',
                            initial=latest_event_id)

    class Meta:
        model = models.PostbackURL
        exclude = ('', '')
Example #32
0
def make_admin_ajax_field(model,model_fieldname,channel,show_help_text = False,**kwargs):
  kwargs.pop('add_link', None) # get rid of this for now until I can add it back in to ajax_selects (if ever)
  return make_ajax_field(model, model_fieldname, channel, show_help_text=show_help_text, **kwargs)
Example #33
0
def make_admin_ajax_field(model,model_fieldname,channel,show_help_text = False,**kwargs):
  kwargs['is_admin'] = True;
  return make_ajax_field(model, model_fieldname, channel, show_help_text=show_help_text, **kwargs);