~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Curtis Hovey
  • Date: 2011-08-18 20:56:37 UTC
  • mto: This revision was merged to the branch mainline in revision 13736.
  • Revision ID: curtis.hovey@canonical.com-20110818205637-ae0pf9aexdea2mlb
Cleaned up doctrings and hushed lint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    'ArchivePackagesView',
23
23
    'ArchiveView',
24
24
    'ArchiveViewBase',
25
 
    'EnableRestrictedFamiliesMixin',
26
25
    'make_archive_vocabulary',
27
26
    'PackageCopyingMixin',
28
27
    'traverse_named_ppa',
35
34
    timedelta,
36
35
    )
37
36
 
38
 
from lazr.restful.utils import smartquote
39
37
import pytz
40
38
from sqlobject import SQLObjectNotFound
41
39
from storm.expr import Desc
81
79
    NavigationMenu,
82
80
    structured,
83
81
    )
 
82
from canonical.lazr.utils import smartquote
84
83
from lp.app.browser.launchpadform import (
85
84
    action,
86
85
    custom_widget,
316
315
 
317
316
    @stepthrough('+subscriptions')
318
317
    def traverse_subscription(self, person_name):
319
 
        person = getUtility(IPersonSet).getByName(person_name)
320
 
        if person is None:
 
318
        try:
 
319
            person = getUtility(IPersonSet).getByName(person_name)
 
320
        except NotFoundError:
321
321
            return None
322
322
 
323
323
        subscriptions = getUtility(IArchiveSubscriberSet).getBySubscriber(
2033
2033
        return 'Edit %s' % self.context.displayname
2034
2034
 
2035
2035
 
2036
 
class EnableRestrictedFamiliesMixin:
2037
 
    """A mixin that provides enabled_restricted_families field support"""
2038
 
 
2039
 
    def createEnabledRestrictedFamilies(self, description=None):
2040
 
        """Creates the 'enabled_restricted_families' field.
2041
 
 
2042
 
        """
2043
 
        terms = []
2044
 
        for family in getUtility(IProcessorFamilySet).getRestricted():
2045
 
            terms.append(SimpleTerm(
2046
 
                family, token=family.name, title=family.title))
2047
 
        old_field = IArchive['enabled_restricted_families']
2048
 
        return form.Fields(
2049
 
            List(__name__=old_field.__name__,
2050
 
                 title=old_field.title,
2051
 
                 value_type=Choice(vocabulary=SimpleVocabulary(terms)),
2052
 
                 required=False,
2053
 
                 description=old_field.description if description is None
2054
 
                     else description),
2055
 
                 render_context=self.render_context)
2056
 
 
2057
 
    def validate_enabled_restricted_families(self, data, error_msg):
2058
 
        enabled_restricted_families = data['enabled_restricted_families']
2059
 
        require_virtualized = data.get('require_virtualized', False)
2060
 
        proc_family_set = getUtility(IProcessorFamilySet)
2061
 
        if (not require_virtualized and
2062
 
            set(enabled_restricted_families) !=
2063
 
                set(proc_family_set.getRestricted())):
2064
 
            self.setFieldError('enabled_restricted_families', error_msg)
2065
 
            self.setFieldError('require_virtualized', error_msg)
2066
 
 
2067
 
 
2068
 
ARCHIVE_ENABLED_RESTRICTED_FAMILITES_ERROR_MSG = (
2069
 
    u'Main archives can not be restricted to certain '
2070
 
    'architectures unless they are set to build on '
2071
 
    'virtualized builders.')
2072
 
 
2073
 
 
2074
 
class ArchiveAdminView(BaseArchiveEditView, EnableRestrictedFamiliesMixin):
 
2036
class ArchiveAdminView(BaseArchiveEditView):
2075
2037
 
2076
2038
    field_names = ['enabled', 'private', 'commercial', 'require_virtualized',
2077
2039
                   'build_debug_symbols', 'buildd_secret', 'authorized_size',
2135
2097
                'commercial',
2136
2098
                'Can only set commericial for private archives.')
2137
2099
 
2138
 
        enabled_restricted_families = data.get('enabled_restricted_families')
2139
 
        require_virtualized = data.get('require_virtualized')
2140
 
        proc_family_set = getUtility(IProcessorFamilySet)
2141
 
        if (enabled_restricted_families and
2142
 
            not require_virtualized and
2143
 
            set(enabled_restricted_families) !=
2144
 
                set(proc_family_set.getRestricted())):
2145
 
            self.setFieldError(
2146
 
                'enabled_restricted_families',
2147
 
                ARCHIVE_ENABLED_RESTRICTED_FAMILITES_ERROR_MSG)
2148
 
            self.setFieldError(
2149
 
                'require_virtualized',
2150
 
                ARCHIVE_ENABLED_RESTRICTED_FAMILITES_ERROR_MSG)
2151
 
 
2152
2100
    @property
2153
2101
    def owner_is_private_team(self):
2154
2102
        """Is the owner a private team?
2158
2106
        """
2159
2107
        return self.context.owner.visibility == PersonVisibility.PRIVATE
2160
2108
 
2161
 
    @property
2162
 
    def initial_values(self):
2163
 
        return {
2164
 
            'enabled_restricted_families':
2165
 
                self.context.enabled_restricted_families,
2166
 
            }
2167
 
 
2168
2109
    def setUpFields(self):
2169
2110
        """Override `LaunchpadEditFormView`.
2170
2111
 
2173
2114
        super(ArchiveAdminView, self).setUpFields()
2174
2115
        self.form_fields += self.createEnabledRestrictedFamilies()
2175
2116
 
 
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
 
2176
2134
 
2177
2135
class ArchiveDeleteView(LaunchpadFormView):
2178
2136
    """View class for deleting `IArchive`s"""