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

Django 3 support #41

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ docs/_build/

# PyBuilder
target/
.idea
openinghours.db
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
language: python

# this list can be easily generated py running `tox -l`
env:
- TOX_ENV=py27-django18
- TOX_ENV=py27-django111
- TOX_ENV=py36-django22
- TOX_ENV=py36-django30

# Currently, Python 3.5 Interpreter is only available when it is specified
# Currently, Python 3.7 Interpreter is only available when it is specified
# in the travis python section. So we have to work around this with this include
# GitHub issue: https://github.com/travis-ci/travis-ci/issues/4794
# GitHub issue: https://github.com/travis-ci/travis-ci/issues/9815
matrix:
include:
- python: "3.6"
- python: "3.7"
env:
- TOX_ENV=py36-django18
- python: "3.6"
- TOX_ENV=py37-django22
- python: "3.7"
env:
- TOX_ENV=py36-django111
- TOX_ENV=py37-django30

install:
- pip install tox-travis
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
=== (ongoing) ===
Please check the latest commits for development version.

=== 0.2.0 ==
- Drop Django 1 and Python 2 support
- Fixed migration errors

=== 0.1.3 ==
- Drop Django 1.7 support
- Fix a TypeError in templatetags (#24)
Expand Down
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ Create your tables

Set ``'TIME_ZONE'`` in your project settings.

Quick dev preview setup
~~~~~~~~~~~~~~~~~~~~~~~

Clone the repo and cd into it.

Then migrate into SQLite, load some test data and run the dev server like so.

::

$ ./manage.py migrate
$ ./manage.py shell
>>> from openinghours.tests.tests import OpeningHoursTestCase as Data
>>> Data.setUp(Data())
$ ./manage.py runserver

Usage
-----

Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import os
import sys

Expand Down
3 changes: 1 addition & 2 deletions openinghours/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
__version__ = '0.1.5'
__version__ = '0.2.0'
2 changes: 1 addition & 1 deletion openinghours/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.contrib import admin
from openinghours.models import OpeningHours, ClosingRules, Company
from openinghours.app_settings import PREMISES_MODEL
Expand All @@ -18,6 +17,7 @@ class CompanyAdmin(admin.ModelAdmin):
inlines = [OpeningHoursInline, ClosingRulesInline]
search_fields = ['name', 'slug']


# OPENINGHOURS_PREMISES_MODEL users need to register
# their own admin from their app
if PREMISES_MODEL == 'openinghours.Company':
Expand Down
1 change: 1 addition & 0 deletions openinghours/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def time_choices():
times.append(hour+':30')
return list(zip(times, times))


TIME_CHOICES = time_choices()


Expand Down
27 changes: 16 additions & 11 deletions openinghours/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Migration(migrations.Migration):
name='Company',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=100)),
('slug', models.SlugField(unique=True)),
('logo', models.FileField(null=True, upload_to=b'logo', blank=True)),
('name', models.CharField(verbose_name='Name', max_length=100)),
('slug', models.SlugField(verbose_name='Slug', unique=True)),
('logo', models.FileField(verbose_name='Logo', null=True, blank=True, upload_to=b'logo')),
],
options={
'swappable': 'OPENINGHOURS_PREMISES_MODEL',
Expand All @@ -26,32 +26,37 @@ class Migration(migrations.Migration):
name='ClosingRules',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('start', models.DateTimeField()),
('end', models.DateTimeField()),
('reason', models.TextField(null=True, blank=True)),
('start', models.DateTimeField(verbose_name='Start')),
('end', models.DateTimeField(verbose_name='End')),
('reason', models.TextField(verbose_name='Reason', null=True, blank=True)),
],
options={
'verbose_name': 'Closing Rule',
'verbose_name_plural': 'Closing Rules',
'ordering': ['start'],
},
),
migrations.CreateModel(
name='OpeningHours',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('weekday', models.IntegerField(choices=[(1, 'Monday'), (2, 'Tuesday'), (3, 'Wednesday'), (4, 'Thursday'), (5, 'Friday'), (6, 'Saturday'), (7, 'Sunday')])),
('from_hour', models.TimeField()),
('to_hour', models.TimeField()),
('company', models.ForeignKey(to=PREMISES_MODEL)),
('weekday', models.IntegerField(verbose_name='Weekday', choices=[
(1, 'Monday'), (2, 'Tuesday'), (3, 'Wednesday'), (4, 'Thursday'),
(5, 'Friday'), (6, 'Saturday'), (7, 'Sunday')
])),
('from_hour', models.TimeField(verbose_name='Opening')),
('to_hour', models.TimeField(verbose_name='Closing')),
('company', models.ForeignKey(verbose_name='Company', to=PREMISES_MODEL, on_delete=models.CASCADE)),
],
options={
'verbose_name': 'Opening Hours',
'verbose_name_plural': 'Opening Hours',
'ordering': ['company', 'weekday', 'from_hour'],
},
),
migrations.AddField(
model_name='closingrules',
name='company',
field=models.ForeignKey(to=PREMISES_MODEL),
field=models.ForeignKey(verbose_name='Company', to=PREMISES_MODEL, on_delete=models.CASCADE),
),
]
77 changes: 0 additions & 77 deletions openinghours/migrations/0002_auto_20170915_0912.py

This file was deleted.

14 changes: 5 additions & 9 deletions openinghours/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import gettext_lazy as _
from openinghours.app_settings import PREMISES_MODEL

# isoweekday
Expand All @@ -17,7 +14,6 @@
]


@python_2_unicode_compatible
class Company(models.Model):
"""
Default model for company premises, which can be
Expand All @@ -36,7 +32,6 @@ def __str__(self):
return self.name


@python_2_unicode_compatible
class OpeningHours(models.Model):
"""
Store opening times of company premises,
Expand All @@ -48,7 +43,8 @@ class Meta:
verbose_name_plural = _('Opening Hours')
ordering = ['company', 'weekday', 'from_hour']

company = models.ForeignKey(PREMISES_MODEL, verbose_name=_('Company'))
company = models.ForeignKey(PREMISES_MODEL, verbose_name=_('Company'),
on_delete=models.CASCADE)
weekday = models.IntegerField(_('Weekday'), choices=WEEKDAYS)
from_hour = models.TimeField(_('Opening'))
to_hour = models.TimeField(_('Closing'))
Expand All @@ -62,7 +58,6 @@ def __str__(self):
}


@python_2_unicode_compatible
class ClosingRules(models.Model):
"""
Used to overrule the OpeningHours. This will "close" the store due to
Expand All @@ -73,7 +68,8 @@ class Meta:
verbose_name_plural = _('Closing Rules')
ordering = ['start']

company = models.ForeignKey(PREMISES_MODEL, verbose_name=_('Company'))
company = models.ForeignKey(PREMISES_MODEL, verbose_name=_('Company'),
on_delete=models.CASCADE)
start = models.DateTimeField(_('Start'))
end = models.DateTimeField(_('End'))
reason = models.TextField(_('Reason'), null=True, blank=True)
Expand Down
14 changes: 8 additions & 6 deletions openinghours/templates/openinghours/edit_form.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% load i18n %}

<script>
$(function(){
// Toggle display for 2nd set of hours
Expand Down Expand Up @@ -54,22 +56,22 @@
<span class="weekday text-muted text-right">
{{ day.name }}</span>
{{ day.slot1.opens }} - {{ day.slot1.shuts }}</span>
<span class="set2"><span class="small text-muted">and</span>
<span class="set2"><span class="small text-muted">{% trans 'and' %}</span>
{{ day.slot2.opens }} - {{ day.slot2.shuts }}</span>
<label><input type="checkbox" class="closed"
id="closed{{ day.number }}"
{% if day.closed %}checked{% endif %}> Closed</label>
{% if day.closed %}checked{% endif %}> {% trans 'Closed' %}</label>
{% if forloop.first %}
<button class="btn btn-default btn-xs" id="repeat">
Apply to all days</button>
{% trans 'Apply to all days' %}</button>
{% endif %}
</div>
{% endfor %}
<p><label><input type="checkbox" id="two_sets"
{% if two_sets %}checked{% endif %}>
There are 2 sets of hours for 1 day.</label>
{% trans 'There are 2 sets of hours for 1 day.' %}</label>
<p>
<button class="btn btn-primary">Apply</button>
<a href="../" class="btn btn-default">Cancel</a>
<button class="btn btn-primary">{% trans 'Apply' %}</button>
<a href="../" class="btn btn-default">{% trans 'Cancel' %}</a>
{% csrf_token %}
</form>
2 changes: 2 additions & 0 deletions openinghours/templates/openinghours/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ <h2>Check current situation</h2>
</pre>
{% endverbatim %}

<p><b>{{ location.name }}</b><br>
In {{ timezone }} it is now {% now "SHORT_DATETIME_FORMAT" %}
{% is_open location as open %}
{% if open %}
<div class="alert alert-success">Come in, we're open!</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table>
<table class="table table-striped table-hover">
{% for day in days %}
<tr>
<th>{% ifchanged %}{{ day.name }}{% endifchanged %}</th>
Expand Down
Loading