~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/browser/archive.py

[r=gmb][bug=837975] Add two fields to distro's +add and +edit pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    'ArchivePackagesView',
23
23
    'ArchiveView',
24
24
    'ArchiveViewBase',
 
25
    'EnableRestrictedFamiliesMixin',
25
26
    'make_archive_vocabulary',
26
27
    'PackageCopyingMixin',
27
28
    'traverse_named_ppa',
2033
2034
        return 'Edit %s' % self.context.displayname
2034
2035
 
2035
2036
 
2036
 
class ArchiveAdminView(BaseArchiveEditView):
 
2037
class EnableRestrictedFamiliesMixin:
 
2038
    """A mixin that provides enabled_restricted_families field support"""
 
2039
 
 
2040
    def createEnabledRestrictedFamilies(self, description=None):
 
2041
        """Creates the 'enabled_restricted_families' field.
 
2042
 
 
2043
        """
 
2044
        terms = []
 
2045
        for family in getUtility(IProcessorFamilySet).getRestricted():
 
2046
            terms.append(SimpleTerm(
 
2047
                family, token=family.name, title=family.title))
 
2048
        old_field = IArchive['enabled_restricted_families']
 
2049
        return form.Fields(
 
2050
            List(__name__=old_field.__name__,
 
2051
                 title=old_field.title,
 
2052
                 value_type=Choice(vocabulary=SimpleVocabulary(terms)),
 
2053
                 required=False,
 
2054
                 description=old_field.description if description is None
 
2055
                     else description),
 
2056
                 render_context=self.render_context)
 
2057
 
 
2058
    def validate_enabled_restricted_families(self, data, error_msg):
 
2059
        enabled_restricted_families = data['enabled_restricted_families']
 
2060
        require_virtualized = data.get('require_virtualized', False)
 
2061
        proc_family_set = getUtility(IProcessorFamilySet)
 
2062
        if (not require_virtualized and
 
2063
            set(enabled_restricted_families) !=
 
2064
                set(proc_family_set.getRestricted())):
 
2065
            self.setFieldError('enabled_restricted_families', error_msg)
 
2066
            self.setFieldError('require_virtualized', error_msg)
 
2067
 
 
2068
 
 
2069
class ArchiveAdminView(BaseArchiveEditView, EnableRestrictedFamiliesMixin):
2037
2070
 
2038
2071
    field_names = ['enabled', 'private', 'commercial', 'require_virtualized',
2039
2072
                   'build_debug_symbols', 'buildd_secret', 'authorized_size',
2097
2130
                'commercial',
2098
2131
                'Can only set commericial for private archives.')
2099
2132
 
 
2133
        enabled_restricted_families = data.get('enabled_restricted_families')
 
2134
        if (enabled_restricted_families and
 
2135
            not self.context.canSetEnabledRestrictedFamilies(
 
2136
                enabled_restricted_families)):
 
2137
            self.setFieldError(
 
2138
                'enabled_restricted_families',
 
2139
                'Main archives can not be restricted to certain '
 
2140
                'architectures unless they are set to build on '
 
2141
                'virtualized builders.')
 
2142
 
2100
2143
    @property
2101
2144
    def owner_is_private_team(self):
2102
2145
        """Is the owner a private team?
2106
2149
        """
2107
2150
        return self.context.owner.visibility == PersonVisibility.PRIVATE
2108
2151
 
 
2152
    @property
 
2153
    def initial_values(self):
 
2154
        return {
 
2155
            'enabled_restricted_families':
 
2156
                self.context.enabled_restricted_families,
 
2157
            }
 
2158
 
2109
2159
    def setUpFields(self):
2110
2160
        """Override `LaunchpadEditFormView`.
2111
2161
 
2114
2164
        super(ArchiveAdminView, self).setUpFields()
2115
2165
        self.form_fields += self.createEnabledRestrictedFamilies()
2116
2166
 
2117
 
    def createEnabledRestrictedFamilies(self):
2118
 
        """Creates the 'enabled_restricted_families' field.
2119
 
 
2120
 
        """
2121
 
        terms = []
2122
 
        for family in getUtility(IProcessorFamilySet).getRestricted():
2123
 
            terms.append(SimpleTerm(
2124
 
                family, token=family.name, title=family.title))
2125
 
        old_field = IArchive['enabled_restricted_families']
2126
 
        return form.Fields(
2127
 
            List(__name__=old_field.__name__,
2128
 
                 title=old_field.title,
2129
 
                 value_type=Choice(vocabulary=SimpleVocabulary(terms)),
2130
 
                 required=False,
2131
 
                 description=old_field.description),
2132
 
                 render_context=self.render_context)
2133
 
 
2134
2167
 
2135
2168
class ArchiveDeleteView(LaunchpadFormView):
2136
2169
    """View class for deleting `IArchive`s"""