Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AddAdForm:
- def __init__(self, category_pk, add_contact_mixin=False):
- self.category = Category.objects.get(pk=category_pk)
- self.form_classes = [(getattr(forms_module, c).__name__.split('_')[1], getattr(forms_module, c))
- for c in dir(forms_module) if c.startswith('Add_')]
- self.add_contact_mixin = add_contact_mixin
- def create(self, *args, **kwargs):
- classes = [c[1] for c in self.form_classes if self.category.ad_class == c[0]]
- if len(classes) == 0:
- raise NoClassFormForCategory(self.category)
- class_obj = classes[0]
- bases = (class_obj,)
- if self.add_contact_mixin and ContactsFormBBMixin not in class_obj.__bases__:
- bases = bases + (ContactsFormBBMixin,)
- class_obj = type('AddForm', bases, {})
- # class_obj = type('__'.join([c.__name__ for c in bases]), bases, {})
- return class_obj(*args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement