Giter VIP home page Giter VIP logo

django-openinghours's Introduction

Django Opening Hours

https://travis-ci.org/arteria/django-openinghours.svg?branch=master https://coveralls.io/repos/github/arteria/django-openinghours/badge.svg?branch=master

A reusable Django app to work with opening hours.

Comes with the following features:

  • Multiple company (premises) support, customisable to directly plug in your own model.
  • Able to show if a company is currently open (“Come in, we’re open!”, “Sorry, we’re closed.”).
  • Able to list the opening hours, e.g. Monday 9am to 5pm, etc. for multiple company premises.
  • Possible to define opening hours passing midnight.
  • Possible to define closing hours, e.g. for holiday.

Installation

To get the latest stable release from PyPi

pip install django-openinghours

To get the latest version from GitHub

pip install -e git+git://github.com/arteria/django-openinghours.git#egg=openinghours-master

Add openinghours to your INSTALLED_APPS

INSTALLED_APPS = (
    ...,
    'openinghours',
)

You can use the company model provided or plug your own using settings.py:

OPENINGHOURS_PREMISES_MODEL = 'yourcastleapp.Castle'

Add the openinghours URLs to your urls.py

urlpatterns = [
    ...
    url(r'^openinghours/', include('openinghours.urls')),
]

Before your tags/filters are available in your templates, load them using

{% load openinghours_tags %}

Create your tables

./manage.py migrate openinghours

Set 'TIME_ZONE' in your project settings.

Usage

Set up a company

This app supports multiple companies (or your custom model) with multiple opening and closing hours.

Set up opening hours

Used to describe when premises are open, defined on a daily basis (per day) by defining one or more start and end times of opening slots.

Optionally, set up the closing hour rules

This is used to define when premises are closed (e.g. due to a holiday, absences, sickness or similar). Please note that the closing hours override the opening hours.

You can find examples of how to use this app in our templates.

Remarks

Opening hours is built using datetime’s isoweekday. This means Monday is represented by number 1 and Sunday by 7.

Planned features

Priority 1 = high/must have, 2 = and 3 = low/nice to have

  • 1 Migrate to Django’s timezone
  • 2 Docs for live testing of defined rules
  • 3 Shortcut for everyday (1-7) = 0 in WEEKDAYS, or 8 = monday to friday, etc.
  • 3 Global closing hours to override all companies. Use cases: close a whole shopping centre

See also CHANGELOG and UPGRADING docs.

Contribute

Just send us your pull request. File and issue. Use it. Talk about it.

django-openinghours is free software. If you find it useful and would like to give back, please consider to make a donation using Bitcoin https://blockchain.info/payment_request?address=1AJkbQdcNkrHzxi91mB1kkPxh4t4BJ4hu4 or PayPal https://www.paypal.me/arteriagmbh. Thank you!

django-openinghours's People

Contributors

bitdeli-chef avatar fmalina avatar imposeren avatar jvamvas avatar philippeowagner avatar vlinhart avatar walterrenner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-openinghours's Issues

on_delete

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)

Adding a feature: Special Opening Hours

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

Opening hours are not ordered by weekday, when no Data is given for a day

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

Concise not working if two sets

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.

makemigrations fail after setting OPENINGHOURS_PREMISES_MODEL

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'

how to make query that returns companies that are open?

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

Support for variable opening hours

Is 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.

Setting Opening Hours

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)

Use get_model() from django.apps to fix incompatibility with django-q

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.

Validation

Currently there are no validations in place to check for the following:

  1. from_hour can be bigger then to_hour (in one set)
  2. 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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.