drought/dashboard/views.py

325 lines
9.7 KiB
Python

from django.contrib.auth.decorators import login_required
# Create your views here.
from django.shortcuts import render
from django.urls import reverse_lazy
from django.utils.decorators import method_decorator
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
from dashboard.models import Country, Spi, Hydro, Landuse, Finance, Popu, Crop, Admdiv
def index(request):
return render(request, 'dashboard/index.html')
@method_decorator(login_required, name='dispatch')
class CountryListView(ListView):
context_object_name = 'countries'
def get_queryset(self):
self.keyword = self.request.GET.get('keyword', '')
if len(self.keyword) != 0:
return Country.objects.filter(name__contains=self.keyword)
return Country.objects.all()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['keyword'] = self.keyword
return context
class CountryDetailView(DetailView):
context_object_name = "country"
model = Country
class CountryCreateView(CreateView):
model = Country
fields = ['name', 'parent_name', 'level', 'datetime', 'area', 'arable_land_area', 'population',
'agricultural_population', 'gross_national_product', 'total_agricultural_output',
'arable_land_per_capita']
class CountryUpdateView(UpdateView):
model = Country
fields = ['name', 'parent_name', 'level', 'datetime', 'area', 'arable_land_area', 'population',
'agricultural_population', 'gross_national_product', 'total_agricultural_output',
'arable_land_per_capita']
class CountryDeleteView(DeleteView):
model = Country
success_url = reverse_lazy('data-country-list')
@method_decorator(login_required, name='dispatch')
class SpiListView(ListView):
context_object_name = 'spis'
def get_queryset(self):
self.keyword = self.request.GET.get('keyword', '')
if len(self.keyword) != 0:
return Spi.objects.filter(name__contains=self.keyword)
return Spi.objects.all()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['keyword'] = self.keyword
return context
class SpiDetailView(DetailView):
context_object_name = "spi"
model = Spi
class SpiCreateView(CreateView):
model = Spi
fields = ['code', 'longitude', 'latitude', 'year', 'month', 'mean_precipitation', 'mean_temperature']
class SpiUpdateView(UpdateView):
model = Spi
fields = ['code', 'longitude', 'latitude', 'year', 'month', 'mean_precipitation', 'mean_temperature']
class SpiDeleteView(DeleteView):
model = Spi
success_url = reverse_lazy('data-spi-list')
@method_decorator(login_required, name='dispatch')
class HydroListView(ListView):
context_object_name = 'hydros'
def get_queryset(self):
self.keyword = self.request.GET.get('keyword', '')
if len(self.keyword) != 0:
return Hydro.objects.filter(name__contains=self.keyword)
return Hydro.objects.all()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['keyword'] = self.keyword
return context
class HydroDetailView(DetailView):
context_object_name = "hydro"
model = Hydro
class HydroCreateView(CreateView):
model = Hydro
fields = ['name', 'date', 'average_water_level', 'average_flow_rate', 'precipitation']
class HydroUpdateView(UpdateView):
model = Hydro
fields = ['name', 'date', 'average_water_level', 'average_flow_rate', 'precipitation']
class HydroDeleteView(DeleteView):
model = Hydro
success_url = reverse_lazy('data-hydro-list')
@method_decorator(login_required, name='dispatch')
class LanduseListView(ListView):
context_object_name = 'landuses'
def get_queryset(self):
self.keyword = self.request.GET.get('keyword', '')
if len(self.keyword) != 0:
return Landuse.objects.filter(name__contains=self.keyword)
return Landuse.objects.all()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['keyword'] = self.keyword
return context
class LanduseDetailView(DetailView):
context_object_name = "landuse"
model = Landuse
class LanduseCreateView(CreateView):
model = Landuse
fields = ['name', 'date', 'Cultivated_land_area', 'Irrigated_land', 'eatch_land', 'eatch_Irrigated_land']
class LanduseUpdateView(UpdateView):
model = Landuse
fields = ['name', 'date', 'Cultivated_land_area', 'Irrigated_land', 'eatch_land', 'eatch_Irrigated_land']
class LanduseDeleteView(DeleteView):
model = Landuse
success_url = reverse_lazy('data-landuse-list')
@method_decorator(login_required, name='dispatch')
class FinanceListView(ListView):
context_object_name = 'finances'
def get_queryset(self):
self.keyword = self.request.GET.get('keyword', '')
if len(self.keyword) != 0:
return Finance.objects.filter(name__contains=self.keyword)
return Finance.objects.all()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['keyword'] = self.keyword
return context
class FinanceDetailView(DetailView):
context_object_name = "finance"
model = Finance
class FinanceCreateView(CreateView):
model = Finance
fields = ['region', 'level', 'date', 'financial_revenue', 'tax_revenue', 'value_added_tax', 'sales_tax',
'corporate_income_tax', 'individual_income_tax', 'resource_tax', 'urban_maintenance_construction_tax',
'property_tax', 'stamp_duty', 'urban_land_use_tax', 'land_value_added_tax', 'vehicle_vessel_tax',
'arable_land_occupancy_tax', 'deed_tax', 'tobacco_tax', 'non_tax_revenue']
class FinanceUpdateView(UpdateView):
model = Finance
fields = ['region', 'level', 'date', 'financial_revenue', 'tax_revenue', 'value_added_tax', 'sales_tax',
'corporate_income_tax', 'individual_income_tax', 'resource_tax', 'urban_maintenance_construction_tax',
'property_tax', 'stamp_duty', 'urban_land_use_tax', 'land_value_added_tax', 'vehicle_vessel_tax',
'arable_land_occupancy_tax', 'deed_tax', 'tobacco_tax', 'non_tax_revenue']
class FinanceDeleteView(DeleteView):
model = Finance
success_url = reverse_lazy('data-finance-list')
@method_decorator(login_required, name='dispatch')
class PopuListView(ListView):
context_object_name = 'popus'
def get_queryset(self):
self.keyword = self.request.GET.get('keyword', '')
if len(self.keyword) != 0:
return Popu.objects.filter(name__contains=self.keyword)
return Popu.objects.all()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['keyword'] = self.keyword
return context
class PopuDetailView(DetailView):
context_object_name = "popu"
model = Popu
class PopuCreateView(CreateView):
model = Popu
fields = ['region', 'date', 'permanent_population', 'households', 'census_register_population', 'male', 'female_sex','birth_rate','mortality','growth_rate','urbanization_rate']
class PopuUpdateView(UpdateView):
model = Popu
fields = ['region', 'date', 'permanent_population', 'households', 'census_register_population', 'male', 'female_sex','birth_rate','mortality','growth_rate','urbanization_rate']
class PopuDeleteView(DeleteView):
model = Popu
success_url = reverse_lazy('data-popu-list')
@method_decorator(login_required, name='dispatch')
class CropListView(ListView):
context_object_name = 'crops'
def get_queryset(self):
self.keyword = self.request.GET.get('keyword', '')
if len(self.keyword) != 0:
return Crop.objects.filter(name__contains=self.keyword)
return Crop.objects.all()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['keyword'] = self.keyword
return context
class CropDetailView(DetailView):
context_object_name = "crop"
model = Crop
class CropCreateView(CreateView):
model = Crop
fields = ['county_area', 'date', 'seeded_area', 'growth_rate1', 'yield1', 'growth_rate2', 'seeded_area','growth_rate3','yield2','growth_rate4']
class CropUpdateView(UpdateView):
model = Crop
fields = ['county_area', 'date', 'seeded_area', 'growth_rate1', 'yield1', 'growth_rate2', 'seeded_area','growth_rate3','yield2','growth_rate4']
class CropDeleteView(DeleteView):
model = Crop
success_url = reverse_lazy('data-crop-list')
@method_decorator(login_required, name='dispatch')
class AdmdivListView(ListView):
context_object_name = 'admdivs'
def get_queryset(self):
self.keyword = self.request.GET.get('keyword', '')
if len(self.keyword) != 0:
return Admdiv.objects.filter(name__contains=self.keyword)
return Admdiv.objects.all()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['keyword'] = self.keyword
return context
class AdmdivDetailView(DetailView):
context_object_name = "admdiv"
model = Admdiv
class AdmdivCreateView(CreateView):
model = Admdiv
fields = ['county_area', 'date', 'government', 'villager_committee', 'street_office', 'residents_committee', 'land_area','proportion']
class AdmdivUpdateView(UpdateView):
model = Admdiv
fields = ['county_area', 'date', 'government', 'villager_committee', 'street_office', 'residents_committee', 'land_area','proportion']
class AdmdivDeleteView(DeleteView):
model = Admdiv
success_url = reverse_lazy('data-admdiv-list')