@@ -101,6 +101,26 class DownloadFileForm(forms.Form): | |||
|
101 | 101 | |
|
102 | 102 | class OperationForm(forms.Form): |
|
103 | 103 | # today = datetime.today() |
|
104 | # -----Campaigns from this month------ | |
|
105 | campaign = forms.ChoiceField(choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:5], label="Campaign") | |
|
104 | # -----Campaigns from this month------[:5] | |
|
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 | 126 | No newline at end of file |
@@ -18,7 +18,10 | |||
|
18 | 18 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
19 | 19 | <div style="clear: both;"></div> |
|
20 | 20 | <br> |
|
21 | <!-- For deep search --> | |
|
22 | {% if search_button == True %} | |
|
21 | 23 | <button id="button-1" type="button" class="btn btn-primary pull-right">{{button}}</button> |
|
24 | {% endif %} | |
|
22 | 25 | <br> |
|
23 | 26 | <br> |
|
24 | 27 | </form> |
@@ -105,6 +108,7 | |||
|
105 | 108 | document.location = $(this).data("href"); |
|
106 | 109 | }); |
|
107 | 110 | |
|
111 | {% if search_button == True %} | |
|
108 | 112 | $(document).ready(function() { |
|
109 | 113 | $("#id_campaign").change(function() { |
|
110 | 114 | var id_camp = document.getElementById("id_campaign").value; |
@@ -112,6 +116,15 | |||
|
112 | 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 | 129 | $("#button-1").click(function() { |
|
117 | 130 | document.location = "{% url 'url_operation_search' %}"; |
@@ -40,6 +40,8 urlpatterns = ( | |||
|
40 | 40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), |
|
41 | 41 | |
|
42 | 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 | 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 | 2 | from django.contrib import messages |
|
3 | 3 | |
|
4 | 4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm |
|
5 | from .forms import OperationSearchForm | |
|
5 | 6 | from apps.cgs.forms import CGSConfigurationForm |
|
6 | 7 | from apps.jars.forms import JARSConfigurationForm |
|
7 | 8 | from apps.usrp.forms import USRPConfigurationForm |
@@ -9,7 +10,7 from apps.abs.forms import ABSConfigurationForm | |||
|
9 | 10 | from apps.rc.forms import RCConfigurationForm |
|
10 | 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 | 14 | from apps.cgs.models import CGSConfiguration |
|
14 | 15 | from apps.jars.models import JARSConfiguration |
|
15 | 16 | from apps.usrp.models import USRPConfiguration |
@@ -70,6 +71,35 def location(request, id_loc): | |||
|
70 | 71 | |
|
71 | 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 | 103 | def location_new(request): |
|
74 | 104 | |
|
75 | 105 | if request.method == 'GET': |
@@ -774,23 +804,65 def operation(request, id_camp=None): | |||
|
774 | 804 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
775 | 805 | |
|
776 | 806 | if request.method=='GET': |
|
777 |
form = OperationForm(initial={'campaign': |
|
|
807 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) | |
|
778 | 808 | |
|
779 | 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 | 812 | if form.is_valid(): |
|
783 | 813 | return redirect('url_operation', id_camp=campaign.id) |
|
814 | locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() | |
|
815 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) | |
|
816 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] | |
|
817 | kwargs = {} | |
|
818 | #---Campaign | |
|
819 | kwargs['campaign'] = campaign | |
|
820 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
|
821 | #---Experiment | |
|
822 | keys = ['id', 'name', 'start_time', 'end_time'] | |
|
823 | kwargs['experiment_keys'] = keys[1:] | |
|
824 | kwargs['experiments'] = experiments | |
|
825 | #---Radar | |
|
826 | kwargs['locations'] = locations | |
|
827 | #---Else | |
|
828 | kwargs['title'] = 'Campaign' | |
|
829 | kwargs['suptitle'] = campaign.name | |
|
830 | kwargs['form'] = form | |
|
831 | kwargs['button'] = 'Search' | |
|
832 | kwargs['search_button'] = True | |
|
784 | 833 | |
|
785 | locations = Location.objects.filter(experiment__campaign__pk = campaign.id) | |
|
786 | experiments = Experiment.objects.filter(campaign=campaign) | |
|
787 | experiments = [Experiment.objects.filter(location__pk=location.id) for location in locations] | |
|
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}) | |
|
788 | 860 | |
|
789 | 861 | kwargs = {} |
|
790 | 862 | #---Campaign |
|
791 | 863 | kwargs['campaign'] = campaign |
|
792 | 864 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
793 | #---Experimet | |
|
865 | #---Experiment | |
|
794 | 866 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
795 | 867 | kwargs['experiment_keys'] = keys[1:] |
|
796 | 868 | kwargs['experiments'] = experiments |
@@ -800,6 +872,16 def operation(request, id_camp=None): | |||
|
800 | 872 | kwargs['title'] = 'Campaign' |
|
801 | 873 | kwargs['suptitle'] = campaign.name |
|
802 | 874 | kwargs['form'] = form |
|
803 |
kwargs['button'] = ' |
|
|
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 | 887 | return render(request, 'operation.html', kwargs) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now