Exemplo n.º 1
0
def add_categories(bundle, *submitted_categories):
    """
            When the user updates the values of one or more categories, we assume that they want to delete the current Category instances with the same keys and replace them with the selected Category value. For instance, if a scenario has the Category key:'category' value:'smart' and the user chooses 'dumb' for the new value, we want to delete the Category instance valued by 'smart' and insert the one valued by 'dumb'. But we don't want to mess with Category instances that have different keys
    """
    logger = logging.getLogger(__name__)
    try:
        submitted_categories_by_key = map_to_keyed_collections(lambda category: category.key, submitted_categories)
        existing_categories_by_key = map_to_keyed_collections(lambda category: category.key, bundle.obj.categories.all())
        categories_to_add_or_maintain = flat_map_values(lambda key, categories: unique(categories, lambda category: category.value),
                                                        merge(existing_categories_by_key, submitted_categories_by_key))
        bundle.obj.categories.clear()
        bundle.obj.categories.add(*categories_to_add_or_maintain)
    except Exception, e:
        logger.critical(e.message)
Exemplo n.º 2
0
def add_categories(bundle, *submitted_categories):
    """
            When the user updates the values of one or more categories, we assume that they want to delete the current Category instances with the same keys and replace them with the selected Category value. For instance, if a scenario has the Category key:'category' value:'smart' and the user chooses 'dumb' for the new value, we want to delete the Category instance valued by 'smart' and insert the one valued by 'dumb'. But we don't want to mess with Category instances that have different keys
    """
    logger = logging.getLogger(__name__)
    try:
        submitted_categories_by_key = map_to_keyed_collections(lambda category: category.key, submitted_categories)
        existing_categories_by_key = map_to_keyed_collections(lambda category: category.key, bundle.obj.categories.all())
        categories_to_add_or_maintain = flat_map_values(lambda key, categories: unique(categories, lambda category: category.value),
                                                        merge(existing_categories_by_key, submitted_categories_by_key))
        bundle.obj.categories.clear()
        bundle.obj.categories.add(*categories_to_add_or_maintain)
    except Exception, e:
        logger.critical(e.message)
Exemplo n.º 3
0
 def dehydrate_presentations(self, bundle):
     """
         Separates the presentations by type into a dict to make them easier to digest on the client.
         Any Presentation of type Presentations goes under 'maps'. Any of type ResultPage goes under 'results'. This
         is done because Sproutcore can't easily handle having multiple classes in a single list. But really, it's
         better for an API consumer to see them separated anyway.
     :param bundle:
     :return:
     """
     return map_to_keyed_collections(lambda presentation_uri: self.map_uri_to_class_key(presentation_uri), bundle.data['presentations'])
Exemplo n.º 4
0
 def dehydrate_presentations(self, bundle):
     """
         Separates the presentations by type into a dict to make them easier to digest on the client.
         Any Presentation of type Presentations goes under 'maps'. Any of type ResultPage goes under 'results'. This
         is done because Sproutcore can't easily handle having multiple classes in a single list. But really, it's
         better for an API consumer to see them separated anyway.
     :param bundle:
     :return:
     """
     return map_to_keyed_collections(lambda presentation_uri: self.map_uri_to_class_key(presentation_uri), bundle.data['presentations'])