arteria / django-openinghours Goto Github PK
View Code? Open in Web Editor NEWAllows to define opening hours and to verify if something, for example a store, is currently open.
License: MIT License
Allows to define opening hours and to verify if something, for example a store, is currently open.
License: MIT License
...are not full implemented, views.py still import Company from openinghours.models
from openinghours.models import Company
apekatten@dev01:~/djangoproject$ python3 manage.py makemigrations
Migrations for 'openinghours':
/usr/local/lib/python3.5/dist-packages/openinghours/migrations/0002_auto_20170715_0103.py
- Create model Company
- Change Meta options on closingrules
- Change Meta options on openinghours
- Alter field company on closingrules
- Alter field end on closingrules
- Alter field reason on closingrules
- Alter field start on closingrules
- Alter field company on openinghours
- Alter field from_hour on openinghours
- Alter field to_hour on openinghours
- Alter field weekday on openinghours
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/makemigrations.py", line 193, in handle
self.write_migration_files(changes)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/makemigrations.py", line 232, in write_migration_files
with io.open(writer.path, "w", encoding='utf-8') as fh:
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/openinghours/migrations/0002_auto_20170715_0103.py'
to display the opening hours.
In openinghours.utils.is_open, what's the purpose of this nested condition?
(now_time < datetime.time(23, 59, 59))
Can someone give an example of why it's needed? Thanks!
Will this project receive support for newer django versions?
#16
I am still getting this issue. Could it possible to help me to resolve this issue?
Hello guys,
I'm new to Django and new to Python, but :
I have installed successfully the app,in the admin it's work,
but i cannot add the opening class object to a field as ForeinKey :
I think I'm missing something... I also set in settings.py
OPENINGHOURS_PREMISES_MODEL = 'app.Example'
Is there any solution, to attach the opening hours to a custom model?
I already know is my fault, but can I have some tips?
Thank you
from openinghours.models import OpeningHours
class Example(model.Models):
opening_hours = models.ForeignKey('OpeningHours',on_delete=models.PROTECT)
on delete needs to be added to both the closing and opening where it's
company = models.ForeignKey(PREMISES_MODEL, verbose_name=_('Company'))
as newer versions such as 2.0 require an on_delete now
company = models.ForeignKey(PREMISES_MODEL, verbose_name=_('Company'), on_delete=models.CASCADE)
I would like to do something like this:
open_shops = Shop.objects.filter(is_open=True)
But how ? :)
and I'd like to add is_open to my model.
update:
Im thinking something like adding this to my Shop model:
@property
def tz_info(self):
return geocoders.GoogleV3().timezone((self.location.y,self.location.x))
@property
def is_open(self):
now = datetime.now(tz=self.tz_info)
now_time = time(now.hour, now.minute, now.second)
if not ClosingRules.objects.filter(company=self, start__lte=now, end__gte=now).count():
ohs = OpeningHours.objects.filter(company=self)
for oh in ohs:
is_open = False
# start and end is on the same day
if (oh.weekday == now.isoweekday() and oh.from_hour <= now_time and now_time <= oh.to_hour):
is_open = oh
# start and end are not on the same day and we test on the start day
if (oh.weekday == now.isoweekday() and oh.from_hour <= now_time and ((oh.to_hour < oh.from_hour) and (now_time < time(23, 59, 59)))):
is_open = oh
# start and end are not on the same day and we test on the end day
if (oh.weekday == (now.isoweekday() - 1) % 7 and oh.from_hour >= now_time and oh.to_hour >= now_time and oh.to_hour < oh.from_hour):
is_open = oh
# print " 'Special' case after midnight", oh
if is_open is not False:
return oh
return False
The companyOpeningHoursList templatetag just "appends" the days where no openinghours are defined.
So when a company is closed on monday and saturday is will render the days tuesday to friday and sunday and append monday and saturday after saturday, which is confusing for the customers.
Example:
Tuesday: 9 - 5
Wednesday: 9 - 5
Thursday: 9 - 5
Friday: 9 - 5
Sunday: 9 - 5
Monday: closed
Sunday: closed
I expected the following output:
Monday: closed
Tuesday: 9 - 5
Wednesday: 9 - 5
Thursday: 9 - 5
Friday: 9 - 5
Sunday: 9 - 5
Sunday: closed
Currently there are no validations in place to check for the following:
from_hour
can be bigger then to_hour
(in one set)from_hour
in set 2 can be smaller then to_hour
in set 1.Is there a way to implement that?
This app is very nice and also very unique. There aren't any useful other modules. So it would be nice, if we can upgrade this module for professional use. I can also assist you other than reporting bugs and feature requests. Let me know what I can do!
So this is a bit of a weird issue. I have been using django-openinghours
in a project for a while and not having any issues, and today I was working on integrating https://github.com/Koed00/django-q into the project.
For some reason, django-openinghours
and django-q
are not compatible with each other, and as soon as I add django_q
to my INSTALLED_APPS
in my project's settings.py
, I get the following error when trying to load any page in the Django Admin:
Traceback:
File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django/template/utils.py" in __getitem__
65. return self._engines[alias]
During handling of the above exception ('django'), another exception occurred:
File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django/template/backends/django.py" in get_package_libraries
126. module = import_module(entry[1])
File "/Users/jordan/Development/my_project/venv/lib/python3.5/importlib/__init__.py" in import_module
126. return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/openinghours/templatetags/openinghours_tags.py" in <module>
6. from openinghours import utils
File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/openinghours/utils.py" in <module>
9. from compat import get_model
Exception Type: InvalidTemplateLibrary at /admin/login/
Exception Value: Invalid template library specified. ImportError raised when trying to load 'openinghours.templatetags.openinghours_tags': cannot import name 'get_model'
If I remove django_q
from my INSTALLED_APPS
, the error goes away and everything works fine again, but then I can't use django-q
obviously, so I've managed to find another solution. If I update the django-openinghours
code to use get_model()
from django.apps
instead of get_model()
from compat
, I no longer get this InvalidTemplateLibrary
exception and both django-openinghours
and django-q
work correctly. I have created a fork of django-openinghours
which has this fix, which you can see at jordanmkoncz@4e23d45. Note that this fork was done from the v0.1.3 commit, as this is the version currently published to PyPI and the one I have been using in my project.
Hey,
the concise display of the openinghours do not work, if the company has a break. It will display all of the weekdays. I managed to find the potential source:
openinghours/templatetags/openinghours_tags.py
lines 141 - 150
for day in days:
if 'hours' not in current_set.keys():
current_set = {'day_names': [day['name']],
'hours': day['hours']}
elif day['hours'] != current_set['hours']: # note 1
concise_days.append(current_set)
current_set = {'day_names': [day['name']],
'hours': day['hours']}
else:
current_set['day_names'].append(day['name'])
Note 1: Here, if you have two sets, it will change current_set. Thus, day['hours'] != current_set['hours']
will always be true for those cases. It should check, if there is a day['hours']
in concise_days
and do actions according to it existence.
Do you guys have a solution for this? I am struggling with it.
Hi,
I am maintaining a project that makes use of django-openinghours. There is a feature in the roadmap to support bank holiday openings (the project is UK based). The requirements are to have different opening hours, not necessarily reducing the normal hours, could be a later opening etc.
I am proposing adding a "SpecialOpeningHours" to this project (when this feature gets to the front of the roadmap), so I'd like to discuss it here, to make sure I do it in a way that is open to being merged back in.
I notice that there are a couple of unmerged PRs, so I wonder if this project is still being maintained? One of the PRs by @fmalina is larger PR and implies you are actively using the code, forgive the django newbie question, but how are you managing this within your projects? If this project is dormant, does it make sense to fork it and maintain it elsewhere?
Thanks in advance!
Adam
datetime.datetime.now()
sIs it currently possible to support a locations opening hours that are different at different times of the year?
For example, a public library might have different hours during the summer months when kids aren't in school from the hours that they have during the school year.
These aren't closed times, but they are different regular hours times for different dates.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.