Update get method and add post method.

This commit is contained in:
Christophe Boulanger 2016-06-03 14:59:23 +02:00
parent 2cfa762903
commit 6670350735
1 changed files with 14 additions and 3 deletions

View File

@ -14,8 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import requests
import unicodedata
import json
from django.views.generic.detail import SingleObjectMixin, DetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
@ -28,6 +28,7 @@ from passerelle import utils
from .models import ImioTsTaxCompute
from .forms import ImioTsTaxComputeForm
class SigCreateView(CreateView):
model = ImioTsTaxCompute
form_class = ImioTsTaxComputeForm
@ -54,5 +55,15 @@ class EvalView(View, SingleObjectMixin):
model = ImioTsTaxCompute
def get(self, request, *args, **kwargs):
result = eval(self.get_object().formule)
return self.post(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
data = dict([(x, request.GET[x]) for x in request.GET.keys()])
if request.body:
payload = json.loads(request.body)
data.update(payload.get("fields"))
expression = self.get_object().formule
code_object = compile(expression, "<string>", "exec")
eval(code_object, data)
result = data.get("result")
return utils.response_for_json(request, {'data': result})