Created
August 28, 2018 16:42
-
-
Save chelseatroy/e2d532d2e49481b275766ada41a24650 to your computer and use it in GitHub Desktop.
Example of Calling Giant Conditional in View
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
from __future__ import unicode_literals | |
from django.shortcuts import render | |
from models import Visualization | |
from exceptions import IncompleteDataException | |
from .forms import VisualizationForm | |
from django.contrib.auth.decorators import login_required | |
@login_required | |
def transform(request): | |
name = request.GET['script'] | |
if request.POST and request.FILES: | |
form = VisualizaionForm(request.POST, request.FILES) | |
if form.is_valid(): | |
input_file = request.FILES['file'] | |
image = None | |
try: | |
vizualization = Visualization.objects.get(pk=name) | |
image = vizualization.from_data(name, input_file) | |
except IncompleteDataException as e: | |
return render(request, 'visualizations/form.html', {'error': e.message()}) | |
return render(request, 'visualizations/results.html', {'image': image}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment