uncloud-mravi/uncloud_v3/app/views.py

53 lines
1.5 KiB
Python
Raw Normal View History

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
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
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'])
context['timeframe'] = get_object_or_404(TimeFrame, slug=self.kwargs['timeframe'])
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 })
context['timeframes'] = context['product'].valid_timeframes()
print(context)
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