-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from VisLab/develop
Refactoring to separate operations from form processing
- Loading branch information
Showing
33 changed files
with
2,112 additions
and
2,007 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,26 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
class ProcessBase(ABC): | ||
def set_input_from_dict(self, input_dict): | ||
""" Sets the child class attributes based on input_dict. | ||
Only sets attributes that exist. | ||
parameters: | ||
input_dict (dict): A dict object containing user data from a JSON service request. | ||
""" | ||
# Only allowed to set variables from init, and also disallow private variables to avoid possible issues | ||
for key, value in input_dict.items(): | ||
if not hasattr(self, key) or callable(getattr(self, key)) or key.startswith("_"): | ||
continue | ||
setattr(self, key, value) | ||
|
||
@abstractmethod | ||
def set_input_from_form(self, request): | ||
""" Set input for processing from a form. | ||
parameters: | ||
request (Request): A Request object containing user data from the form. | ||
""" | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def process(self): | ||
""" Perform the requested string processing action. | ||
Returns: | ||
dict: The results in standard format. | ||
""" | ||
raise NotImplementedError | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class BaseOperations(ABC): | ||
def set_input_from_dict(self, input_dict): | ||
""" Sets the child class attributes based on input_dict. | ||
Only sets attributes that exist. | ||
parameters: | ||
input_dict (dict): A dict object containing user data from a JSON service request. | ||
""" | ||
# Only allowed to set variables from init, and also disallow private variables to avoid possible issues | ||
for key, value in input_dict.items(): | ||
if not hasattr(self, key) or callable(getattr(self, key)) or key.startswith("_"): | ||
continue | ||
setattr(self, key, value) | ||
|
||
@abstractmethod | ||
def process(self): | ||
""" Perform the requested string processing action. | ||
Returns: | ||
dict: The results in standard format. | ||
""" | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.