From c21f4b3dacd597a15a5ec39d525df1dfe1b70376 Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Mon, 17 Jul 2023 01:47:57 +0200 Subject: Add project. --- restaurant_orders/settings/__init__.py | 0 restaurant_orders/settings/admin.py | 1 + restaurant_orders/settings/apps.py | 6 +++ restaurant_orders/settings/forms.py | 18 +++++++++ .../templates/settings/restaurant_settings.html | 22 +++++++++++ restaurant_orders/settings/urls.py | 9 +++++ restaurant_orders/settings/views.py | 44 ++++++++++++++++++++++ 7 files changed, 100 insertions(+) create mode 100644 restaurant_orders/settings/__init__.py create mode 100644 restaurant_orders/settings/admin.py create mode 100644 restaurant_orders/settings/apps.py create mode 100644 restaurant_orders/settings/forms.py create mode 100644 restaurant_orders/settings/templates/settings/restaurant_settings.html create mode 100644 restaurant_orders/settings/urls.py create mode 100644 restaurant_orders/settings/views.py (limited to 'restaurant_orders/settings') diff --git a/restaurant_orders/settings/__init__.py b/restaurant_orders/settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/restaurant_orders/settings/admin.py b/restaurant_orders/settings/admin.py new file mode 100644 index 0000000..694323f --- /dev/null +++ b/restaurant_orders/settings/admin.py @@ -0,0 +1 @@ +from django.contrib import admin diff --git a/restaurant_orders/settings/apps.py b/restaurant_orders/settings/apps.py new file mode 100644 index 0000000..71a36cb --- /dev/null +++ b/restaurant_orders/settings/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class SettingsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'settings' diff --git a/restaurant_orders/settings/forms.py b/restaurant_orders/settings/forms.py new file mode 100644 index 0000000..1ea90e9 --- /dev/null +++ b/restaurant_orders/settings/forms.py @@ -0,0 +1,18 @@ +from django import forms +from core.models import Restaurant + +FORM_TAILWIND_CLASSES = 'form-control block w-full px-3 py-1.5 text-base font-normal text-gray-700 bg-white bg-clip-padding border border-solid border-gray-300 rounded transition ease-in-out m-0 focus:text-gray-700 focus:bg-white focus:border-blue-600 focus:outline-none' + +class RestaurantForm(forms.ModelForm): + woocommerce_consumer_key = forms.CharField(required=False) + woocommerce_consumer_secret = forms.CharField(required=False) + woocommerce_webhook_secret = forms.CharField(required=False) + + class Meta: + model = Restaurant + exclude = ('users', ) + + def __init__(self, *args, **kwargs): + super(RestaurantForm, self).__init__(*args, **kwargs) + for key in self.fields.keys(): + self.fields[key].widget.attrs.update({'class': FORM_TAILWIND_CLASSES}) diff --git a/restaurant_orders/settings/templates/settings/restaurant_settings.html b/restaurant_orders/settings/templates/settings/restaurant_settings.html new file mode 100644 index 0000000..eebe63a --- /dev/null +++ b/restaurant_orders/settings/templates/settings/restaurant_settings.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + +{% block title %}Settings{% endblock %} + +{% block content %} +
+

Settings

+ +
+ Wpisz ten wehbhook do ustawien w twoim sklepie! + {{request.scheme}}://{{request.get_host}}{% url 'wordpress_integration:webhook' restaurant_pk=view.kwargs.pk %} +
+ +
+
+ {% csrf_token %} + {{form.as_p}} + +
+
+
+{% endblock %} diff --git a/restaurant_orders/settings/urls.py b/restaurant_orders/settings/urls.py new file mode 100644 index 0000000..294ea14 --- /dev/null +++ b/restaurant_orders/settings/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from settings.views import Home, RestaurantSettings + +app_name = 'settings' + +urlpatterns = [ + path('', Home.as_view(), name='home'), + path('restaurant/', RestaurantSettings.as_view(), name='restaurant_settings') +] diff --git a/restaurant_orders/settings/views.py b/restaurant_orders/settings/views.py new file mode 100644 index 0000000..0921cd3 --- /dev/null +++ b/restaurant_orders/settings/views.py @@ -0,0 +1,44 @@ +from django.urls import reverse +from django.shortcuts import render, redirect, Http404 +from django.views.generic.edit import UpdateView, CreateView, View +from django.contrib.messages.views import SuccessMessageMixin +from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin + +from core.models import Restaurant +from settings.forms import RestaurantForm + + +class Home(LoginRequiredMixin, PermissionRequiredMixin, View): + permission_required = 'core.change_restaurant' + + def get(self, request): + if not self.request.user.has_perm('settings.change_restaurant'): + raise Http404 + + redirect_url = 'settings:restaurant_settings' + restaurants = Restaurant.get_user_restaurants(request.user) + + if len(restaurants) == 1: + return redirect(redirect_url, pk=restaurants[0].pk) + + return render(request, template_name='restaurants_choice.html', context={ + 'title': 'Ustawienia', + 'restaurants': restaurants, + 'redirect_url': redirect_url + }) + +class RestaurantSettings(LoginRequiredMixin, SuccessMessageMixin, PermissionRequiredMixin, UpdateView): + template_name = 'settings/restaurant_settings.html' + form_class = RestaurantForm + model = Restaurant + success_message = 'Zapisano!' + permission_required = 'core.change_restaurant' + + def get_queryset(self, *args, **kwargs): + return super().get_queryset(*args, **kwargs).filter( + pk=self.kwargs['pk'], + users=self.request.user.pk + ) + + def get_success_url(self): + return reverse('settings:restaurant_settings', args=(self.kwargs['pk'], )) -- cgit v1.2.3