Demo entry 6785018

Codice Python

   

Submitted by anonymous on Mar 12, 2019 at 13:07
Language: Python. Code size: 2.1 kB.

class BaseActivities(object):
    _allowed_models = []
    _model_to_classes = {}
    @classmethod
    def register(cls, activity_class, model):
        model_path = "{}.{}".format(model.app_label, model.model_name)
        assert model_path in cls._allowed_models, \
            "Model '{}' not allowed for class '{}'".format(model_path, activity_class)
        if model not in cls._model_to_classes:
            cls._model_to_classes[model] = []
        cls._model_to_classes[model].append(activity_class)
    @classmethod
    def get_for_model(cls, model):
        """Returns activity classes registered by model"""
        return cls._model_to_classes.get(model, [])
    @classmethod
    def is_registered(cls, model):
        """Returns if a model is registered"""
        return cls in cls._model_to_classes.get(model, [])
    @classmethod
    def get_data(cls, model, ids):
        """Returns activities’ aggregated data"""
    @classmethod
    def get_data_details(cls, model, ids):
        """Returns activities’ details"""

class BaseWarnings(object):
    _allowed_models = []
    _model_to_classes = {}
    @classmethod
    def register(cls, warning_class, model):
        model_path = "{}.{}".format(model.app_label, model.model_name)
        assert model_path in cls._allowed_models, \
            "Model '{}' not allowed for class '{}'".format(model_path, warning_class)
        if model not in cls._model_to_classes:
            cls._model_to_classes[model] = []
        cls._model_to_classes[model].append(warning_class)
    @classmethod
    def get_for_model(cls, model):
        """Returns warning classes registered by model"""
        return cls._model_to_classes.get(model, [])
    @classmethod
    def is_registered(cls, model):
        """Returns if a model is registered"""
        return cls in cls._model_to_classes.get(model, [])
    @classmethod
    def get_data(cls, model, ids):
        """Returns warnings’ aggregated data"""
    @classmethod
    def get_data_details(cls, model, ids):
        """Returns warnings’ details"""

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).