|
|
@@ -7,19 +7,20 @@ from PIL import Image
|
|
|
from PIL import ImageFont
|
|
|
from PIL import ImageDraw
|
|
|
|
|
|
-from django.db import models
|
|
|
-from django.db.models import Count
|
|
|
-from django.core import serializers
|
|
|
-from django.core.files import File
|
|
|
-from django.core.mail import send_mail
|
|
|
-from django.urls import reverse, reverse_lazy
|
|
|
-from django.http import HttpResponseRedirect, Http404, HttpResponse
|
|
|
from django.contrib import messages
|
|
|
from django.contrib.auth import login, authenticate
|
|
|
from django.contrib.auth.models import User
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
from django.contrib.auth.models import User, Group
|
|
|
+from django.core import serializers
|
|
|
+from django.core.files import File
|
|
|
+from django.core.mail import send_mail
|
|
|
+from django.core.exceptions import PermissionDenied
|
|
|
+from django.urls import reverse, reverse_lazy
|
|
|
+from django.http import HttpResponseRedirect, Http404, HttpResponse
|
|
|
+from django.db import models
|
|
|
+from django.db.models import Count
|
|
|
from django.views import generic
|
|
|
from django.views.generic import TemplateView
|
|
|
from django.views.generic import FormView
|
|
|
@@ -30,11 +31,11 @@ from django.forms import formset_factory
|
|
|
from django.forms import BaseModelFormSet
|
|
|
from django.forms import modelformset_factory, inlineformset_factory
|
|
|
from django.forms.models import model_to_dict
|
|
|
-from django_file_form.uploader import FileFormUploader
|
|
|
# from django_countries import countries
|
|
|
from django.template import Context, Template
|
|
|
from django.conf import settings
|
|
|
|
|
|
+from django_file_form.uploader import FileFormUploader
|
|
|
from constance import config
|
|
|
from django.db.models import Q
|
|
|
from newsletter.forms import *
|
|
|
@@ -43,6 +44,7 @@ from post_office import mail
|
|
|
|
|
|
from marktplatz.models import *
|
|
|
from .forms import *
|
|
|
+from .utils import *
|
|
|
|
|
|
# Create your views here.
|
|
|
def index(request):
|
|
|
@@ -698,7 +700,7 @@ class NewProductView(LoginRequiredMixin, FormView):
|
|
|
model = Product
|
|
|
|
|
|
|
|
|
-class ProductCreateView(CreateView, LoginRequiredMixin):
|
|
|
+class ProductCreateView(LoginRequiredMixin, CreateView):
|
|
|
template_name = 'marktplatz/product_create.html'
|
|
|
model = Product
|
|
|
form_class = ProductForm
|
|
|
@@ -776,6 +778,55 @@ class WohnProjektCreateView(ProductCreateView):
|
|
|
# return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
|
+
|
|
|
+class ProductUpdateView(LoginRequiredMixin, UpdateView):
|
|
|
+ template_name = 'marktplatz/product_create.html'
|
|
|
+ model = Product
|
|
|
+ form_class = ProductForm
|
|
|
+ gotoPics = False
|
|
|
+ # success_url =
|
|
|
+
|
|
|
+
|
|
|
+ def dispatch(self, request, *args, **kwargs):
|
|
|
+ if not request.user.is_authenticated:
|
|
|
+ return self.handle_no_permission()
|
|
|
+
|
|
|
+ if self.model.check_manageable(request.user, id= kwargs['pk']):
|
|
|
+ return super().dispatch(request, *args, **kwargs)
|
|
|
+ raise PermissionDenied
|
|
|
+
|
|
|
+
|
|
|
+ def get_context_data(self, **kwargs):
|
|
|
+ context = super().get_context_data(**kwargs)
|
|
|
+ context['info_txt'] = Template(config.INFO_TXT).render(Context(context))
|
|
|
+ return context
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ if 'add-image' in request.POST:
|
|
|
+ self.gotoPics = True
|
|
|
+ return super().post(self, request, *args, **kwargs)
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ return super().get(self, request, *args, **kwargs)
|
|
|
+
|
|
|
+ def form_valid(self, form):
|
|
|
+
|
|
|
+ product = form.save(commit=False)
|
|
|
+ product.contact = Contact.objects.get(user = self.request.user)
|
|
|
+ product.save()
|
|
|
+
|
|
|
+ if (self.gotoPics):
|
|
|
+ return HttpResponseRedirect(reverse('add-image', kwargs={'pk': product.pk}))
|
|
|
+ else:
|
|
|
+ return HttpResponseRedirect( reverse('meine-projekte') )
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class WohnProjektUpdateView(ProductUpdateView):
|
|
|
+ model = Wohnprojekt
|
|
|
+ form_class = WohnprojektForm
|
|
|
+
|
|
|
+
|
|
|
class addImageView(LoginRequiredMixin, FormView):
|
|
|
use_ajax = True
|
|
|
template_name = 'marktplatz/file_upload.html'
|