GithubHelp home page GithubHelp logo

arteria / django-openinghours Goto Github PK

View Code? Open in Web Editor NEW
57.0 57.0 38.0 127 KB

Allows to define opening hours and to verify if something, for example a store, is currently open.

License: MIT License

Makefile 0.67% Python 87.69% HTML 11.64%

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

Watchers

 avatar  avatar  avatar  avatar

django-openinghours's Issues

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

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.

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'

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

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)

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!

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

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)

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.

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.