Example #1
0
 def get_serializer_class(model_name):
     """Obtener un serializer segĂșn model_name."""
     module = sys.modules[__name__]
     object_model = 'Anuncio{}Serializer'.format(ucfirst(model_name))
     if hasattr(module, object_model):
         return getattr(module, object_model)
     msg_error = 'El serializer {} no ha sido creado'.format(object_model)
     raise NotImplementedError(msg_error)
Example #2
0
    def get_form_class(model_name):
        """Obtener una subclase de BaseAlertForm.

        Obtener una instancia con un nombre de CATEGORY_CHOICES.

        Returns:
            Clase en caso de existir, None en caso contrario.
        """
        module = sys.modules[__name__]
        object_model = 'Alert{}Form'.format(ucfirst(model_name))
        if hasattr(module, object_model):
            return getattr(module, object_model)
Example #3
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['form'] = self.get_form()
     context['category_name'] = ucfirst(self.category)
     return context
Example #4
0
 def test_ucfirst(self):
     """La primera letra en mayusculas."""
     texto = 'hola mundo'
     self.assertEqual(text.ucfirst(texto), 'Hola mundo')