Exemple #1
0
 def get_form_class(self):
     # We need to lookup the volume so we know which volume to assign the component to
     self.volume = get_objects_for_user(self.request.user, 'p2_core.view_volume') \
         .filter(pk=self.kwargs.get('pk')).first()
     controller_path = self.request.GET.get('controller')
     if controller_path in COMPONENT_MANAGER:
         controller = path_to_class(controller_path)
         self.controller_path = controller_path
         return path_to_class(
             controller(Component(volume=self.volume)).form_class)
     raise Http404
Exemple #2
0
def signal_marshall(self, signal, args=None, kwargs=None):
    """Run signal in task worker"""
    if not args:
        args = []
    if not kwargs:
        kwargs = {}
    # Lookup PK to model instance
    for key, value in kwargs.items():
        if 'class' in value and 'pk' in value:
            model_class = path_to_class(value.get('class'))
            model_instance = model_class.objects.get(pk=value.get('pk'))
            kwargs[key] = model_instance
    signal_cls = path_to_class(signal)
    signal_cls.send(sender=self, *args, **kwargs)
Exemple #3
0
 def clean_tags(self):
     controller_class = path_to_class(
         self.cleaned_data.get('controller_path'))
     controller = controller_class(self.instance)
     for key in controller.get_required_tags():
         if key not in self.cleaned_data.get('tags'):
             raise forms.ValidationError("Tag '%s' missing." % key)
     return self.cleaned_data.get('tags')
Exemple #4
0
 def __actual_load(self):
     """Make sure classes are loaded"""
     if not self.__loaded:
         # Make sure all controllers are imported
         for controller in CONFIG.y(self.__config_path, []):
             self.__class_list.append(path_to_class(controller))
             self.__class_path_list.append(controller)
         self.__loaded = True
Exemple #5
0
 def controller(self):
     """Get instantiated controller class"""
     if not self._controller_instance:
         controller_class = path_to_class(self.controller_path)
         try:
             self._controller_instance = controller_class(self)
         except (TypeError, ImportError) as exc:
             LOGGER.warning(exc)
     return self._controller_instance
Exemple #6
0
 def get_form_class(self):
     return path_to_class(self.object.controller.form_class)
Exemple #7
0
 def controller(self):
     """Get instantiated controller class"""
     if not self._controller_instance:
         controller_class = path_to_class(self.controller_path)
         self._controller_instance = controller_class(self)
     return self._controller_instance
Exemple #8
0
def get_attribute(blob, path):
    """Access blob.attributes but allow keys like 'site:bytes"""
    return blob.attributes.get(path_to_class(path))