Advertisement
Guest User

Untitled

a guest
Oct 31st, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. class AddAdForm:
  2.     def __init__(self, category_pk, add_contact_mixin=False):
  3.         self.category = Category.objects.get(pk=category_pk)
  4.         self.form_classes = [(getattr(forms_module, c).__name__.split('_')[1], getattr(forms_module, c))
  5.                              for c in dir(forms_module) if c.startswith('Add_')]
  6.         self.add_contact_mixin = add_contact_mixin
  7.  
  8.     def create(self, *args, **kwargs):
  9.         classes = [c[1] for c in self.form_classes if self.category.ad_class == c[0]]
  10.         if len(classes) == 0:
  11.             raise NoClassFormForCategory(self.category)
  12.         class_obj = classes[0]
  13.  
  14.         bases = (class_obj,)
  15.  
  16.         if self.add_contact_mixin and ContactsFormBBMixin not in class_obj.__bases__:
  17.             bases = bases + (ContactsFormBBMixin,)
  18.  
  19.         class_obj = type('AddForm', bases, {})
  20.         # class_obj = type('__'.join([c.__name__ for c in bases]), bases, {})
  21.  
  22.         return class_obj(*args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement