diff options
author | jdlugosz963 <jdlugosz963@gmail.com> | 2023-07-17 01:47:57 +0200 |
---|---|---|
committer | jdlugosz963 <jdlugosz963@gmail.com> | 2023-07-17 01:52:26 +0200 |
commit | c21f4b3dacd597a15a5ec39d525df1dfe1b70376 (patch) | |
tree | 0dfc51d2ffeb7b5022d9ad852f2fd3620c72196a /restaurant_orders/settings | |
parent | 2c6f98aeef4fa1aba5678fe17c8e762a11db7b40 (diff) | |
download | restaurant-orders-c21f4b3dacd597a15a5ec39d525df1dfe1b70376.tar.gz restaurant-orders-c21f4b3dacd597a15a5ec39d525df1dfe1b70376.zip |
Add project.main
Diffstat (limited to 'restaurant_orders/settings')
-rw-r--r-- | restaurant_orders/settings/__init__.py | 0 | ||||
-rw-r--r-- | restaurant_orders/settings/admin.py | 1 | ||||
-rw-r--r-- | restaurant_orders/settings/apps.py | 6 | ||||
-rw-r--r-- | restaurant_orders/settings/forms.py | 18 | ||||
-rw-r--r-- | restaurant_orders/settings/templates/settings/restaurant_settings.html | 22 | ||||
-rw-r--r-- | restaurant_orders/settings/urls.py | 9 | ||||
-rw-r--r-- | restaurant_orders/settings/views.py | 44 |
7 files changed, 100 insertions, 0 deletions
diff --git a/restaurant_orders/settings/__init__.py b/restaurant_orders/settings/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/restaurant_orders/settings/__init__.py | |||
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 @@ | |||
1 | from django.apps import AppConfig | ||
2 | |||
3 | |||
4 | class SettingsConfig(AppConfig): | ||
5 | default_auto_field = 'django.db.models.BigAutoField' | ||
6 | 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 @@ | |||
1 | from django import forms | ||
2 | from core.models import Restaurant | ||
3 | |||
4 | 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' | ||
5 | |||
6 | class RestaurantForm(forms.ModelForm): | ||
7 | woocommerce_consumer_key = forms.CharField(required=False) | ||
8 | woocommerce_consumer_secret = forms.CharField(required=False) | ||
9 | woocommerce_webhook_secret = forms.CharField(required=False) | ||
10 | |||
11 | class Meta: | ||
12 | model = Restaurant | ||
13 | exclude = ('users', ) | ||
14 | |||
15 | def __init__(self, *args, **kwargs): | ||
16 | super(RestaurantForm, self).__init__(*args, **kwargs) | ||
17 | for key in self.fields.keys(): | ||
18 | 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 @@ | |||
1 | {% extends "base.html" %} | ||
2 | |||
3 | {% block title %}Settings{% endblock %} | ||
4 | |||
5 | {% block content %} | ||
6 | <div class="py-20"> | ||
7 | <h3 class="text-3xl font-bold mb-2">Settings</h3> | ||
8 | |||
9 | <div id='webhook_url' class='w-full mb-8'> | ||
10 | <span>Wpisz ten wehbhook do ustawien w twoim sklepie!</span> | ||
11 | <strong> {{request.scheme}}://{{request.get_host}}{% url 'wordpress_integration:webhook' restaurant_pk=view.kwargs.pk %}</strong> | ||
12 | </div> | ||
13 | |||
14 | <div class="grid place-items-center"> | ||
15 | <form method="post" class="p-6 rounded-lg shadow-lg bg-gray-50 justify-center max-w-sm" enctype="multipart/form-data"> | ||
16 | {% csrf_token %} | ||
17 | {{form.as_p}} | ||
18 | <input type="submit" value="Zatwierdz!" /> | ||
19 | </form> | ||
20 | </div> | ||
21 | </div> | ||
22 | {% 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 @@ | |||
1 | from django.urls import path | ||
2 | from settings.views import Home, RestaurantSettings | ||
3 | |||
4 | app_name = 'settings' | ||
5 | |||
6 | urlpatterns = [ | ||
7 | path('', Home.as_view(), name='home'), | ||
8 | path('restaurant/<int:pk>', RestaurantSettings.as_view(), name='restaurant_settings') | ||
9 | ] | ||
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 @@ | |||
1 | from django.urls import reverse | ||
2 | from django.shortcuts import render, redirect, Http404 | ||
3 | from django.views.generic.edit import UpdateView, CreateView, View | ||
4 | from django.contrib.messages.views import SuccessMessageMixin | ||
5 | from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin | ||
6 | |||
7 | from core.models import Restaurant | ||
8 | from settings.forms import RestaurantForm | ||
9 | |||
10 | |||
11 | class Home(LoginRequiredMixin, PermissionRequiredMixin, View): | ||
12 | permission_required = 'core.change_restaurant' | ||
13 | |||
14 | def get(self, request): | ||
15 | if not self.request.user.has_perm('settings.change_restaurant'): | ||
16 | raise Http404 | ||
17 | |||
18 | redirect_url = 'settings:restaurant_settings' | ||
19 | restaurants = Restaurant.get_user_restaurants(request.user) | ||
20 | |||
21 | if len(restaurants) == 1: | ||
22 | return redirect(redirect_url, pk=restaurants[0].pk) | ||
23 | |||
24 | return render(request, template_name='restaurants_choice.html', context={ | ||
25 | 'title': 'Ustawienia', | ||
26 | 'restaurants': restaurants, | ||
27 | 'redirect_url': redirect_url | ||
28 | }) | ||
29 | |||
30 | class RestaurantSettings(LoginRequiredMixin, SuccessMessageMixin, PermissionRequiredMixin, UpdateView): | ||
31 | template_name = 'settings/restaurant_settings.html' | ||
32 | form_class = RestaurantForm | ||
33 | model = Restaurant | ||
34 | success_message = 'Zapisano!' | ||
35 | permission_required = 'core.change_restaurant' | ||
36 | |||
37 | def get_queryset(self, *args, **kwargs): | ||
38 | return super().get_queryset(*args, **kwargs).filter( | ||
39 | pk=self.kwargs['pk'], | ||
40 | users=self.request.user.pk | ||
41 | ) | ||
42 | |||
43 | def get_success_url(self): | ||
44 | return reverse('settings:restaurant_settings', args=(self.kwargs['pk'], )) | ||