# Path: channelworm/ion_channel/models.py
# class Graph(models.Model):
#     experiment = models.ForeignKey(Experiment, null=True, blank=True, on_delete=models.CASCADE)
#     patch_clamp = models.ForeignKey(PatchClamp, null=True, blank=True, on_delete=models.CASCADE)
# 
#     x_axis_type = models.CharField(max_length=50, choices=Axis_Type_CHOICES)
#     x_axis_unit = models.CharField(max_length=50,verbose_name='Axis unit in the original figure (e.g. ms)')
#     x_axis_toSI = models.FloatField(default=1,verbose_name='Multiply by this value to convert to SI (e.g. 1e-3)')
# 
#     y_axis_type = models.CharField(max_length=50, choices=Axis_Type_CHOICES)
#     y_axis_unit = models.CharField(max_length=50,verbose_name='Axis unit in the original figure (e.g. mV)')
#     y_axis_toSI = models.FloatField(default=1,verbose_name='Multiply by this value to convert to SI (e.g. 1e-3)')
# 
#     ion_channel = models.ManyToManyField(IonChannel)
#     mutants = models.CharField(max_length=300, blank=True, null=True, verbose_name='Additional ion channel mutants (e.g. nf100,n582)')
# 
#     figure_ref_address = models.CharField(max_length=50,verbose_name='Figure number (e.g. 2A)')
#     figure_ref_caption = models.TextField(verbose_name='Figure caption')
#     file = models.ImageField(upload_to='ion_channel/graph/%Y/%m/%d')
# 
#     def __unicode__(self):
#         return str(self.y_axis_type) + "/" + str(self.x_axis_type) + " relation, Fig. " + \
#                str(self.figure_ref_address) + ", From:  " + self.experiment.reference.citation + \
#                ", " + self.experiment.reference.year


import json
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from channelworm.ion_channel.models import Graph



# Create your views here.

def index(request):
    return render(request, 'digitizer/index.html')


def digitize(request, graph_id):
    graph = get_object_or_404(Graph, pk=graph_id)
    return render(request, 'digitizer/index.html', {'graph': graph})


def csv_export(request):
    data = request.POST.get("data")

# Path: channelworm/ion_channel/models.py
# class Graph(models.Model):
#     experiment = models.ForeignKey(Experiment, null=True, blank=True, on_delete=models.CASCADE)
#     patch_clamp = models.ForeignKey(PatchClamp, null=True, blank=True, on_delete=models.CASCADE)
# 
#     x_axis_type = models.CharField(max_length=50, choices=Axis_Type_CHOICES)
#     x_axis_unit = models.CharField(max_length=50,verbose_name='Axis unit in the original figure (e.g. ms)')
#     x_axis_toSI = models.FloatField(default=1,verbose_name='Multiply by this value to convert to SI (e.g. 1e-3)')
# 
#     y_axis_type = models.CharField(max_length=50, choices=Axis_Type_CHOICES)
#     y_axis_unit = models.CharField(max_length=50,verbose_name='Axis unit in the original figure (e.g. mV)')
#     y_axis_toSI = models.FloatField(default=1,verbose_name='Multiply by this value to convert to SI (e.g. 1e-3)')
# 
#     ion_channel = models.ManyToManyField(IonChannel)
#     mutants = models.CharField(max_length=300, blank=True, null=True, verbose_name='Additional ion channel mutants (e.g. nf100,n582)')
# 
#     figure_ref_address = models.CharField(max_length=50,verbose_name='Figure number (e.g. 2A)')
#     figure_ref_caption = models.TextField(verbose_name='Figure caption')
#     file = models.ImageField(upload_to='ion_channel/graph/%Y/%m/%d')
# 
#     def __unicode__(self):
#         return str(self.y_axis_type) + "/" + str(self.x_axis_type) + " relation, Fig. " + \
#                str(self.figure_ref_address) + ", From:  " + self.experiment.reference.citation + \
#                ", " + self.experiment.reference.year


# Path: channelworm/digitizer/views.py
import json
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from channelworm.ion_channel.models import Graph




# Create your views here.

def index(request):
    return render(request, 'digitizer/index.html')


def digitize(request, graph_id):
    graph = get_object_or_404(Graph, pk=graph_id)
    return render(request, 'digitizer/index.html', {'graph': graph})


def csv_export(request):
    data = request.POST.get("data")

    file_name = request.POST.get("filename")