Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging djreservation with gentelella #74

Open
wants to merge 6 commits into
base: reservations
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
20 changes: 19 additions & 1 deletion demo/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)))
Expand Down Expand Up @@ -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')],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No puso la app en installed apps por eso es que no le reconoce las plantillas.

'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -140,3 +142,19 @@
'use_readonlywidgets': True,
'use_flags': True
}

TOKENIZE = getattr(settings, 'DJRESERVATION_TOKENIZE', False)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

el objecto settings de djreservation tiene sentido, acá la variable settings no existe, además que fuerza al usuario a siempre poner esos settings y eso no es deseado


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')
6 changes: 4 additions & 2 deletions djgentelella/reservation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
12 changes: 10 additions & 2 deletions djgentelella/reservation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion djgentelella/reservation/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'''

from __future__ import unicode_literals
from djreservation.models import Reservation
from .models import Reservation


class ReservationMiddleware(object):
Expand Down
28 changes: 0 additions & 28 deletions djgentelella/reservation/settings.py

This file was deleted.

9 changes: 1 addition & 8 deletions djgentelella/reservation/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@

{% block css%} {%endblock%}

{% block content %}
{%endblock%}

{% block js %}
{%endblock%}
{% extends 'gentelella/base.html' %}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{%endfor%}
<tr>
<td></td>
<td><input class="btn btn-success" type="submit" value="{% trans 'Reserve'%}"></td>
<td><input class="btn btn-outline-success" type="submit" value="{% trans 'Reserve' %}"></td>
</tr>
</table>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@

{% block content %}
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="col-md-8 offset-md-2">

<form class="form-horizontal" method="post">
{% csrf_token %}
{% csrf_token %}
<h2>{% trans 'Are you sure? See above the products details' %}</h2>

<input type="submit"
class="btn btn-success" value="{% trans 'Finish this reservation' %}" />

<input type="submit" class="btn btn-success" value="{% trans 'Finish this reservation' %}" />
</form>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-1">
<div class="col-md-8 offset-md-2">
<h1> {% trans 'Reserved products' %} </h1>
<ul class="list-group">
{% for product in reservation.product_set.all %}
Expand All @@ -28,10 +27,10 @@ <h1> {% trans 'Reserved products' %} </h1>
{% empty %}
<li class="list-group-item">
{% trans "Products are not reserved yet" %}
</li>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block content %}
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="col-md-6 offset-md-3">
{% trans 'Thanks, your reservation was processed successfully' %}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% extends 'base.html' %}
{% load static i18n %}

{% block css%}
{% block css%}
<link rel="stylesheet" type="text/css" media="screen"
href="{% static 'css/bootstrap-datetimepicker.min.css' %}">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css"
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto hay que eliminarlo, ya que djgentelella tiene iconos incorpoados de la versión 4
datepiker también forma parte de gentelella.

rel="stylesheet">

<style>
Expand All @@ -13,7 +13,7 @@
width: 270px;
}
</style>

{%endblock%}


Expand All @@ -25,15 +25,15 @@ <h1> {% trans "Creating a reservation"%} </h1>
{% endblock %}
{{form.errors}}
<form class="form-horizontal" method="post">
{% csrf_token %}
{% csrf_token %}

{% block form_start %}{% endblock %}

{% block form_start %}{% endblock %}

<div class="form-group">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sería mejor un {{form.as_horizontal }} ??

{{ form.reserved_start_date.errors }}
<label id="{{ form.reserved_start_date.id_label_tag }}" class="col-sm-2 control-label" > {% trans 'Reservation start date' %} </label>
<div id="dtp_reserved_start_date" class="input-append date">
<div class="col-sm-2">
<div class="col-sm-2">
{{ form.reserved_start_date }}
</div>

Expand All @@ -44,13 +44,13 @@ <h1> {% trans "Creating a reservation"%} </h1>
</div>
</div>
</div>


<div class="form-group">
{{ form.reserved_end_date.errors }}
<label id="{{ form.reserved_end_date.id_label_tag }}" class="col-sm-2 control-label" > {% trans 'Reservation end date' %} </label>
<div id="dtp_reserved_end_date" class="input-append date">
<div class="col-sm-2">
<div class="col-sm-2">
{{ form.reserved_end_date }}
</div>

Expand All @@ -61,27 +61,10 @@ <h1> {% trans "Creating a reservation"%} </h1>
</div>
</div>
</div>
{% block form_end %}{% endblock %}
<button type="submit" class="btn btn-default">{% trans 'Submit' %}</button>
{% block form_end %}{% endblock %}

<button type="submit" class="btn btn-outline-success">{% trans 'Submit' %}</button>
</form>

{% endblock %}

{% block js %}
<script type="text/javascript"
src="{% static 'js/bootstrap-datetimepicker.min.js' %}">
</script>

<script type="text/javascript">
rsd= $('#dtp_reserved_start_date').datetimepicker({
format: 'MM/dd/yyyy hh:mm',
autoclose: true
});
rd= $('#dtp_reserved_end_date').datetimepicker({
format: 'MM/dd/yyyy hh:mm',
autoclose: true
});
</script>

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="panel-heading" role="tab" id="headingOne">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto debería utilizar un tabla de gentelella, para esta primera etapa está ok, pero en la siguiente hay que cambia para que se conecte a un api

<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{{reservation.pk}}" aria-expanded="true" aria-controls="collapse{{reservation.pk}}">
{{reservation}}
{{reservation}}
</a>
</h4>
</div>
Expand All @@ -18,21 +18,21 @@ <h4 class="panel-title">
<ul class="list-group">
{% for product in reservation.product_set.all%}
<li class="list-group-item">{{product}}
{% if product.borrowed %}
{% if product.borrowed %}
<a href="#" style="position: absolute;right: 15px;" >
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
</a>
{%else%}
<a href="#" style="position: absolute;right: 15px;" >
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</a>
{% endif %}
{% endif %}
</li>
{% endfor%}
</ul>

{% if reservation.observation_set.count %}
<div class="alert alert-info">
<div class="alert alert-info" role="alert">
<h2> {% trans 'Observations' %}</h2>
{% for observation in reservation.observation_set.all %}
{{observation.text}}
Expand All @@ -45,7 +45,7 @@ <h2> {% trans 'Observations' %}</h2>
</div>

{% empty %}
<h2> {% trans 'No reservations saved yet' %}</h2>
<h2 class="text-center title"> {% trans 'No reservations saved yet' %}</h2>
{% endfor %}
</div>

Expand All @@ -58,11 +58,11 @@ <h2> {% trans 'No reservations saved yet' %}</h2>
<a href="?page={{ page_obj.previous_page_number }}">{% trans 'Previous' %}</a>
</li>
{% endif %}

<li>
{% trans 'Page' %} {{ page_obj.number }} -- {{ page_obj.paginator.num_pages }}.
</li>

{% if page_obj.has_next %}
<li>
<a href="?page={{ page_obj.next_page_number }}">{% trans 'Next' %}</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
<h1> {% trans "Creating a reservation of :"%} <br><small >{{object}}</small></h1>
{% endblock%}
{% block form_start %}
{{ product_form.non_field_errors }}
<div class="form-group">
{{product_form.amount.errors }}
<label for="id_amount" class="col-sm-2 control-label">{{product_form.amount.label}}</label>
<div class="col-sm-2">
{{product_form.amount}}
{{product_form.available_amount}}
{{product_form.model_instance}}
</div></div>

{% endblock %}
{{ product_form.as_horizontal }}

{% endblock %}
14 changes: 7 additions & 7 deletions djgentelella/reservation/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:pk>/", 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/<int:pk>/", 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<pk>\d+)/(?P<token>[0-9a-f-]+)/(?P<status>\d)$",
re_path(r"token/(?P<pk>\d+)/(?P<token>[0-9a-f-]+)/(?P<status>\d)$",
views.update_reservation_by_token,
name="reservation_token")
]
Loading