@@ -101,6 +101,26 class DownloadFileForm(forms.Form): | |||||
101 |
|
101 | |||
102 | class OperationForm(forms.Form): |
|
102 | class OperationForm(forms.Form): | |
103 | # today = datetime.today() |
|
103 | # today = datetime.today() | |
104 | # -----Campaigns from this month------ |
|
104 | # -----Campaigns from this month------[:5] | |
105 | campaign = forms.ChoiceField(choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:5], label="Campaign") |
|
105 | campaign = forms.ChoiceField(label="Campaign") | |
|
106 | ||||
|
107 | def __init__(self, *args, **kwargs): | |||
|
108 | ||||
|
109 | if 'length' not in kwargs.keys(): | |||
|
110 | length = None | |||
|
111 | else: | |||
|
112 | length = kwargs['length'] | |||
|
113 | ||||
|
114 | kwargs.pop('length') | |||
|
115 | ||||
|
116 | super(OperationForm, self).__init__(*args, **kwargs) | |||
|
117 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:length] | |||
|
118 | ||||
|
119 | class OperationSearchForm(forms.Form): | |||
|
120 | # -----ALL Campaigns------ | |||
|
121 | campaign = forms.ChoiceField(label="Campaign") | |||
|
122 | ||||
|
123 | def __init__(self, *args, **kwargs): | |||
|
124 | super(OperationSearchForm, self).__init__(*args, **kwargs) | |||
|
125 | self.fields['campaign'].choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name') | |||
106 | No newline at end of file |
|
126 |
@@ -18,7 +18,10 | |||||
18 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
18 | {% bootstrap_form form layout='horizontal' size='medium' %} | |
19 | <div style="clear: both;"></div> |
|
19 | <div style="clear: both;"></div> | |
20 | <br> |
|
20 | <br> | |
|
21 | <!-- For deep search --> | |||
|
22 | {% if search_button == True %} | |||
21 | <button id="button-1" type="button" class="btn btn-primary pull-right">{{button}}</button> |
|
23 | <button id="button-1" type="button" class="btn btn-primary pull-right">{{button}}</button> | |
|
24 | {% endif %} | |||
22 | <br> |
|
25 | <br> | |
23 | <br> |
|
26 | <br> | |
24 | </form> |
|
27 | </form> | |
@@ -105,6 +108,7 | |||||
105 | document.location = $(this).data("href"); |
|
108 | document.location = $(this).data("href"); | |
106 | }); |
|
109 | }); | |
107 |
|
110 | |||
|
111 | {% if search_button == True %} | |||
108 | $(document).ready(function() { |
|
112 | $(document).ready(function() { | |
109 | $("#id_campaign").change(function() { |
|
113 | $("#id_campaign").change(function() { | |
110 | var id_camp = document.getElementById("id_campaign").value; |
|
114 | var id_camp = document.getElementById("id_campaign").value; | |
@@ -112,6 +116,15 | |||||
112 | document.location = "{% url 'url_operation'%}"+String(id_camp); |
|
116 | document.location = "{% url 'url_operation'%}"+String(id_camp); | |
113 | }); |
|
117 | }); | |
114 | }); |
|
118 | }); | |
|
119 | {% else %} | |||
|
120 | $(document).ready(function() { | |||
|
121 | $("#id_campaign").change(function() { | |||
|
122 | var id_camp = document.getElementById("id_campaign").value; | |||
|
123 | //alert(id_camp); | |||
|
124 | document.location = "{% url 'url_operation_search'%}"+String(id_camp); | |||
|
125 | }); | |||
|
126 | }); | |||
|
127 | {% endif %} | |||
115 |
|
128 | |||
116 | $("#button-1").click(function() { |
|
129 | $("#button-1").click(function() { | |
117 | document.location = "{% url 'url_operation_search' %}"; |
|
130 | document.location = "{% url 'url_operation_search' %}"; |
@@ -40,6 +40,8 urlpatterns = ( | |||||
40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), |
|
40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), | |
41 |
|
41 | |||
42 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
42 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), | |
|
43 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), | |||
|
44 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), | |||
43 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), |
|
45 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), | |
44 |
|
46 | |||
45 | ) |
|
47 | ) |
@@ -2,6 +2,7 from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |||||
2 | from django.contrib import messages |
|
2 | from django.contrib import messages | |
3 |
|
3 | |||
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm |
|
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm | |
|
5 | from .forms import OperationSearchForm | |||
5 | from apps.cgs.forms import CGSConfigurationForm |
|
6 | from apps.cgs.forms import CGSConfigurationForm | |
6 | from apps.jars.forms import JARSConfigurationForm |
|
7 | from apps.jars.forms import JARSConfigurationForm | |
7 | from apps.usrp.forms import USRPConfigurationForm |
|
8 | from apps.usrp.forms import USRPConfigurationForm | |
@@ -9,7 +10,7 from apps.abs.forms import ABSConfigurationForm | |||||
9 | from apps.rc.forms import RCConfigurationForm |
|
10 | from apps.rc.forms import RCConfigurationForm | |
10 | from apps.dds.forms import DDSConfigurationForm |
|
11 | from apps.dds.forms import DDSConfigurationForm | |
11 |
|
12 | |||
12 | from .models import Campaign, Experiment, Device, Configuration, Location |
|
13 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment | |
13 | from apps.cgs.models import CGSConfiguration |
|
14 | from apps.cgs.models import CGSConfiguration | |
14 | from apps.jars.models import JARSConfiguration |
|
15 | from apps.jars.models import JARSConfiguration | |
15 | from apps.usrp.models import USRPConfiguration |
|
16 | from apps.usrp.models import USRPConfiguration | |
@@ -70,6 +71,35 def location(request, id_loc): | |||||
70 |
|
71 | |||
71 | return render(request, 'location.html', kwargs) |
|
72 | return render(request, 'location.html', kwargs) | |
72 |
|
73 | |||
|
74 | #def location_play(request, id_camp, id_loc): | |||
|
75 | ||||
|
76 | # campaign = get_object_or_404(Campaign, pk=id_camp) | |||
|
77 | # print campaign | |||
|
78 | # location = get_object_or_404(Location, pk=id_loc) | |||
|
79 | # experiments = Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) | |||
|
80 | # locations = Location.objects.filter(pk=id_loc) | |||
|
81 | ||||
|
82 | # if request.method=='GET': | |||
|
83 | # form = OperationForm(initial={'campaign': campaign.id}) | |||
|
84 | ||||
|
85 | # kwargs = {} | |||
|
86 | #---Campaign | |||
|
87 | # kwargs['campaign'] = campaign | |||
|
88 | # kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |||
|
89 | #---Experiment | |||
|
90 | # keys = ['id', 'name', 'start_time', 'end_time'] | |||
|
91 | # kwargs['experiment_keys'] = keys[1:] | |||
|
92 | # kwargs['experiments'] = experiments | |||
|
93 | #---Radar | |||
|
94 | # kwargs['location'] = location | |||
|
95 | #---Else | |||
|
96 | # kwargs['title'] = 'Campaign' | |||
|
97 | # kwargs['suptitle'] = campaign.name | |||
|
98 | # kwargs['form'] = form | |||
|
99 | # kwargs['button'] = 'Search' | |||
|
100 | ||||
|
101 | # return render(request, 'operation_play.html', kwargs) | |||
|
102 | ||||
73 | def location_new(request): |
|
103 | def location_new(request): | |
74 |
|
104 | |||
75 | if request.method == 'GET': |
|
105 | if request.method == 'GET': | |
@@ -774,23 +804,21 def operation(request, id_camp=None): | |||||
774 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
804 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
775 |
|
805 | |||
776 | if request.method=='GET': |
|
806 | if request.method=='GET': | |
777 |
form = OperationForm(initial={'campaign': |
|
807 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) | |
778 |
|
808 | |||
779 | if request.method=='POST': |
|
809 | if request.method=='POST': | |
780 | form = OperationForm(request.POST, initial={'campaign':campaign.id}) |
|
810 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) | |
781 |
|
811 | |||
782 | if form.is_valid(): |
|
812 | if form.is_valid(): | |
783 | return redirect('url_operation', id_camp=campaign.id) |
|
813 | return redirect('url_operation', id_camp=campaign.id) | |
784 |
|
814 | locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | ||
785 |
|
|
815 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
786 | experiments = Experiment.objects.filter(campaign=campaign) |
|
816 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |
787 | experiments = [Experiment.objects.filter(location__pk=location.id) for location in locations] |
|
|||
788 |
|
||||
789 | kwargs = {} |
|
817 | kwargs = {} | |
790 | #---Campaign |
|
818 | #---Campaign | |
791 | kwargs['campaign'] = campaign |
|
819 | kwargs['campaign'] = campaign | |
792 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
820 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
793 | #---Experimet |
|
821 | #---Experiment | |
794 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
822 | keys = ['id', 'name', 'start_time', 'end_time'] | |
795 | kwargs['experiment_keys'] = keys[1:] |
|
823 | kwargs['experiment_keys'] = keys[1:] | |
796 | kwargs['experiments'] = experiments |
|
824 | kwargs['experiments'] = experiments | |
@@ -800,6 +828,60 def operation(request, id_camp=None): | |||||
800 | kwargs['title'] = 'Campaign' |
|
828 | kwargs['title'] = 'Campaign' | |
801 | kwargs['suptitle'] = campaign.name |
|
829 | kwargs['suptitle'] = campaign.name | |
802 | kwargs['form'] = form |
|
830 | kwargs['form'] = form | |
803 |
kwargs['button'] = ' |
|
831 | kwargs['button'] = 'Search' | |
|
832 | kwargs['search_button'] = True | |||
|
833 | ||||
|
834 | return render(request, 'operation.html', kwargs) | |||
|
835 | ||||
|
836 | def operation_search(request, id_camp=None, location_play = None): | |||
|
837 | ||||
|
838 | ||||
|
839 | if not id_camp: | |||
|
840 | campaigns = Campaign.objects.all().order_by('-start_date') | |||
|
841 | form = OperationSearchForm() | |||
|
842 | ||||
|
843 | if not campaigns: | |||
|
844 | return render(request, 'operation.html', {}) | |||
|
845 | ||||
|
846 | id_camp = campaigns[0].id | |||
|
847 | campaign = get_object_or_404(Campaign, pk = id_camp) | |||
|
848 | ||||
|
849 | kwargs = {} | |||
|
850 | kwargs['title'] = 'All Campaigns' | |||
|
851 | kwargs['form'] = form | |||
|
852 | return render(request, 'operation.html', kwargs) | |||
|
853 | ||||
|
854 | else: | |||
|
855 | campaign = get_object_or_404(Campaign, pk = id_camp) | |||
|
856 | locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |||
|
857 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |||
|
858 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |||
|
859 | form = OperationSearchForm(initial={'campaign': campaign.id}) | |||
|
860 | ||||
|
861 | kwargs = {} | |||
|
862 | #---Campaign | |||
|
863 | kwargs['campaign'] = campaign | |||
|
864 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |||
|
865 | #---Experiment | |||
|
866 | keys = ['id', 'name', 'start_time', 'end_time'] | |||
|
867 | kwargs['experiment_keys'] = keys[1:] | |||
|
868 | kwargs['experiments'] = experiments | |||
|
869 | #---Radar | |||
|
870 | kwargs['locations'] = locations | |||
|
871 | #---Else | |||
|
872 | kwargs['title'] = 'Campaign' | |||
|
873 | kwargs['suptitle'] = campaign.name | |||
|
874 | kwargs['form'] = form | |||
|
875 | kwargs['button'] = 'Select' | |||
|
876 | kwargs['details'] = True | |||
|
877 | kwargs['search_button'] = False | |||
|
878 | ||||
|
879 | ||||
|
880 | if request.method=='POST': | |||
|
881 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) | |||
|
882 | ||||
|
883 | if form.is_valid(): | |||
|
884 | return redirect('operation.html', id_camp=campaign.id) | |||
|
885 | ||||
804 |
|
886 | |||
805 | return render(request, 'operation.html', kwargs) No newline at end of file |
|
887 | return render(request, 'operation.html', kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now