diff --git a/Readme.rst b/Readme.rst index 505b33e..7712c08 100644 --- a/Readme.rst +++ b/Readme.rst @@ -187,3 +187,11 @@ Here is an example of ``gettext`` implementation: .. code:: js alert(gettext("new_word")) + +To fix use vendors files need to update the line 53 + +.. code:: python + + await asyncio.wait(map(lambda runner: asyncio.create_task(runner.future), running)) + +in the root ``{venv}/lib/python3.11/site-packages/pylp/cli/cli.py``. diff --git a/demo/demo/settings.py b/demo/demo/settings.py index 19465ee..ce0ccad 100644 --- a/demo/demo/settings.py +++ b/demo/demo/settings.py @@ -11,6 +11,8 @@ """ import os +from django.conf import settings +from datetime import datetime # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -61,7 +63,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, 'demo/templates/')], + 'DIRS': [os.path.join(BASE_DIR, 'demo/templates/', 'djgentelella/reservation/templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -140,3 +142,19 @@ 'use_readonlywidgets': True, 'use_flags': True } + +TOKENIZE = getattr(settings, 'DJRESERVATION_TOKENIZE', False) + +START_RESERVATION_DATETIME = getattr( + settings, 'DJRESERVATION_START_RESERVATION_DATETIME', None) + +END_RESERVATION_DATETIME = getattr( + settings, 'DJRESERVATION_END_RESERVATION_DATETIME', None) + +if START_RESERVATION_DATETIME: + START_RESERVATION_DATETIME = datetime.strptime( + START_RESERVATION_DATETIME, '%d/%m/%Y %H:%M') + +if END_RESERVATION_DATETIME: + END_RESERVATION_DATETIME = datetime.strptime( + END_RESERVATION_DATETIME, '%d/%m/%Y %H:%M') diff --git a/djgentelella/reservation/admin.py b/djgentelella/reservation/admin.py index d548413..7108b3f 100644 --- a/djgentelella/reservation/admin.py +++ b/djgentelella/reservation/admin.py @@ -5,7 +5,7 @@ from django.utils.safestring import mark_safe from .email import send_reservation_email -from .models import Reservation, Observation, Product +from .models import Reservation, Observation, Product, ReservationToken from .product_manager import proccess_reservation # Register your models here. @@ -101,4 +101,6 @@ def save_model(self, request, obj, form, change): proccess_reservation(obj, differ_obj, change_status) return dev -admin.site.register(Reservation, ReservationAdmin) +admin.site.register(Reservation) +admin.site.register(Product) +admin.site.register(ReservationToken) diff --git a/djgentelella/reservation/forms.py b/djgentelella/reservation/forms.py index 1f51ae1..dd6700a 100644 --- a/djgentelella/reservation/forms.py +++ b/djgentelella/reservation/forms.py @@ -12,9 +12,12 @@ from django.utils.translation import gettext_lazy as _ from .models import Product, Reservation +from ..forms.forms import GTForm +from ..widgets.core import DateTimeInput -class ReservationForm(forms.ModelForm): + +class ReservationForm(forms.ModelForm, GTForm): def clean(self): if hasattr(self, 'request'): @@ -26,10 +29,15 @@ def clean(self): class Meta: model = Reservation fields = '__all__' + widgets = { + "reserved_start_date": DateTimeInput, + "reserved_end_date": DateTimeInput, + } exclude = ['user', 'status'] -class ProductForm(forms.ModelForm): + +class ProductForm(forms.ModelForm, GTForm): model_instance = forms.CharField(widget=forms.HiddenInput) available_amount = forms.FloatField(widget=forms.HiddenInput) diff --git a/djgentelella/reservation/middleware.py b/djgentelella/reservation/middleware.py index 1d0ff93..d3be507 100644 --- a/djgentelella/reservation/middleware.py +++ b/djgentelella/reservation/middleware.py @@ -7,7 +7,7 @@ ''' from __future__ import unicode_literals -from djreservation.models import Reservation +from .models import Reservation class ReservationMiddleware(object): diff --git a/djgentelella/reservation/settings.py b/djgentelella/reservation/settings.py deleted file mode 100644 index 83afc01..0000000 --- a/djgentelella/reservation/settings.py +++ /dev/null @@ -1,28 +0,0 @@ -# encoding: utf-8 - -''' -Free as freedom will be 5/10/2016 - -@author: luisza -''' - -from __future__ import unicode_literals -from django.conf import settings -from django.utils import timezone -from datetime import datetime - -TOKENIZE = getattr(settings, 'DJRESERVATION_TOKENIZE', False) - -START_RESERVATION_DATETIME = getattr( - settings, 'DJRESERVATION_START_RESERVATION_DATETIME', None) - -END_RESERVATION_DATETIME = getattr( - settings, 'DJRESERVATION_END_RESERVATION_DATETIME', None) - -if START_RESERVATION_DATETIME: - START_RESERVATION_DATETIME = datetime.strptime( - START_RESERVATION_DATETIME, '%d/%m/%Y %H:%M') - -if END_RESERVATION_DATETIME: - END_RESERVATION_DATETIME = datetime.strptime( - END_RESERVATION_DATETIME, '%d/%m/%Y %H:%M') diff --git a/djgentelella/reservation/templates/base.html b/djgentelella/reservation/templates/base.html index 7d9aec4..5ae260c 100644 --- a/djgentelella/reservation/templates/base.html +++ b/djgentelella/reservation/templates/base.html @@ -1,8 +1 @@ - -{% block css%} {%endblock%} - -{% block content %} -{%endblock%} - -{% block js %} -{%endblock%} +{% extends 'gentelella/base.html' %} diff --git a/djgentelella/reservation/templates/djreservation/product_form.html b/djgentelella/reservation/templates/djreservation/product_form.html index b9491f7..a93b90b 100644 --- a/djgentelella/reservation/templates/djreservation/product_form.html +++ b/djgentelella/reservation/templates/djreservation/product_form.html @@ -18,7 +18,7 @@ {%endfor%} - + diff --git a/djgentelella/reservation/templates/djreservation/reservation_confirm.html b/djgentelella/reservation/templates/djreservation/reservation_confirm.html index ed995f0..7ba0de4 100644 --- a/djgentelella/reservation/templates/djreservation/reservation_confirm.html +++ b/djgentelella/reservation/templates/djreservation/reservation_confirm.html @@ -3,19 +3,18 @@ {% block content %}
-
- +
+
- {% csrf_token %} + {% csrf_token %}

{% trans 'Are you sure? See above the products details' %}

- - + +
-
+

{% trans 'Reserved products' %}

    {% for product in reservation.product_set.all %} @@ -28,10 +27,10 @@

    {% trans 'Reserved products' %}

    {% empty %}
  • {% trans "Products are not reserved yet" %} -
  • + {% endfor %}
-
+
{% endblock %} diff --git a/djgentelella/reservation/templates/djreservation/reservation_finished.html b/djgentelella/reservation/templates/djreservation/reservation_finished.html index 9cc0c18..130d5e4 100644 --- a/djgentelella/reservation/templates/djreservation/reservation_finished.html +++ b/djgentelella/reservation/templates/djreservation/reservation_finished.html @@ -3,7 +3,7 @@ {% block content %}
-
+
{% trans 'Thanks, your reservation was processed successfully' %}
diff --git a/djgentelella/reservation/templates/djreservation/reservation_form.html b/djgentelella/reservation/templates/djreservation/reservation_form.html index dcb32f5..f9e2874 100644 --- a/djgentelella/reservation/templates/djreservation/reservation_form.html +++ b/djgentelella/reservation/templates/djreservation/reservation_form.html @@ -1,10 +1,10 @@ {% extends 'base.html' %} {% load static i18n %} -{% block css%} +{% block css%} - - + {%endblock%} @@ -25,15 +25,15 @@

{% trans "Creating a reservation"%}

{% endblock %} {{form.errors}}
-{% csrf_token %} +{% csrf_token %} + +{% block form_start %}{% endblock %} -{% block form_start %}{% endblock %} -
{{ form.reserved_start_date.errors }}
-
+
{{ form.reserved_start_date }}
@@ -44,13 +44,13 @@

{% trans "Creating a reservation"%}

- +
{{ form.reserved_end_date.errors }}
-
+
{{ form.reserved_end_date }}
@@ -61,27 +61,10 @@

{% trans "Creating a reservation"%}

-{% block form_end %}{% endblock %} - - +{% block form_end %}{% endblock %} + +
{% endblock %} -{% block js %} - - - - -{% endblock %} diff --git a/djgentelella/reservation/templates/djreservation/reservation_list.html b/djgentelella/reservation/templates/djreservation/reservation_list.html index 4ba1ac2..64c6a62 100644 --- a/djgentelella/reservation/templates/djreservation/reservation_list.html +++ b/djgentelella/reservation/templates/djreservation/reservation_list.html @@ -9,7 +9,7 @@ @@ -18,7 +18,7 @@

    {% for product in reservation.product_set.all%}
  • {{product}} -{% if product.borrowed %} +{% if product.borrowed %} @@ -26,13 +26,13 @@

    -{% endif %} +{% endif %}

  • {% endfor%}
{% if reservation.observation_set.count %} -
+ {% empty %} -

{% trans 'No reservations saved yet' %}

+

{% trans 'No reservations saved yet' %}

{% endfor %}
@@ -58,11 +58,11 @@

{% trans 'No reservations saved yet' %}

{% trans 'Previous' %} {% endif %} - +
  • {% trans 'Page' %} {{ page_obj.number }} -- {{ page_obj.paginator.num_pages }}.
  • - + {% if page_obj.has_next %}
  • {% trans 'Next' %} diff --git a/djgentelella/reservation/templates/djreservation/simple_reservation.html b/djgentelella/reservation/templates/djreservation/simple_reservation.html index 057f441..bfa823c 100644 --- a/djgentelella/reservation/templates/djreservation/simple_reservation.html +++ b/djgentelella/reservation/templates/djreservation/simple_reservation.html @@ -6,14 +6,6 @@

    {% trans "Creating a reservation of :"%}
    {{object}}

    {% endblock%} {% block form_start %} -{{ product_form.non_field_errors }} -
    - {{product_form.amount.errors }} - -
    -{{product_form.amount}} -{{product_form.available_amount}} -{{product_form.model_instance}} -
    - -{% endblock %} \ No newline at end of file +{{ product_form.as_horizontal }} + +{% endblock %} diff --git a/djgentelella/reservation/urls.py b/djgentelella/reservation/urls.py index 1b4f132..dbcae13 100644 --- a/djgentelella/reservation/urls.py +++ b/djgentelella/reservation/urls.py @@ -6,18 +6,18 @@ from django.urls import path, re_path from . import views -from .settings import TOKENIZE +from django.conf import settings urlpatterns = [ - path("reservation/create", views.CreateReservation.as_view(), name="add_user_reservation"), - path("reservation/finish", views.finish_reservation, name="finish_reservation"), - path("reservation/delete_product_reservation//", views.deleteProduct, name="delete_product_reservation"), - path("reservation/list", views.ReservationList.as_view(), name="reservation_list"), + path("create", views.CreateReservation.as_view(), name="add_user_reservation"), + path("finish", views.finish_reservation, name="finish_reservation"), + path("delete_product_reservation//", views.deleteProduct, name="delete_product_reservation"), + path("list", views.ReservationList.as_view(), name="reservation_list"), ] -if TOKENIZE: +if settings.TOKENIZE: urlpatterns += [ - re_path(r"reservation/token/(?P\d+)/(?P[0-9a-f-]+)/(?P\d)$", + re_path(r"token/(?P\d+)/(?P[0-9a-f-]+)/(?P\d)$", views.update_reservation_by_token, name="reservation_token") ] diff --git a/djgentelella/reservation/views.py b/djgentelella/reservation/views.py index b7e3baf..6070fc4 100644 --- a/djgentelella/reservation/views.py +++ b/djgentelella/reservation/views.py @@ -1,6 +1,9 @@ from django.shortcuts import render, get_object_or_404,\ redirect from django.views.generic.edit import CreateView +from rest_framework.reverse import reverse_lazy + +from demo.settings import END_RESERVATION_DATETIME from .models import Product, Reservation, ReservationToken from .forms import ProductForm, ReservationForm from django.http.response import HttpResponseRedirect, Http404 @@ -11,10 +14,7 @@ from django.views.generic.list import ListView from django.contrib import messages -from .settings import (END_RESERVATION_DATETIME, - START_RESERVATION_DATETIME, - TOKENIZE) - +from django.conf import settings def get_base_url(request): protocol = request.is_secure() and 'https://' or 'http://' @@ -25,6 +25,7 @@ def get_base_url(request): class ReservationList(ListView): model = Reservation paginate_by = 10 + template_name = "djreservation/reservation_list.html" def get_queryset(self): queryset = ListView.get_queryset(self) @@ -36,7 +37,8 @@ def get_queryset(self): class CreateReservation(CreateView): model = Reservation form_class = ReservationForm - success_url = "/" + template_name = "djreservation/reservation_form.html" + success_url = reverse_lazy('reservation_list') def get_success_url(self): if self.request.GET.get('next'): @@ -58,7 +60,7 @@ def form_valid(self, form): self.object = form.save(commit=False) self.object.user = self.request.user self.object.save() - if TOKENIZE: + if settings.TOKENIZE: ReservationToken.objects.create( reservation=self.object, base_url=get_base_url(self.request)) @@ -126,11 +128,11 @@ def get_context_data(self, **kwargs): def get_form_kwargs(self): kwargs = CreateView.get_form_kwargs(self) - if END_RESERVATION_DATETIME: - kwargs['initial']['reserved_end_date'] = END_RESERVATION_DATETIME - if START_RESERVATION_DATETIME: + if settings.END_RESERVATION_DATETIME: + kwargs['initial']['reserved_end_date'] = settings.END_RESERVATION_DATETIME + if settings.START_RESERVATION_DATETIME: kwargs['initial'][ - 'reserved_start_date'] = START_RESERVATION_DATETIME + 'reserved_start_date'] = settings.START_RESERVATION_DATETIME return kwargs def form_valid(self, form): @@ -149,7 +151,7 @@ def form_valid(self, form): ) self.object.save() - if TOKENIZE: + if settings.TOKENIZE: ReservationToken.objects.create( reservation=reservation, base_url=get_base_url(self.request)