arturrro

Untitled

Sep 15th, 2020
751
27 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ProjectAutoCalculation:
  2.  
  3.     # funkcje byłyby zdefiniowane w oddzielnym module, np. project_auto_calculations
  4.     model_to_func = {
  5.         ProjectBenefit: [func1, func2],
  6.         ProjectGoal: [func1],
  7.         ProjectMilestone: [func3, func4]
  8.     }
  9.  
  10.     def __init__(self, project, model, **extra):
  11.         self.model = model
  12.         self.project = project
  13.         self.extra = extra
  14.  
  15.     def determine(self):
  16.         for func in self.model_to_func[model]:
  17.             func(project, **extra)
  18.  
  19.  
  20. class ProjectAutoCalculationMixin:
  21.  
  22.     def save(self, commit=False):
  23.         super(ProjectAutoCalculationMixin, self).save(commit)
  24.         ProjectAutoCalculation(project, model).determine()
  25.  
  26.  
  27. class ProjectGoal(ProjectAutoCalculationMixin, form.ModelForm):
  28.     pass
  29.  
RAW Paste Data