def build_versions_form(project):
 attrs = {'project': project}
 versions_qs = project.versions.all()
 active = versions_qs.filter(active=True)
 if active.exists():
  choices = [(version.slug, version.verbose_name) for version in active]
  attrs['default-version'] = forms.ChoiceField(label=_('Default Version'), choices=choices, initial=project.get_default_version())
 for version in versions_qs:
  field_name = ('version-%s' % version.slug)
  privacy_name = ('privacy-%s' % version.slug)
  if (version.type == TAG):
   label = ('%s (%s)' % (version.verbose_name, version.identifier[:8]))
  else:
   label = version.verbose_name
  attrs[field_name] = forms.BooleanField(label=label, widget=DualCheckboxWidget(version), initial=version.active, required=False)
  attrs[privacy_name] = forms.ChoiceField(label='privacy', choices=constants.PRIVACY_CHOICES, initial=version.privacy_level)
 return type('VersionsForm', (BaseVersionsForm,), attrs)

def build_versions_form ( project ) : attrs = { 'project' : project } versions_qs = project . versions . all ( ) active = versions_qs . filter ( active = True ) if active . exists ( ) : choices = [ ( version . slug , version . verbose_name ) for version in active ] attrs [ 'default-version' ] = forms . ChoiceField ( label = _ ( 'Default Version' ) , choices = choices , initial = project . get_default_version ( ) ) for version in versions_qs : field_name = ( 'version-%s' % version . slug ) privacy_name = ( 'privacy-%s' % version . slug ) if ( version . type == TAG ) : label = ( '%s (%s)' % ( version . verbose_name , version . identifier [ : 8 ] ) ) else : label = version . verbose_name attrs [ field_name ] = forms . BooleanField ( label = label , widget = DualCheckboxWidget ( version ) , initial = version . active , required = False ) attrs [ privacy_name ] = forms . ChoiceField ( label = 'privacy' , choices = constants . PRIVACY_CHOICES , initial = version . privacy_level ) return type ( 'VersionsForm' , ( BaseVersionsForm , ) , attrs )
versions form with a list of versions and version privacy levels .