def testConstraint(self): def isodd(x): return x % 2 == 1 i = Int(title=u"my constrained integer", constraint=isodd) i.validate(11) self.assertRaises(ConstraintNotSatisfied, i.validate, 10)
def testContextAwareDefaultFactory(self): @provider(IContextAwareDefaultFactory) def getAnswerToUniverse(context): if context is None: return 0 return context.answer field = Int(defaultFactory=getAnswerToUniverse) self.assertEqual(field.default, 0) class Context(object): answer = 42 bound = field.bind(Context()) self.assertEqual(bound.default, 42)
class IReferenceIndexCatalog(zope.interface.Interface): """A catalog of indexes that we want to search for in the referatory.""" author = TextLine( title=_('ireferenceindexcatalog-author-title', u"Author / Uniform Author"), description=_( 'ireferenceindexcatalog-author-desc', u"Search by author. Even matches the author-field of the uniform title." ), required=False, default=u'', ) title = TextLine( title=_('ireferenceindexcatalog-title-title', u"Title / Uniform Title"), description=_('ireferenceindexercatalog-title-desc', u"Search by title or uniform title."), required=False, default=u'', ) post = Int( title=_('ireferenceindexcatalog-post-title', u"Published/Written After"), description=_('ireferenceindexcatalog-post-desc', u"Matches, if published after."), required=False, ) ante = Int( title=_('ireferenceindexcatalog-ante-title', u"Published/Writter Before"), description=_('ireferenceindexcatalog-ante-desc', u"Matsches, if published before."), required=False, ) year = Int( title=_('ireferenceindexcatalog-year-title', u"Year first published"), description=_('ireferenceindexcatalog-year-desc', u"Matches the exact year of origin."), required=False, ) language = TextLine( title=_('ireferenceindexcatalog-language-title', u"Language / Original Language"), description=_('ireferenceindexcatalog-language-desc', u"Search for items by language."), required=False, default=u'', ) edition_year = TextLine( title=_('irefenceindexer-editionyear-title', u"Year of edition"), description=_('ireferenceindexcatalog-edtionyear-desc', u"Matches the year of the edition."), required=True, ) editor = TextLine( title=_('ireferenceindexcatalog-editor-title', u"Editor"), description=_('ireferenceindexcatalog-editor-desc', u"Search by editor."), required=False, default=u'', ) publisher = TextLine( title=_('ireferenceindexcatalog-publisher-title', u"Publisher"), description=_('ireferenceindexcatalog-publisher-desc', u"Search by publisher."), required=False, default=u'', ) address = TextLine( title=_('ireferenceindexcatalog-address-title', u"Address"), description=_('ireferenceindexcatalog-address-desc', u"Search by address of edition (place of publication)."), required=False, default=u'', )
class IReferatory(zope.interface.Interface): """The referatory is a container/folder. It contains all our references. This interface defines the schema part of the referatory.""" _count = Int(title=u"Count", )
class IUniformTitleContainer(zope.interface.Interface): """The uniform title objects go into a destinct container. This interface is the schema part of this container. """ _count = Int(title=u"Count", )
class ISpecificationView(IHasOwner, IHasLinkedBranches): """Specification's attributes and methods that require the permission launchpad.LimitedView. """ name = exported(SpecNameField( title=_('Name'), required=True, readonly=False, description=_( "May contain lower-case letters, numbers, and dashes. " "It will be used in the specification url. " "Examples: mozilla-type-ahead-find, postgres-smart-serial.")), as_of="devel") title = exported(Title( title=_('Title'), required=True, description=_( "Describe the feature as clearly as possible in up to 70 " "characters. This title is displayed in every feature " "list or report.")), as_of="devel") specurl = exported( SpecURLField( title=_('Specification URL'), required=False, description=_( "The URL of the specification. This is usually a wiki page."), constraint=valid_webref), exported_as="specification_url", as_of="devel", ) summary = exported(Summary( title=_('Summary'), required=True, description=_( "A single-paragraph description of the feature. " "This will also be displayed in most feature listings.")), as_of="devel") definition_status = exported(Choice( title=_('Definition Status'), readonly=True, vocabulary=SpecificationDefinitionStatus, default=SpecificationDefinitionStatus.NEW, description=_( "The current status of the process to define the " "feature and get approval for the implementation plan.")), as_of="devel") assignee = exported(PublicPersonChoice( title=_('Assignee'), required=False, description=_("The person responsible for implementing the feature."), vocabulary='ValidPersonOrTeam'), as_of="devel") assigneeID = Attribute('db assignee value') drafter = exported(PublicPersonChoice( title=_('Drafter'), required=False, description=_( "The person responsible for drafting the specification."), vocabulary='ValidPersonOrTeam'), as_of="devel") drafterID = Attribute('db drafter value') approver = exported(PublicPersonChoice( title=_('Approver'), required=False, description=_( "The person responsible for approving the specification, " "and for reviewing the code when it's ready to be landed."), vocabulary='ValidPersonOrTeam'), as_of="devel") approverID = Attribute('db approver value') priority = exported(Choice(title=_('Priority'), vocabulary=SpecificationPriority, default=SpecificationPriority.UNDEFINED, required=True), as_of="devel") datecreated = exported( Datetime(title=_('Date Created'), required=True, readonly=True), as_of="devel", exported_as="date_created", ) owner = exported(PublicPersonChoice(title=_('Owner'), required=True, readonly=True, vocabulary='ValidPersonOrTeam'), as_of="devel") product = Choice(title=_('Project'), required=False, vocabulary='Product') distribution = Choice(title=_('Distribution'), required=False, vocabulary='Distribution') # Exported as readonly for simplicity, but could be exported as read-write # using setTarget() as the mutator. target = exported(ReferenceChoice( title=_('For'), required=True, readonly=True, vocabulary='DistributionOrProduct', description=_("The project for which this proposal is being made."), schema=ISpecificationTarget), as_of="devel") productseries = Choice( title=_('Series Goal'), required=False, vocabulary='FilteredProductSeries', description=_( "Choose a series in which you would like to deliver this " "feature. Selecting '(nothing selected)' will clear the goal.")) distroseries = Choice( title=_('Series Goal'), required=False, vocabulary='FilteredDistroSeries', description=_( "Choose a series in which you would like to deliver this " "feature. Selecting '(nothing selected)' will clear the goal.")) # milestone milestone = exported(ReferenceChoice( title=_('Milestone'), required=False, vocabulary='Milestone', description=_( "The milestone in which we would like this feature to be " "delivered."), schema=IMilestone), as_of="devel") # nomination to a series for release management # XXX: It'd be nice to export goal as read-only, but it's tricky because # users will need to be aware of goalstatus as what's returned by .goal # may not be the accepted goal. goal = Attribute("The series for which this feature is a goal.") goalstatus = Choice( title=_('Goal Acceptance'), vocabulary=SpecificationGoalStatus, default=SpecificationGoalStatus.PROPOSED, description=_( "Whether or not the drivers have accepted this feature as " "a goal for the targeted series.")) goal_proposer = Attribute("The person who nominated the spec for " "this series.") date_goal_proposed = Attribute("The date of the nomination.") goal_decider = Attribute("The person who approved or declined " "the spec a a goal.") date_goal_decided = Attribute("The date the spec was approved " "or declined as a goal.") work_items = List(description=_( "All non-deleted work items for this spec, sorted by " "their 'sequence'"), value_type=Reference(schema=ISpecificationWorkItem), readonly=True) whiteboard = exported(Text( title=_('Status Whiteboard'), required=False, description=_("Any notes on the status of this spec you would like to " "make. Your changes will override the current text.")), as_of="devel") workitems_text = exported(WorkItemsText( title=_('Work Items'), required=False, readonly=True, description=_( "Work items for this specification input in a text format. " "Your changes will override the current work items.")), as_of="devel") direction_approved = exported(Bool( title=_('Basic direction approved?'), required=True, default=False, description=_("Check this to indicate that the drafter and assignee " "have satisfied the approver that they are headed in " "the right basic direction with this specification.")), as_of="devel") man_days = Int( title=_("Estimated Developer Days"), required=False, default=None, description=_( "An estimate of the " "number of developer days it will take to implement this feature. " "Please only provide an estimate if you are relatively confident " "in the number.")) implementation_status = exported(Choice( title=_("Implementation Status"), required=True, readonly=True, default=SpecificationImplementationStatus.UNKNOWN, vocabulary=SpecificationImplementationStatus, description=_("The state of progress being made on the actual " "implementation or delivery of this feature.")), as_of="devel") superseded_by = Choice( title=_("Superseded by"), required=False, default=None, vocabulary='Specification', description=_( "The specification " "which supersedes this one. Note that selecting a specification " "here and pressing Continue will change the specification " "status to Superseded.")) # lifecycle starter = exported(PublicPersonChoice( title=_('Starter'), required=False, readonly=True, description=_( 'The person who first set the state of the ' 'spec to the values that we consider mark it as started.'), vocabulary='ValidPersonOrTeam'), as_of="devel") date_started = exported(Datetime( title=_('Date Started'), required=False, readonly=True, description=_('The date when this spec was marked started.')), as_of="devel") completer = exported(PublicPersonChoice( title=_('Starter'), required=False, readonly=True, description=_( 'The person who finally set the state of the ' 'spec to the values that we consider mark it as complete.'), vocabulary='ValidPersonOrTeam'), as_of="devel") date_completed = exported(Datetime( title=_('Date Completed'), required=False, readonly=True, description=_( 'The date when this spec was marked ' 'complete. Note that complete also includes "obsolete" and ' 'superseded. Essentially, it is the state where no more work ' 'will be done on the feature.')), as_of="devel") # joins subscriptions = Attribute('The set of subscriptions to this spec.') subscribers = Attribute('The set of subscribers to this spec.') sprints = Attribute('The sprints at which this spec is discussed.') sprint_links = Attribute('The entries that link this spec to sprints.') dependencies = exported( CollectionField( title=_('Specs on which this one depends.'), value_type=Reference(schema=Interface), # ISpecification, really. readonly=True), as_of="devel") linked_branches = exported( CollectionField( title=_("Branches associated with this spec, usually " "branches on which this spec is being implemented."), value_type=Reference(schema=Interface), # ISpecificationBranch readonly=True), as_of="devel") def getDependencies(): """Specs on which this one depends.""" def getBlockedSpecs(): """Specs for which this spec is a dependency.""" # emergent properties informational = Attribute('Is True if this spec is purely informational ' 'and requires no implementation.') is_complete = exported(Bool( title=_('Is started'), readonly=True, required=True, description=_( 'Is True if this spec is already completely implemented. ' 'Note that it is True for informational specs, since ' 'they describe general functionality rather than specific ' 'code to be written. It is also true of obsolete and ' 'superseded specs, since there is no longer any need ' 'to schedule work for them.')), as_of="devel") is_incomplete = Attribute( 'Is True if this work still needs to ' 'be done. Is in fact always the opposite of is_complete.') is_blocked = Attribute('Is True if this spec depends on another spec ' 'which is still incomplete.') is_started = exported(Bool( title=_('Is started'), readonly=True, required=True, description=_( 'Is True if the spec is in a state which ' 'we consider to be "started". This looks at the delivery ' 'attribute, and also considers informational specs to be ' 'started when they are approved.')), as_of="devel") lifecycle_status = exported(Choice( title=_('Lifecycle Status'), vocabulary=SpecificationLifecycleStatus, default=SpecificationLifecycleStatus.NOTSTARTED, readonly=True), as_of="devel") def all_deps(): """All the dependencies, including dependencies of dependencies. If a user is provided, filters to only dependencies the user can see. """ def all_blocked(): """All specs blocked on this, and those blocked on the blocked ones. If a user is provided, filters to only blocked dependencies the user can see. """ def validateMove(target): """Check that the specification can be moved to the target.""" def getSprintSpecification(sprintname): """Get the record that links this spec to the named sprint.""" def notificationRecipientAddresses(): """Return the list of email addresses that receive notifications.""" has_accepted_goal = exported(Bool( title=_('Series goal is accepted'), readonly=True, required=True, description=_( 'Is true if this specification has been ' 'proposed as a goal for a specific series, ' 'and the drivers of that series have accepted the goal.')), as_of="devel") # lifecycle management def updateLifecycleStatus(user): """Mark the specification as started, and/or complete, if appropriate. This will verify that the state of the specification is in fact "complete" (there is a completeness test in Specification.is_complete) and then record the completer and the date_completed. If the spec is not completed, then it ensures that nothing is recorded about its completion. It returns a SpecificationLifecycleStatus dbschema showing the overall state of the specification IF the state has changed. """ # event-related methods def getDelta(old_spec, user): """Return a dictionary of things that changed between this spec and the old_spec. This method is primarily used by event subscription code, to determine what has changed during an ObjectModifiedEvent. """ # subscription-related methods def subscription(person): """Return the subscription for this person to this spec, or None.""" @operation_parameters(person=Reference(IPerson, title=_('Person'), required=True), essential=copy_field( ISpecificationSubscription['essential'], required=False)) @call_with(subscribed_by=REQUEST_USER) @export_write_operation() @operation_for_version('devel') def subscribe(person, subscribed_by=None, essential=False): """Subscribe this person to the feature specification.""" @operation_parameters(person=Reference(IPerson, title=_('Person'), required=False)) @call_with(unsubscribed_by=REQUEST_USER) @export_write_operation() @operation_for_version('devel') def unsubscribe(person, unsubscribed_by): """Remove the person's subscription to this spec.""" def getSubscriptionByName(name): """Return a subscription based on the person's name, or None.""" def isSubscribed(person): """Is person subscribed to this spec? Returns True if the user is explicitly subscribed to this spec (no matter what the type of subscription), otherwise False. If person is None, the return value is always False. """ # sprints def linkSprint(sprint, user): """Put this spec on the agenda of the sprint.""" def unlinkSprint(sprint): """Remove this spec from the agenda of the sprint.""" # dependencies def createDependency(specification): """Create a dependency for this spec on the spec provided.""" def removeDependency(specification): """Remove any dependency of this spec on the spec provided.""" # branches def getBranchLink(branch): """Return the SpecificationBranch link for the branch, or None.""" def getLinkedBugTasks(user): """Return the bug tasks that are relevant to this blueprint. When multiple tasks are on a bug, if one of the tasks is for the target, then only that task is returned. Otherwise the default bug task is returned. :param user: The user doing the search. """ def getAllowedInformationTypes(who): """Get a list of acceptable `InformationType`s for this spec."""