def auto_tag(self): """Apply tags to myself that are implied by my metadata. You don't need to call save on the question after this. """ to_add = self.product.get('tags', []) + self.category.get('tags', []) version = self.metadata.get('ff_version', '') dev_releases = product_details.firefox_history_development_releases if version in dev_releases or \ version in product_details.firefox_history_stability_releases or \ version in product_details.firefox_history_major_releases: to_add.append('Firefox %s' % version) tenths = _tenths_version(version) if tenths: to_add.append('Firefox %s' % tenths) elif _has_beta(version, dev_releases): to_add.append('Firefox %s' % version) to_add.append('beta') self.tags.add(*to_add) # Add a tag for the OS if it already exists as a tag: os = self.metadata.get('os') if os: try: add_existing_tag(os, self.tags) except Tag.DoesNotExist: pass
def auto_tag(self): """Apply tags to myself that are implied by my metadata. You don't need to call save on the question after this. """ to_add = self.product.get('tags', []) + self.category.get('tags', []) version = self.metadata.get('ff_version', '') if version in product_details.firefox_history_development_releases or \ version in product_details.firefox_history_stability_releases or \ version in product_details.firefox_history_major_releases: to_add.append('Firefox %s' % version) tenths = _tenths_version(version) if tenths: to_add.append('Firefox %s' % tenths) self.tags.add(*to_add) # Add a tag for the OS if it already exists as a tag: os = self.metadata.get('os') if os: try: add_existing_tag(os, self.tags) except Tag.DoesNotExist: pass
def auto_tag(self): """Apply tags to myself that are implied by my metadata. You don't need to call save on the question after this. """ to_add = self.product.get('tags', []) + self.category.get('tags', []) version = self.metadata.get('ff_version', '') # Remove the beta (b*), aurora (a2) or nightly (a1) suffix. version = re.split('[a-b]', version)[0] dev_releases = product_details.firefox_history_development_releases if version in dev_releases or \ version in product_details.firefox_history_stability_releases or \ version in product_details.firefox_history_major_releases: to_add.append('Firefox %s' % version) tenths = _tenths_version(version) if tenths: to_add.append('Firefox %s' % tenths) elif _has_beta(version, dev_releases): to_add.append('Firefox %s' % version) to_add.append('beta') self.tags.add(*to_add) # Add a tag for the OS if it already exists as a tag: os = self.metadata.get('os') if os: try: add_existing_tag(os, self.tags) except Tag.DoesNotExist: pass
def auto_tag(self): """Apply tags to myself that are implied by my metadata. You don't need to call save on the question after this. """ to_add = self.product.get("tags", []) + self.category.get("tags", []) version = self.metadata.get("ff_version", "") if ( version in product_details.firefox_history_development_releases or version in product_details.firefox_history_stability_releases or version in product_details.firefox_history_major_releases ): to_add.append("Firefox %s" % version) tenths = _tenths_version(version) if tenths: to_add.append("Firefox %s" % tenths) self.tags.add(*to_add) # Add a tag for the OS if it already exists as a tag: os = self.metadata.get("os") if os: try: add_existing_tag(os, self.tags) except Tag.DoesNotExist: pass
def _add_tag(request, question_id): """Add a named tag to a question, creating it first if appropriate. Tag name (case-insensitive) must be in request.POST['tag-name']. If there is no such tag and the user is not allowed to make new tags, raise Tag.DoesNotExist. If no tag name is provided, return None. Otherwise, return the canonicalized tag name. """ tag_name = request.POST.get('tag-name', '').strip() if tag_name: question = get_object_or_404(Question, pk=question_id) try: canonical_name = add_existing_tag(tag_name, question.tags) except Tag.DoesNotExist: if request.user.has_perm('taggit.add_tag'): question.tags.add(tag_name) # implicitly creates if needed return tag_name raise return canonical_name
def test_add_existing_no_such_tag(self): """Assert add_existing_tag doesn't work when the tag doesn't exist.""" add_existing_tag('nonexistent tag', self.untagged_question.tags)
def test_add_existing_case_insensitive(self): """Assert add_existing_tag works case-insensitively.""" add_existing_tag('LEMON', self.untagged_question.tags) tags_eq(self.untagged_question, [u'lemon'])