示例#1
0
文件: forms.py 项目: rtnpro/faf
    def __init__(self, db, request):
        '''
        Builds choices according to user selection.
        '''

        self.db = db
        super(OsComponentFilterForm, self).__init__()

        self.fields['os_release'].populate_choices(all_distros_with_all_releases(db))
        self.fields['os_release'].widget.attrs['onchange'] = (
            'Dajaxice.pyfaf.hub.services.components(Dajax.process'
            ',{"os_release":this.value,"associate":"*","component_field":"component"})')

        # Set initial value for operating system release.
        if 'os_release' in request:
            self.fields['os_release'].try_to_select(request['os_release'])

        # Find all components
        distro, release = split_distro_release(self.fields['os_release'].initial)
        self.os_release_id = distro_release_id(db, distro, release)

        self.fields['component'].populate_choices(components_list(db, [self.os_release_id]
            if self.os_release_id != -1 else []))

        if 'component' in request:
            self.fields['component'].try_to_select(request['component'])
示例#2
0
文件: ajax.py 项目: rtnpro/faf
def associates(request, os_release, field):
    dajax = Dajax()

    db = pyfaf.storage.getDatabase()

    os_releases = None
    os_release_id = distro_release_id(db, *split_distro_release(os_release))
    if os_release_id != -1:
        os_releases = [os_release_id]

    out = "<option value='*'>All Associates</option>"
    for associate in associates_list(db, os_releases):
        out += "<option value='%s'>%s</option>\n" % (str(associate.id), associate.name)

    dajax.assign('#id_%s' % (field), 'innerHTML', out)
    return dajax.json()
示例#3
0
文件: ajax.py 项目: rtnpro/faf
def components(request, os_release, associate, component_field):
    dajax = Dajax()

    db = pyfaf.storage.getDatabase()

    os_releases = []
    os_release_id = distro_release_id(db, *split_distro_release(os_release))
    if os_release_id != -1:
        os_releases.append(os_release_id)

    out = "<option value='*'>All Components</option>"
    for component in unique(components_list(db, os_releases,
                            None if '*' == associate else [int(associate)]), lambda x: x[1]):
        out += "<option value='%s'>%s</option>\n" % (slugify(component[1]), component[1])

    dajax.assign('#id_%s' % (component_field), 'innerHTML', out)
    return dajax.json()