def _handle_recipe_set(self, xmlrecipeSet, user, ignore_missing_tasks=False): """ Handles the processing of recipesets into DB entries from their xml """ recipeSet = RecipeSet(ttasks=0) recipeset_priority = xmlrecipeSet.get_xml_attr('priority',unicode,None) if recipeset_priority is not None: try: my_priority = TaskPriority.from_string(recipeset_priority) except InvalidRequestError: raise BX(_('You have specified an invalid recipeSet priority:%s' % recipeset_priority)) allowed_priorities = RecipeSet.allowed_priorities_initial(user) if my_priority in allowed_priorities: recipeSet.priority = my_priority else: recipeSet.priority = TaskPriority.default_priority() else: recipeSet.priority = TaskPriority.default_priority() for xmlrecipe in xmlrecipeSet.iter_recipes(): recipe = self.handleRecipe(xmlrecipe, user, ignore_missing_tasks=ignore_missing_tasks) recipe.ttasks = len(recipe.tasks) recipeSet.ttasks += recipe.ttasks recipeSet.recipes.append(recipe) # We want the guests to be part of the same recipeSet for guest in recipe.guests: recipeSet.recipes.append(guest) guest.ttasks = len(guest.tasks) recipeSet.ttasks += guest.ttasks if not recipeSet.recipes: raise BX(_('No Recipes! You can not have a recipeSet with no recipes!')) return recipeSet
def _update_recipeset(recipeset, data=None): if not data: data = {} def record_activity(field, old=None, new=None, action=u'Changed'): recipeset.record_activity(user=identity.current.user, service=u'HTTP', action=action, field=field, old=old, new=new) with convert_internal_errors(): if 'priority' in data: priority = TaskPriority.from_string(data['priority']) if priority != recipeset.priority: if not recipeset.can_change_priority(identity.current.user): raise Forbidden403('Cannot change recipe set %s priority' % recipeset.id) allowed = recipeset.allowed_priorities(identity.current.user) if priority not in allowed: raise Forbidden403( 'Cannot set recipe set %s priority to %s, ' 'permitted priorities are: %s' % (recipeset.id, priority, ' '.join( unicode(pri) for pri in allowed))) record_activity(u'Priority', old=recipeset.priority.value, new=priority.value) recipeset.priority = priority if 'waived' in data: if not isinstance(data['waived'], bool): raise ValueError('waived key must be true or false') waived = data['waived'] if waived != recipeset.waived: if not recipeset.can_waive(identity.current.user): raise Forbidden403('Cannot waive recipe set %s' % recipeset.id) record_activity(u'Waived', old=unicode(recipeset.waived), new=unicode(waived)) recipeset.waived = waived
def _handle_recipe_set(self, xmlrecipeSet, user, ignore_missing_tasks=False): """ Handles the processing of recipesets into DB entries from their xml """ recipeSet = RecipeSet(ttasks=0) recipeset_priority = xmlrecipeSet.get_xml_attr('priority', unicode, None) if recipeset_priority is not None: try: my_priority = TaskPriority.from_string(recipeset_priority) except InvalidRequestError: raise BX( _('You have specified an invalid recipeSet priority:%s' % recipeset_priority)) allowed_priorities = RecipeSet.allowed_priorities_initial(user) if my_priority in allowed_priorities: recipeSet.priority = my_priority else: recipeSet.priority = TaskPriority.default_priority() else: recipeSet.priority = TaskPriority.default_priority() for xmlrecipe in xmlrecipeSet.iter_recipes(): recipe = self.handleRecipe( xmlrecipe, user, ignore_missing_tasks=ignore_missing_tasks) recipe.ttasks = len(recipe.tasks) recipeSet.ttasks += recipe.ttasks recipeSet.recipes.append(recipe) # We want the guests to be part of the same recipeSet for guest in recipe.guests: recipeSet.recipes.append(guest) guest.ttasks = len(guest.tasks) recipeSet.ttasks += guest.ttasks if not recipeSet.recipes: raise BX( _('No Recipes! You can not have a recipeSet with no recipes!')) return recipeSet