From 5de3f74a88310d129fd24a867950ff8567fa7d69 Mon Sep 17 00:00:00 2001 From: evilchili Date: Wed, 31 Jan 2024 23:05:46 -0800 Subject: [PATCH] simplified post handling --- ttfrog/db/base.py | 2 -- ttfrog/webserver/controllers/base.py | 30 ++++++---------------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/ttfrog/db/base.py b/ttfrog/db/base.py index e3c8de8..bd69e51 100644 --- a/ttfrog/db/base.py +++ b/ttfrog/db/base.py @@ -1,5 +1,3 @@ -from itertools import chain - from pyramid_sqlalchemy import BaseObject from wtforms import validators diff --git a/ttfrog/webserver/controllers/base.py b/ttfrog/webserver/controllers/base.py index 48a592a..3e511d5 100644 --- a/ttfrog/webserver/controllers/base.py +++ b/ttfrog/webserver/controllers/base.py @@ -1,4 +1,3 @@ -import logging from collections import defaultdict from wtforms_sqlalchemy.orm import model_form @@ -26,7 +25,6 @@ class BaseController: def configure(self): self.load_from_id() - def load_from_id(self): if not self.request.POST['id']: return @@ -37,28 +35,12 @@ class BaseController: if not self.model: return '' - # no user submission to process - if self.request.method != 'POST': - return self.model_form(obj=self.record) - - # process submission - form = self.model_form(self.request.POST, obj=self.record) - if self.model.validate(form): - form.populate_obj(self.record) - error = self.save_changes() - if error: - form.errors['process'] = error - return form - - def save_changes(self): - try: - with db.transaction(): - for (key, val) in self.request.POST.items(): - if hasattr(self.record, key): - setattr(self.record, key, val) - except Exception as e: - return e - return None + if self.request.method == 'POST': + form = self.model_form(self.request.POST, obj=self.record) + if self.model.validate(form): + form.populate_obj(self.record) + return form + return self.model_form(obj=self.record) def output(self, **kwargs) -> dict: return dict(