~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/answers/browser/question.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-23 23:33:29 UTC
  • mfrom: (14022.1.7 valid-targets-1)
  • Revision ID: launchpad@pqm.canonical.com-20110923233329-3h43u5amuvd1yiee
[r=bac][bug=857448, 164424,
        117525] Restrict the target widget to pillars that use Launchpad

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
    IAnswersFrontPageSearchForm,
98
98
    IQuestionTarget,
99
99
    )
 
100
from lp.answers.vocabulary import UsesAnswersDistributionVocabulary
100
101
from lp.app.browser.launchpadform import (
101
102
    action,
102
103
    custom_widget,
725
726
    cancel_url = next_url
726
727
 
727
728
 
 
729
class QuestionTargetWidget(LaunchpadTargetWidget):
 
730
    """A targeting widget that is aware of pillars that use Answers."""
 
731
 
 
732
    def getDistributionVocabulary(self):
 
733
        distro = self.context.context.distribution
 
734
        vocabulary = UsesAnswersDistributionVocabulary(distro)
 
735
        return vocabulary
 
736
 
 
737
 
728
738
class QuestionEditView(LaunchpadEditFormView):
729
739
    """View for editing a Question."""
730
740
    schema = IQuestion
735
745
 
736
746
    custom_widget('title', TextWidget, displayWidth=40)
737
747
    custom_widget('whiteboard', TextAreaWidget, height=5)
738
 
    custom_widget('target', LaunchpadTargetWidget)
 
748
    custom_widget('target', QuestionTargetWidget)
739
749
 
740
750
    @property
741
751
    def page_title(self):
762
772
    @action(_("Save Changes"), name="change")
763
773
    def change_action(self, action, data):
764
774
        """Update the Question from the request form data."""
 
775
        # Target must be the last field processed because it implicitly
 
776
        # changes the user's permissions.
 
777
        target_data = {'target': self.context.target}
 
778
        if 'target' in data:
 
779
            target_data['target'] = data['target']
 
780
            del data['target']
765
781
        self.updateContextFromData(data)
 
782
        if target_data['target'] != self.context.target:
 
783
            self.updateContextFromData(target_data)
766
784
 
767
785
    @property
768
786
    def next_url(self):