~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/browser/distribution.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-12 18:11:42 UTC
  • mfrom: (13901.2.2 perm-845803)
  • Revision ID: launchpad@pqm.canonical.com-20110912181142-fnn8de7d1cq3ra9r
[r=julian-edwards][bug=845803] Remove call to
        canSetEnabledRestrictedFamilies

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
from collections import defaultdict
42
42
import datetime
43
43
 
 
44
from zope.app.form.browser.boolwidgets import CheckBoxWidget
44
45
from zope.component import getUtility
45
46
from zope.event import notify
46
47
from zope.formlib import form
47
48
from zope.interface import implements
48
49
from zope.lifecycleevent import ObjectCreatedEvent
 
50
from zope.schema import Bool
49
51
from zope.security.interfaces import Unauthorized
50
52
 
51
53
from canonical.launchpad.browser.feeds import FeedsMixin
82
84
    )
83
85
from lp.app.errors import NotFoundError
84
86
from lp.app.widgets.image import ImageChangeWidget
 
87
from lp.app.widgets.itemswidgets import LabeledMultiCheckBoxWidget
85
88
from lp.archivepublisher.interfaces.publisherconfig import (
86
89
    IPublisherConfig,
87
90
    IPublisherConfigSet,
104
107
    IRegistryCollectionNavigationMenu,
105
108
    RegistryCollectionActionMenuBase,
106
109
    )
 
110
from lp.registry.browser.objectreassignment import ObjectReassignmentView
107
111
from lp.registry.browser.pillar import PillarBugsMenu
108
 
from lp.registry.browser.objectreassignment import ObjectReassignmentView
109
112
from lp.registry.interfaces.distribution import (
110
113
    IDerivativeDistribution,
111
114
    IDistribution,
123
126
    request_country,
124
127
    )
125
128
from lp.services.propertycache import cachedproperty
 
129
from lp.soyuz.browser.archive import EnableRestrictedFamiliesMixin
126
130
from lp.soyuz.browser.packagesearch import PackageSearchViewBase
127
131
from lp.soyuz.enums import ArchivePurpose
128
132
from lp.soyuz.interfaces.archive import IArchiveSet
 
133
from lp.soyuz.interfaces.processor import IProcessorFamilySet
129
134
 
130
135
 
131
136
class DistributionNavigation(
772
777
        return self.context.count()
773
778
 
774
779
 
775
 
class DistributionAddView(LaunchpadFormView):
 
780
class RequireVirtualizedBuildersMixin:
 
781
    """A mixin that provides require_virtualized field support"""
 
782
 
 
783
    def createRequireVirtualized(self):
 
784
        return form.Fields(
 
785
            Bool(
 
786
                __name__='require_virtualized',
 
787
                title=u"Require virtualized builders",
 
788
                description=(
 
789
                    u"Only build the distribution's packages on virtual "
 
790
                    "builders."),
 
791
                required=True))
 
792
 
 
793
    def updateRequireVirtualized(self, require_virtualized, archive):
 
794
        if archive.require_virtualized != require_virtualized:
 
795
            archive.require_virtualized = require_virtualized
 
796
 
 
797
 
 
798
class DistributionAddView(LaunchpadFormView,
 
799
                          RequireVirtualizedBuildersMixin,
 
800
                          EnableRestrictedFamiliesMixin):
776
801
 
777
802
    schema = IDistribution
778
803
    label = "Register a new distribution"
789
814
        "official_rosetta",
790
815
        "answers_usage",
791
816
        ]
 
817
    custom_widget('require_virtualized', CheckBoxWidget)
 
818
    custom_widget('enabled_restricted_families', LabeledMultiCheckBoxWidget)
792
819
 
793
820
    @property
794
821
    def page_title(self):
795
822
        """The page title."""
796
823
        return self.label
797
824
 
 
825
    def validate(self, data):
 
826
        self.validate_enabled_restricted_families(
 
827
            data, ENABLED_RESTRICTED_FAMILITES_ERROR_MSG)
 
828
 
 
829
    @property
 
830
    def initial_values(self):
 
831
        proc_family_set = getUtility(IProcessorFamilySet)
 
832
        restricted_families = set(proc_family_set.getRestricted())
 
833
        return {
 
834
            'enabled_restricted_families': restricted_families,
 
835
            'require_virtualized': False,
 
836
            }
 
837
 
798
838
    @property
799
839
    def cancel_url(self):
800
840
        """See `LaunchpadFormView`."""
801
841
        return canonical_url(self.context)
802
842
 
 
843
    def setUpFields(self):
 
844
        """See `LaunchpadFormView`."""
 
845
        LaunchpadFormView.setUpFields(self)
 
846
        self.form_fields += self.createRequireVirtualized()
 
847
        self.form_fields += self.createEnabledRestrictedFamilies(
 
848
            u'The restricted architecture families on which the '
 
849
            "distribution's main archive can build.")
 
850
 
803
851
    @action("Save", name='save')
804
852
    def save_action(self, action, data):
805
853
        distribution = getUtility(IDistributionSet).new(
813
861
            owner=self.user,
814
862
            registrant=self.user,
815
863
            )
 
864
        archive = distribution.main_archive
 
865
        self.updateRequireVirtualized(data['require_virtualized'], archive)
 
866
        if archive.require_virtualized is True:
 
867
            archive.enabled_restricted_families = (
 
868
                data['enabled_restricted_families'])
 
869
 
816
870
        notify(ObjectCreatedEvent(distribution))
817
871
        self.next_url = canonical_url(distribution)
818
872
 
819
873
 
820
 
class DistributionEditView(RegistryEditFormView):
 
874
ENABLED_RESTRICTED_FAMILITES_ERROR_MSG = (
 
875
    u"This distribution's main archive can not be restricted to "
 
876
    'certain architectures unless the archive is also set '
 
877
    'to build on virtualized builders.')
 
878
 
 
879
 
 
880
class DistributionEditView(RegistryEditFormView,
 
881
                           RequireVirtualizedBuildersMixin,
 
882
                           EnableRestrictedFamiliesMixin):
821
883
 
822
884
    schema = IDistribution
823
885
    field_names = [
827
889
        'description',
828
890
        'bug_reporting_guidelines',
829
891
        'bug_reported_acknowledgement',
 
892
        'package_derivatives_email',
830
893
        'icon',
831
894
        'logo',
832
895
        'mugshot',
841
904
    custom_widget('icon', ImageChangeWidget, ImageChangeWidget.EDIT_STYLE)
842
905
    custom_widget('logo', ImageChangeWidget, ImageChangeWidget.EDIT_STYLE)
843
906
    custom_widget('mugshot', ImageChangeWidget, ImageChangeWidget.EDIT_STYLE)
 
907
    custom_widget('require_virtualized', CheckBoxWidget)
 
908
    custom_widget('enabled_restricted_families', LabeledMultiCheckBoxWidget)
844
909
 
845
910
    @property
846
911
    def label(self):
847
912
        """See `LaunchpadFormView`."""
848
913
        return 'Change %s details' % self.context.displayname
849
914
 
 
915
    def setUpFields(self):
 
916
        """See `LaunchpadFormView`."""
 
917
        RegistryEditFormView.setUpFields(self)
 
918
        self.form_fields += self.createRequireVirtualized()
 
919
        self.form_fields += self.createEnabledRestrictedFamilies(
 
920
            u'The restricted architecture families on which the '
 
921
            "distribution's main archive can build.")
 
922
 
 
923
    @property
 
924
    def initial_values(self):
 
925
        return {
 
926
            'require_virtualized':
 
927
                self.context.main_archive.require_virtualized,
 
928
            'enabled_restricted_families':
 
929
                self.context.main_archive.enabled_restricted_families,
 
930
            }
 
931
 
850
932
    def validate(self, data):
851
933
        """Constrain bug expiration to Launchpad Bugs tracker."""
852
934
        # enable_bug_expiration is disabled by JavaScript when official_malone
856
938
        if not official_malone:
857
939
            data['enable_bug_expiration'] = False
858
940
 
 
941
        # Validate enabled_restricted_families.
 
942
        self.validate_enabled_restricted_families(
 
943
            data,
 
944
            ENABLED_RESTRICTED_FAMILITES_ERROR_MSG)
 
945
 
 
946
    def change_archive_fields(self, data):
 
947
        # Update context.main_archive.
 
948
        new_require_virtualized = data.get('require_virtualized')
 
949
        if new_require_virtualized is not None:
 
950
            self.updateRequireVirtualized(
 
951
                new_require_virtualized, self.context.main_archive)
 
952
            del(data['require_virtualized'])
 
953
        new_enabled_restricted_families = data.get(
 
954
            'enabled_restricted_families')
 
955
        if new_enabled_restricted_families is not None:
 
956
            if (set(self.context.main_archive.enabled_restricted_families) !=
 
957
                set(new_enabled_restricted_families)):
 
958
                self.context.main_archive.enabled_restricted_families = (
 
959
                    new_enabled_restricted_families)
 
960
            del(data['enabled_restricted_families'])
 
961
 
 
962
    @action("Change", name='change')
 
963
    def change_action(self, action, data):
 
964
        self.change_archive_fields(data)
 
965
        self.updateContextFromData(data)
 
966
 
859
967
 
860
968
class DistributionSeriesBaseView(LaunchpadView):
861
969
    """A base view to list distroseries."""