@@ -0,0 +1,96 | |||
|
1 | ||
|
2 | import ast | |
|
3 | import json | |
|
4 | from itertools import chain | |
|
5 | ||
|
6 | from django import forms | |
|
7 | from django.utils.safestring import mark_safe | |
|
8 | from django.utils.encoding import force_unicode | |
|
9 | from django.utils.html import conditional_escape | |
|
10 | ||
|
11 | ||
|
12 | class SpectralWidget(forms.widgets.TextInput): | |
|
13 | ||
|
14 | def render(self, label, value, attrs=None): | |
|
15 | ||
|
16 | disabled = 'disabled' if attrs.get('disabled', False) else '' | |
|
17 | name = attrs.get('name', label) | |
|
18 | if '[' in value: | |
|
19 | value = ast.literal_eval(value) | |
|
20 | ||
|
21 | codes = value | |
|
22 | if not isinstance(value, list): | |
|
23 | if len(value) > 1: | |
|
24 | text='' | |
|
25 | for val in value: | |
|
26 | text = text+str(val)+',' | |
|
27 | codes=text | |
|
28 | else: | |
|
29 | codes=value+"," | |
|
30 | ||
|
31 | html = '''<textarea rows="5" {0} class="form-control" id="id_{1}" name="{2}" style="white-space:nowrap; overflow:scroll;">{3}</textarea> | |
|
32 | <input type="text" class="col-md-1 col-no-padding" id="num1" value=0> | |
|
33 | <input type="text" class="col-md-1 col-no-padding" id="num2" value=0> | |
|
34 | <button type="button" class="button" id="add_spectral_button"> Add </button> | |
|
35 | <button type="button" class="button" id="all_spectral_button"> All </button> | |
|
36 | <button type="button" class="button" id="self_spectral_button"> Self </button> | |
|
37 | <button type="button" class="button" id="cross_spectral_button"> Cross </button> | |
|
38 | <button type="button" class="button" id="delete_spectral_button"> Delete </button> | |
|
39 | '''.format(disabled, label, name, codes) | |
|
40 | ||
|
41 | script = ''' | |
|
42 | <script type="text/javascript"> | |
|
43 | $(document).ready(function () {{ | |
|
44 | ||
|
45 | var spectral_number1 = $("#num1").val(); | |
|
46 | var spectral_number2 = $("#num2").val(); | |
|
47 | ||
|
48 | ||
|
49 | $("#all_spectral_button").click(function(){{ | |
|
50 | alert(spectral_comb) | |
|
51 | }}); | |
|
52 | ||
|
53 | $("#add_spectral_button").click(function(){{ | |
|
54 | var spectral_comb = $("#id_spectral").val(); | |
|
55 | var spectral_number1 = $("#num1").val(); | |
|
56 | var spectral_number2 = $("#num2").val(); | |
|
57 | var str = spectral_number1+", "+spectral_number2; | |
|
58 | //not to duplicate | |
|
59 | var n = spectral_comb.search(str); | |
|
60 | if (n==-1){ | |
|
61 | $("#id_spectral").val(spectral_comb+"["+$("#num1").val()+", "+$("#num2").val()+"],") | |
|
62 | } | |
|
63 | }}); | |
|
64 | ||
|
65 | $("#delete_spectral_button").click(function(){{ | |
|
66 | var spectral_comb = $("#id_spectral").val(); | |
|
67 | var spectral_number1 = $("#num1").val(); | |
|
68 | var spectral_number2 = $("#num2").val(); | |
|
69 | var str = spectral_number1+", "+spectral_number2; | |
|
70 | var n = spectral_comb.search(str); | |
|
71 | if (n==-1){ | |
|
72 | ||
|
73 | } | |
|
74 | else { | |
|
75 | n= spectral_comb.length; | |
|
76 | if (n<8){ | |
|
77 | var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"]," | |
|
78 | var txt = spectral_comb.replace(tuple,''); | |
|
79 | } | |
|
80 | else { | |
|
81 | var tuple = ",["+$("#num1").val()+", "+$("#num2").val()+"]" | |
|
82 | var txt = spectral_comb.replace(tuple,''); | |
|
83 | } | |
|
84 | $("#id_spectral").val(txt) | |
|
85 | ||
|
86 | var tuple = "["+$("#num1").val()+", "+$("#num2").val()+"]," | |
|
87 | var txt = spectral_comb.replace(tuple,''); | |
|
88 | $("#id_spectral").val(txt) | |
|
89 | } | |
|
90 | }}); | |
|
91 | ||
|
92 | }}); | |
|
93 | </script> | |
|
94 | ''' | |
|
95 | ||
|
96 | return mark_safe(html+script) No newline at end of file |
@@ -1,6 +1,7 | |||
|
1 | 1 | from django import forms |
|
2 | 2 | from apps.main.models import Device, Experiment |
|
3 | 3 | from .models import JARSConfiguration |
|
4 | from .widgets import SpectralWidget | |
|
4 | 5 | |
|
5 | 6 | class JARSConfigurationForm(forms.ModelForm): |
|
6 | 7 | def __init__(self, *args, **kwargs): |
@@ -15,6 +16,7 class JARSConfigurationForm(forms.ModelForm): | |||
|
15 | 16 | self.fields['experiment'].widget.choices = [(experiment.id, experiment) for experiment in experiments] |
|
16 | 17 | |
|
17 | 18 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
19 | self.fields['spectral'].widget = SpectralWidget() | |
|
18 | 20 | |
|
19 | 21 | #-------------JARS Configuration needs an Experiment----------------- |
|
20 | 22 | def clean(self): |
@@ -49,7 +49,7 class JARSConfiguration(Configuration): | |||
|
49 | 49 | incohe_integr = models.PositiveIntegerField(verbose_name='Incoherent Integrations',validators=[MinValueValidator(1)], default = 30) |
|
50 | 50 | filter = models.ForeignKey(JARSfilter, on_delete=models.CASCADE, null=True, blank=True) |
|
51 | 51 | spectral_number = models.PositiveIntegerField(verbose_name='# Spectral Combinations',validators=[MinValueValidator(1)], null=True, blank=True) |
|
52 |
spectral = models.CharField(verbose_name='Combinations', max_length= |
|
|
52 | spectral = models.CharField(verbose_name='Combinations', max_length=5000, default = '[0,0]') | |
|
53 | 53 | create_directory = models.BooleanField(verbose_name='Create Directory Per Day', default=True) |
|
54 | 54 | include_expname = models.BooleanField(verbose_name='Experiment Name in Directory', default=True) |
|
55 | 55 | acq_link = models.BooleanField(verbose_name='Acquisition Link', default=True) |
General Comments 0
You need to be logged in to leave comments.
Login now