class ISearchMilestoneTagsForm(Interface): """Schema for the search milestone tags form.""" tags = TextLine(title=_('Search by tags'), description=_('Insert space separated tag names'), required=True, min_length=2, max_length=64, constraint=lambda value: validate_tags(value.split()))
def extendFields(self): """See `LaunchpadFormView`. Add a text-entry widget for milestone tags since there is not property on the interface. """ tag_entry = TextLine( __name__='tags', title=u'Tags', required=False, constraint=lambda value: validate_tags(value.split())) self.form_fields += form.Fields( tag_entry, render_context=self.render_context) # Make an instance attribute to avoid mutating the class attribute. self.field_names = getattr(self, '_field_names', self.field_names)[:] # Insert the tags field before the summary. summary_index = self.field_names.index('summary') self.field_names.insert(summary_index, tag_entry.__name__)
def extendFields(self): """See `LaunchpadFormView`. Add a text-entry widget for milestone tags since there is not property on the interface. """ tag_entry = TextLine( __name__='tags', title=u'Tags', required=False, constraint=lambda value: validate_tags(value.split())) self.form_fields += form.Fields(tag_entry, render_context=self.render_context) # Make an instance attribute to avoid mutating the class attribute. self.field_names = getattr(self, '_field_names', self.field_names)[:] # Insert the tags field before the summary. summary_index = self.field_names.index('summary') self.field_names.insert(summary_index, tag_entry.__name__)
def setTags(self, tags, user): """See IMilestone.""" # Circular reference prevention. from lp.registry.model.milestonetag import MilestoneTag, validate_tags store = Store.of(self) if tags: if not validate_tags(tags): raise InvalidTags() current_tags = set(self.getTags()) new_tags = set(tags) if new_tags == current_tags: return # Removing deleted tags. to_remove = current_tags.difference(new_tags) if to_remove: store.find( MilestoneTag, MilestoneTag.tag.is_in(to_remove)).remove() # Adding new tags. for tag in new_tags.difference(current_tags): store.add(MilestoneTag(self, tag, user)) else: store.find( MilestoneTag, MilestoneTag.milestone_id == self.id).remove()
def setTags(self, tags, user): """See IMilestone.""" # Circular reference prevention. from lp.registry.model.milestonetag import MilestoneTag, validate_tags store = Store.of(self) if tags: if not validate_tags(tags): raise InvalidTags() current_tags = set(self.getTags()) new_tags = set(tags) if new_tags == current_tags: return # Removing deleted tags. to_remove = current_tags.difference(new_tags) if to_remove: store.find(MilestoneTag, MilestoneTag.tag.is_in(to_remove)).remove() # Adding new tags. for tag in new_tags.difference(current_tags): store.add(MilestoneTag(self, tag, user)) else: store.find(MilestoneTag, MilestoneTag.milestone_id == self.id).remove()
def traverse_tags(self, name): tags = name.split(u',') if validate_tags(tags): return ProjectGroupMilestoneTag(self.context, tags)
def traverse_tags(self, name): tags = name.split(u',') if validate_tags(tags): return ProjectGroupMilestoneTag(self.context, tags)