2022-01-14 23:26:35 +00:00
|
|
|
from django.shortcuts import render, get_object_or_404
|
|
|
|
from django.urls import reverse
|
2022-01-02 17:29:35 +00:00
|
|
|
|
2022-01-14 21:23:39 +00:00
|
|
|
from django.views.generic.edit import CreateView
|
2022-01-14 23:26:35 +00:00
|
|
|
from django.views.generic.base import TemplateView
|
|
|
|
from django.views.generic.list import ListView
|
|
|
|
from django.views.generic.detail import DetailView
|
|
|
|
|
|
|
|
|
|
|
|
from .models import *
|
2022-01-14 21:23:39 +00:00
|
|
|
|
|
|
|
class ProductOrderView(CreateView):
|
|
|
|
model = ProductOrder
|
2022-01-14 23:26:35 +00:00
|
|
|
fields = ['resources']
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['product'] = get_object_or_404(Product, slug=self.kwargs['product'])
|
2022-01-15 22:57:55 +00:00
|
|
|
context['timeframe'] = get_object_or_404(TimeFrame, slug=self.kwargs['timeframe'])
|
2022-01-15 23:31:59 +00:00
|
|
|
|
|
|
|
res_price = []
|
|
|
|
for res in context['product'].resources.all():
|
|
|
|
price = res.price_per_time.filter(timeframe=context['timeframe'])[0].price
|
|
|
|
currency = res.price_per_time.filter(timeframe=context['timeframe'])[0].currency
|
|
|
|
|
|
|
|
res_price.append((res, price, currency))
|
|
|
|
context['res_price'] = res_price
|
|
|
|
|
2022-01-14 23:26:35 +00:00
|
|
|
print(context)
|
|
|
|
print(self.kwargs)
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class ProductDetailView(DetailView):
|
|
|
|
model = Product
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['productorder'] = reverse('product-order', kwargs={'product': self.object.slug })
|
2022-01-15 22:57:55 +00:00
|
|
|
context['timeframes'] = context['product'].valid_timeframes()
|
|
|
|
print(context)
|
2022-01-14 23:26:35 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class ProductListView(ListView):
|
|
|
|
model = Product
|
|
|
|
|
|
|
|
|
|
|
|
class ProductSelectView(CreateView):
|
|
|
|
model = ProductOrder
|
|
|
|
fields = ['product' ]
|
|
|
|
|
|
|
|
|
|
|
|
class Yearly(TemplateView):
|
|
|
|
template_name = "app/config_product.html"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(Yearly, self).get_context_data(**kwargs)
|
|
|
|
context['current_year'] = self.current_year
|
|
|
|
context['current_month'] = self.current_month
|
|
|
|
return context
|