├── .gitignore ├── .travis.yml ├── AUTHORS.rst ├── CONTRIBUTING.rst ├── HISTORY.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── docs ├── Makefile ├── authors.rst ├── conf.py ├── contributing.rst ├── history.rst ├── index.rst ├── installation.rst ├── make.bat ├── readme.rst └── usage.rst ├── manage.py ├── requirements-test.txt ├── requirements.txt ├── runtests.py ├── settings.py ├── setup.cfg ├── setup.py ├── tests ├── __init__.py └── test_schedule.py ├── tinyschedule ├── __init__.py ├── admin.py ├── forms.py ├── migrations │ ├── 0001_initial.py │ └── __init__.py ├── models.py └── views.py └── tox.ini /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.py[cod] 3 | 4 | # C extensions 5 | *.so 6 | 7 | # Packages 8 | *.egg 9 | *.egg-info 10 | dist 11 | build 12 | eggs 13 | parts 14 | bin 15 | var 16 | sdist 17 | develop-eggs 18 | .installed.cfg 19 | lib 20 | lib64 21 | 22 | # Installer logs 23 | pip-log.txt 24 | 25 | # Unit test / coverage reports 26 | .coverage 27 | .tox 28 | nosetests.xml 29 | 30 | # Translations 31 | *.mo 32 | 33 | # Mr Developer 34 | .mr.developer.cfg 35 | .project 36 | .pydevproject 37 | 38 | # Complexity 39 | output/*.html 40 | output/*/index.html 41 | 42 | # Sphinx 43 | docs/_build 44 | 45 | .idea/ 46 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file for automatic testing at travis-ci.org 2 | 3 | language: python 4 | 5 | python: 6 | - "3.5" 7 | - "2.7" 8 | 9 | # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors 10 | install: pip install -r requirements-test.txt 11 | 12 | # command to run tests using coverage, e.g. python setup.py test 13 | script: coverage run --source tinyschedule runtests.py 14 | 15 | # report coverage to coveralls.io 16 | after_success: coveralls 17 | -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | Credits 3 | ======= 4 | 5 | Development Lead 6 | ---------------- 7 | 8 | * Jef Geskens 9 | 10 | Contributors 11 | ------------ 12 | 13 | None yet. Why not be the first? 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Contributing 3 | ============ 4 | 5 | Contributions are welcome, and they are greatly appreciated! Every 6 | little bit helps, and credit will always be given. 7 | 8 | You can contribute in many ways: 9 | 10 | Types of Contributions 11 | ---------------------- 12 | 13 | Report Bugs 14 | ~~~~~~~~~~~ 15 | 16 | Report bugs at https://github.com/jgeskens/django-tinyschedule/issues. 17 | 18 | If you are reporting a bug, please include: 19 | 20 | * Your operating system name and version. 21 | * Any details about your local setup that might be helpful in troubleshooting. 22 | * Detailed steps to reproduce the bug. 23 | 24 | Fix Bugs 25 | ~~~~~~~~ 26 | 27 | Look through the GitHub issues for bugs. Anything tagged with "bug" 28 | is open to whoever wants to implement it. 29 | 30 | Implement Features 31 | ~~~~~~~~~~~~~~~~~~ 32 | 33 | Look through the GitHub issues for features. Anything tagged with "feature" 34 | is open to whoever wants to implement it. 35 | 36 | Write Documentation 37 | ~~~~~~~~~~~~~~~~~~~ 38 | 39 | django-tinyschedule could always use more documentation, whether as part of the 40 | official django-tinyschedule docs, in docstrings, or even on the web in blog posts, 41 | articles, and such. 42 | 43 | Submit Feedback 44 | ~~~~~~~~~~~~~~~ 45 | 46 | The best way to send feedback is to file an issue at https://github.com/jgeskens/django-tinyschedule/issues. 47 | 48 | If you are proposing a feature: 49 | 50 | * Explain in detail how it would work. 51 | * Keep the scope as narrow as possible, to make it easier to implement. 52 | * Remember that this is a volunteer-driven project, and that contributions 53 | are welcome :) 54 | 55 | Get Started! 56 | ------------ 57 | 58 | Ready to contribute? Here's how to set up `django-tinyschedule` for local development. 59 | 60 | 1. Fork the `django-tinyschedule` repo on GitHub. 61 | 2. Clone your fork locally:: 62 | 63 | $ git clone git@github.com:your_name_here/django-tinyschedule.git 64 | 65 | 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: 66 | 67 | $ mkvirtualenv django-tinyschedule 68 | $ cd django-tinyschedule/ 69 | $ python setup.py develop 70 | 71 | 4. Create a branch for local development:: 72 | 73 | $ git checkout -b name-of-your-bugfix-or-feature 74 | 75 | Now you can make your changes locally. 76 | 77 | 5. When you're done making changes, check that your changes pass flake8 and the 78 | tests, including testing other Python versions with tox:: 79 | 80 | $ flake8 schedule tests 81 | $ python setup.py test 82 | $ tox 83 | 84 | To get flake8 and tox, just pip install them into your virtualenv. 85 | 86 | 6. Commit your changes and push your branch to GitHub:: 87 | 88 | $ git add . 89 | $ git commit -m "Your detailed description of your changes." 90 | $ git push origin name-of-your-bugfix-or-feature 91 | 92 | 7. Submit a pull request through the GitHub website. 93 | 94 | Pull Request Guidelines 95 | ----------------------- 96 | 97 | Before you submit a pull request, check that it meets these guidelines: 98 | 99 | 1. The pull request should include tests. 100 | 2. If the pull request adds functionality, the docs should be updated. Put 101 | your new functionality into a function with a docstring, and add the 102 | feature to the list in README.rst. 103 | 3. The pull request should work for Python 2.7, and 3.3, and for PyPy. Check 104 | https://travis-ci.org/jgeskens/django-tinyschedule/pull_requests 105 | and make sure that the tests pass for all supported Python versions. 106 | 107 | Tips 108 | ---- 109 | 110 | To run a subset of tests:: 111 | 112 | $ python -m unittest tests.test_schedule 113 | -------------------------------------------------------------------------------- /HISTORY.rst: -------------------------------------------------------------------------------- 1 | .. :changelog: 2 | 3 | History 4 | ------- 5 | 6 | 0.1.0 (2015-02-03) 7 | ++++++++++++++++++ 8 | 9 | * First release on PyPI. 10 | 11 | 0.1.1 (2015-02-04) 12 | ++++++++++++++++++ 13 | 14 | * Add AbstractSchedule 15 | 16 | 0.1.2 (2015-02-04) 17 | ++++++++++++++++++ 18 | 19 | * Renamed package from ``schedule`` to a less general name ``tinyschedule`` to avoid conflicts. 20 | 21 | 0.1.3 (2015-02-05) 22 | ++++++++++++++++++ 23 | 24 | * Small bugfix: if you subclass AbstractSchedule, you will now get your own class when using ``ScheduleManager.lookup(...)`` 25 | 26 | 0.1.4 (2015-03-10) 27 | ++++++++++++++++++ 28 | 29 | * Bugfix in __getitem__ 30 | 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Jef Geskens 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | * Neither the name of django-tinyschedule nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include AUTHORS.rst 2 | include CONTRIBUTING.rst 3 | include HISTORY.rst 4 | include LICENSE 5 | include README.rst 6 | recursive-include tinyschedule *.html *.png *.gif *js *.css *jpg *jpeg *svg *py 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean-pyc clean-build docs 2 | 3 | help: 4 | @echo "clean-build - remove build artifacts" 5 | @echo "clean-pyc - remove Python file artifacts" 6 | @echo "lint - check style with flake8" 7 | @echo "test - run tests quickly with the default Python" 8 | @echo "testall - run tests on every Python version with tox" 9 | @echo "coverage - check code coverage quickly with the default Python" 10 | @echo "docs - generate Sphinx HTML documentation, including API docs" 11 | @echo "release - package and upload a release" 12 | @echo "sdist - package" 13 | 14 | clean: clean-build clean-pyc 15 | 16 | clean-build: 17 | rm -fr build/ 18 | rm -fr dist/ 19 | rm -fr *.egg-info 20 | 21 | clean-pyc: 22 | find . -name '*.pyc' -exec rm -f {} + 23 | find . -name '*.pyo' -exec rm -f {} + 24 | find . -name '*~' -exec rm -f {} + 25 | 26 | lint: 27 | flake8 tinyschedule tests 28 | 29 | test: 30 | python runtests.py test 31 | 32 | test-all: 33 | tox 34 | 35 | coverage: 36 | coverage run --source tinyschedule runtests.py 37 | coverage report -m 38 | coverage html 39 | open htmlcov/index.html 40 | 41 | docs: 42 | rm -f docs/django-tinyschedule.rst 43 | rm -f docs/modules.rst 44 | sphinx-apidoc -o docs/ tinyschedule 45 | $(MAKE) -C docs clean 46 | $(MAKE) -C docs html 47 | open docs/_build/html/index.html 48 | 49 | release: clean 50 | python setup.py sdist upload 51 | python setup.py bdist_wheel upload 52 | 53 | sdist: clean 54 | python setup.py sdist 55 | ls -l dist 56 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ============================= 2 | django-tinyschedule 3 | ============================= 4 | 5 | .. image:: https://badge.fury.io/py/django-tinyschedule.png 6 | :target: https://badge.fury.io/py/django-tinyschedule 7 | 8 | .. image:: https://travis-ci.org/jgeskens/django-tinyschedule.png?branch=master 9 | :target: https://travis-ci.org/jgeskens/django-tinyschedule 10 | 11 | .. image:: https://coveralls.io/repos/jgeskens/django-tinyschedule/badge.svg?branch=master 12 | :target: https://coveralls.io/r/jgeskens/django-tinyschedule?branch=master 13 | 14 | A small package for managing schedules in Django 15 | 16 | Documentation 17 | ------------- 18 | 19 | The full documentation is at https://django-tinyschedule.readthedocs.org. 20 | 21 | Quickstart 22 | ---------- 23 | 24 | Install django-tinyschedule:: 25 | 26 | pip install django-tinyschedule 27 | 28 | Then use it in a project:: 29 | 30 | import tinyschedule 31 | 32 | Features 33 | -------- 34 | 35 | * Easily define schedules using the Schedule model 36 | * Make your own Schedule-like models by extending ScheduleBase 37 | * Tiny and lightweight, easy to grasp 38 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/complexity.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/complexity.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/complexity" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/complexity" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /docs/authors.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../AUTHORS.rst 2 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # complexity documentation build configuration file, created by 4 | # sphinx-quickstart on Tue Jul 9 22:26:36 2013. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | cwd = os.getcwd() 22 | parent = os.path.dirname(cwd) 23 | sys.path.append(parent) 24 | 25 | import tinyschedule 26 | 27 | # -- General configuration ----------------------------------------------------- 28 | 29 | # If your documentation needs a minimal Sphinx version, state it here. 30 | #needs_sphinx = '1.0' 31 | 32 | # Add any Sphinx extension module names here, as strings. They can be extensions 33 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 34 | extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] 35 | 36 | # Add any paths that contain templates here, relative to this directory. 37 | templates_path = ['_templates'] 38 | 39 | # The suffix of source filenames. 40 | source_suffix = '.rst' 41 | 42 | # The encoding of source files. 43 | #source_encoding = 'utf-8-sig' 44 | 45 | # The master toctree document. 46 | master_doc = 'index' 47 | 48 | # General information about the project. 49 | project = u'django-tinyschedule' 50 | copyright = u'2015, Jef Geskens' 51 | 52 | # The version info for the project you're documenting, acts as replacement for 53 | # |version| and |release|, also used in various other places throughout the 54 | # built documents. 55 | # 56 | # The short X.Y version. 57 | version = tinyschedule.__version__ 58 | # The full version, including alpha/beta/rc tags. 59 | release = tinyschedule.__version__ 60 | 61 | # The language for content autogenerated by Sphinx. Refer to documentation 62 | # for a list of supported languages. 63 | #language = None 64 | 65 | # There are two options for replacing |today|: either, you set today to some 66 | # non-false value, then it is used: 67 | #today = '' 68 | # Else, today_fmt is used as the format for a strftime call. 69 | #today_fmt = '%B %d, %Y' 70 | 71 | # List of patterns, relative to source directory, that match files and 72 | # directories to ignore when looking for source files. 73 | exclude_patterns = ['_build'] 74 | 75 | # The reST default role (used for this markup: `text`) to use for all documents. 76 | #default_role = None 77 | 78 | # If true, '()' will be appended to :func: etc. cross-reference text. 79 | #add_function_parentheses = True 80 | 81 | # If true, the current module name will be prepended to all description 82 | # unit titles (such as .. function::). 83 | #add_module_names = True 84 | 85 | # If true, sectionauthor and moduleauthor directives will be shown in the 86 | # output. They are ignored by default. 87 | #show_authors = False 88 | 89 | # The name of the Pygments (syntax highlighting) style to use. 90 | pygments_style = 'sphinx' 91 | 92 | # A list of ignored prefixes for module index sorting. 93 | #modindex_common_prefix = [] 94 | 95 | # If true, keep warnings as "system message" paragraphs in the built documents. 96 | #keep_warnings = False 97 | 98 | 99 | # -- Options for HTML output --------------------------------------------------- 100 | 101 | # The theme to use for HTML and HTML Help pages. See the documentation for 102 | # a list of builtin themes. 103 | html_theme = 'default' 104 | 105 | # Theme options are theme-specific and customize the look and feel of a theme 106 | # further. For a list of options available for each theme, see the 107 | # documentation. 108 | #html_theme_options = {} 109 | 110 | # Add any paths that contain custom themes here, relative to this directory. 111 | #html_theme_path = [] 112 | 113 | # The name for this set of Sphinx documents. If None, it defaults to 114 | # " v documentation". 115 | #html_title = None 116 | 117 | # A shorter title for the navigation bar. Default is the same as html_title. 118 | #html_short_title = None 119 | 120 | # The name of an image file (relative to this directory) to place at the top 121 | # of the sidebar. 122 | #html_logo = None 123 | 124 | # The name of an image file (within the static path) to use as favicon of the 125 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 126 | # pixels large. 127 | #html_favicon = None 128 | 129 | # Add any paths that contain custom static files (such as style sheets) here, 130 | # relative to this directory. They are copied after the builtin static files, 131 | # so a file named "default.css" will overwrite the builtin "default.css". 132 | html_static_path = ['_static'] 133 | 134 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 135 | # using the given strftime format. 136 | #html_last_updated_fmt = '%b %d, %Y' 137 | 138 | # If true, SmartyPants will be used to convert quotes and dashes to 139 | # typographically correct entities. 140 | #html_use_smartypants = True 141 | 142 | # Custom sidebar templates, maps document names to template names. 143 | #html_sidebars = {} 144 | 145 | # Additional templates that should be rendered to pages, maps page names to 146 | # template names. 147 | #html_additional_pages = {} 148 | 149 | # If false, no module index is generated. 150 | #html_domain_indices = True 151 | 152 | # If false, no index is generated. 153 | #html_use_index = True 154 | 155 | # If true, the index is split into individual pages for each letter. 156 | #html_split_index = False 157 | 158 | # If true, links to the reST sources are added to the pages. 159 | #html_show_sourcelink = True 160 | 161 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 162 | #html_show_sphinx = True 163 | 164 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 165 | #html_show_copyright = True 166 | 167 | # If true, an OpenSearch description file will be output, and all pages will 168 | # contain a tag referring to it. The value of this option must be the 169 | # base URL from which the finished HTML is served. 170 | #html_use_opensearch = '' 171 | 172 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 173 | #html_file_suffix = None 174 | 175 | # Output file base name for HTML help builder. 176 | htmlhelp_basename = 'django-tinyscheduledoc' 177 | 178 | 179 | # -- Options for LaTeX output -------------------------------------------------- 180 | 181 | latex_elements = { 182 | # The paper size ('letterpaper' or 'a4paper'). 183 | #'papersize': 'letterpaper', 184 | 185 | # The font size ('10pt', '11pt' or '12pt'). 186 | #'pointsize': '10pt', 187 | 188 | # Additional stuff for the LaTeX preamble. 189 | #'preamble': '', 190 | } 191 | 192 | # Grouping the document tree into LaTeX files. List of tuples 193 | # (source start file, target name, title, author, documentclass [howto/manual]). 194 | latex_documents = [ 195 | ('index', 'django-tinyschedule.tex', u'django-tinyschedule Documentation', 196 | u'Jef Geskens', 'manual'), 197 | ] 198 | 199 | # The name of an image file (relative to this directory) to place at the top of 200 | # the title page. 201 | #latex_logo = None 202 | 203 | # For "manual" documents, if this is true, then toplevel headings are parts, 204 | # not chapters. 205 | #latex_use_parts = False 206 | 207 | # If true, show page references after internal links. 208 | #latex_show_pagerefs = False 209 | 210 | # If true, show URL addresses after external links. 211 | #latex_show_urls = False 212 | 213 | # Documents to append as an appendix to all manuals. 214 | #latex_appendices = [] 215 | 216 | # If false, no module index is generated. 217 | #latex_domain_indices = True 218 | 219 | 220 | # -- Options for manual page output -------------------------------------------- 221 | 222 | # One entry per manual page. List of tuples 223 | # (source start file, name, description, authors, manual section). 224 | man_pages = [ 225 | ('index', 'django-tinyschedule', u'django-tinyschedule Documentation', 226 | [u'Jef Geskens'], 1) 227 | ] 228 | 229 | # If true, show URL addresses after external links. 230 | #man_show_urls = False 231 | 232 | 233 | # -- Options for Texinfo output ------------------------------------------------ 234 | 235 | # Grouping the document tree into Texinfo files. List of tuples 236 | # (source start file, target name, title, author, 237 | # dir menu entry, description, category) 238 | texinfo_documents = [ 239 | ('index', 'django-tinyschedule', u'django-tinyschedule Documentation', 240 | u'Jef Geskens', 'django-tinyschedule', 'One line description of project.', 241 | 'Miscellaneous'), 242 | ] 243 | 244 | # Documents to append as an appendix to all manuals. 245 | #texinfo_appendices = [] 246 | 247 | # If false, no module index is generated. 248 | #texinfo_domain_indices = True 249 | 250 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 251 | #texinfo_show_urls = 'footnote' 252 | 253 | # If true, do not generate a @detailmenu in the "Top" node's menu. 254 | #texinfo_no_detailmenu = False 255 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst 2 | -------------------------------------------------------------------------------- /docs/history.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../HISTORY.rst 2 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. complexity documentation master file, created by 2 | sphinx-quickstart on Tue Jul 9 22:26:36 2013. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to django-tinyschedule's documentation! 7 | ================================================================= 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | readme 15 | installation 16 | usage 17 | contributing 18 | authors 19 | history 20 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Installation 3 | ============ 4 | 5 | At the command line:: 6 | 7 | $ easy_install django-tinyschedule 8 | 9 | Or, if you have virtualenvwrapper installed:: 10 | 11 | $ mkvirtualenv django-tinyschedule 12 | $ pip install django-tinyschedule 13 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\complexity.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\complexity.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /docs/readme.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | Usage 3 | ======== 4 | 5 | To use django-tinyschedule in a project:: 6 | 7 | import tinyschedule 8 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from __future__ import unicode_literals 4 | import os, sys 5 | 6 | if __name__ == '__main__': 7 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings') 8 | 9 | from django.core.management import execute_from_command_line 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /requirements-test.txt: -------------------------------------------------------------------------------- 1 | django>=1.7.0 2 | coverage 3 | coveralls 4 | mock>=1.0.1 5 | nose>=1.3.0 6 | django-nose>=1.2 7 | flake8>=2.1.0 8 | tox>=1.7.0 9 | six==1.9.0 10 | 11 | # Additional test requirements go here 12 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | django>=1.7.0 2 | wheel==0.24.0 3 | six==1.9.0 4 | # Additional requirements go here 5 | -------------------------------------------------------------------------------- /runtests.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | try: 4 | from django.conf import settings, global_settings 5 | 6 | settings.configure( 7 | DEBUG=True, 8 | USE_TZ=True, 9 | DATABASES={ 10 | "default": { 11 | "ENGINE": "django.db.backends.sqlite3", 12 | } 13 | }, 14 | ROOT_URLCONF="tinyschedule.urls", 15 | INSTALLED_APPS=[ 16 | "django.contrib.auth", 17 | "django.contrib.contenttypes", 18 | "django.contrib.sites", 19 | "tinyschedule", 20 | ], 21 | SITE_ID=1, 22 | NOSE_ARGS=['-s'], 23 | MIDDLEWARE_CLASSES=[ 24 | 'django.middleware.common.CommonMiddleware', 25 | ], 26 | ) 27 | 28 | try: 29 | import django 30 | setup = django.setup 31 | except AttributeError: 32 | pass 33 | else: 34 | setup() 35 | 36 | from django_nose import NoseTestSuiteRunner 37 | except ImportError: 38 | import traceback 39 | traceback.print_exc() 40 | raise ImportError("To fix this error, run: pip install -r requirements-test.txt") 41 | 42 | 43 | def run_tests(*test_args): 44 | if not test_args: 45 | test_args = ['tests'] 46 | 47 | # Run tests 48 | test_runner = NoseTestSuiteRunner(verbosity=1) 49 | 50 | failures = test_runner.run_tests(test_args) 51 | 52 | if failures: 53 | sys.exit(failures) 54 | 55 | 56 | if __name__ == '__main__': 57 | run_tests(*sys.argv[1:]) 58 | -------------------------------------------------------------------------------- /settings.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | DATABASES = { 3 | 'default': { 4 | 'ENGINE': 'django.db.backends.sqlite3', 5 | 'NAME': '/tmp/django-tinyschedule.db', 6 | } 7 | } 8 | 9 | INSTALLED_APPS = [ 10 | 'django.contrib.auth', 11 | 'django.contrib.contenttypes', 12 | 'django.contrib.sessions', 13 | 'django.contrib.sites', 14 | 15 | 'tinyschedule' 16 | ] 17 | 18 | SECRET_KEY = 'spam-spam-spam-spam' 19 | 20 | CACHES = { 21 | 'default': { 22 | 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 23 | 'LOCATION': 'spam-and-eggs' 24 | } 25 | } 26 | 27 | MIDDLEWARE_CLASSES = ( 28 | 'django.contrib.sessions.middleware.SessionMiddleware', 29 | 'django.middleware.csrf.CsrfViewMiddleware', 30 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 31 | 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 32 | ) 33 | 34 | SITE_ID = 1 35 | 36 | MEDIA_ROOT = 'media' 37 | STATIC_ROOT = 'static' 38 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [wheel] 2 | universal = 1 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import sys 6 | 7 | import tinyschedule 8 | 9 | try: 10 | from setuptools import setup 11 | except: 12 | from distutils.core import setup 13 | 14 | version = tinyschedule.__version__ 15 | 16 | if sys.argv[-1] == 'publish': 17 | os.system('python setup.py sdist upload') 18 | print("You probably want to also tag the version now:") 19 | print(" git tag -a %s -m 'version %s'" % (version, version)) 20 | print(" git push --tags") 21 | sys.exit() 22 | 23 | readme = open('README.rst').read() 24 | history = open('HISTORY.rst').read().replace('.. :changelog:', '') 25 | 26 | setup( 27 | name='django-tinyschedule', 28 | version=version, 29 | description="""A small package for managing schedules in Django""", 30 | long_description=readme + '\n\n' + history, 31 | author='Jef Geskens', 32 | author_email='jef.geskens@gmail.com', 33 | url='https://github.com/jgeskens/django-tinyschedule', 34 | packages=[ 35 | 'tinyschedule', 36 | ], 37 | include_package_data=True, 38 | install_requires=[ 39 | ], 40 | license="BSD", 41 | zip_safe=False, 42 | keywords='django-tinyschedule', 43 | classifiers=[ 44 | 'Development Status :: 2 - Pre-Alpha', 45 | 'Framework :: Django', 46 | 'Intended Audience :: Developers', 47 | 'License :: OSI Approved :: BSD License', 48 | 'Natural Language :: English', 49 | 'Programming Language :: Python :: 2', 50 | 'Programming Language :: Python :: 2.6', 51 | 'Programming Language :: Python :: 2.7', 52 | 'Programming Language :: Python :: 3', 53 | 'Programming Language :: Python :: 3.5', 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jgeskens/django-tinyschedule/270c0167a77c210e644b7e1c1ada119cd67144dd/tests/__init__.py -------------------------------------------------------------------------------- /tests/test_schedule.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | from tinyschedule.models import Schedule, ScheduleRepeatType 4 | 5 | import datetime 6 | import six 7 | 8 | 9 | class ScheduleTests(TestCase): 10 | def setUp(self): 11 | self.simple = Schedule.objects.create(start_date=datetime.date(2014, 6, 30)) 12 | 13 | self.everyday = Schedule.objects.create( 14 | start_date=datetime.date(2014, 6, 30), 15 | repeat_type=ScheduleRepeatType.DAILY) 16 | 17 | self.every3days = Schedule.objects.create( 18 | start_date=datetime.date(2014, 6, 27), 19 | repeat_type=ScheduleRepeatType.DAILY, 20 | repeat_every=3) 21 | 22 | self.every2daysuntil = Schedule.objects.create( 23 | start_date=datetime.date(2014, 6, 28), 24 | end_date=datetime.date(2014, 7, 15), 25 | repeat_type=ScheduleRepeatType.DAILY, 26 | repeat_every=2) 27 | 28 | self.every2weeksmonwedfri = Schedule.objects.create( 29 | start_date=datetime.date(2014, 6, 30), 30 | repeat_type=ScheduleRepeatType.WEEKLY, 31 | monday=True, wednesday=True, friday=True, 32 | repeat_every=2) 33 | 34 | self.everymonth = Schedule.objects.create( 35 | start_date=datetime.date(2014, 1, 15), 36 | end_date=datetime.date(2014, 8, 31), 37 | repeat_type=ScheduleRepeatType.MONTHLY) 38 | 39 | self.everymonthweekday = Schedule.objects.create( 40 | start_date=datetime.date(2014, 1, 15), 41 | end_date=datetime.date(2015, 8, 31), 42 | repeat_type=ScheduleRepeatType.MONTHLY, 43 | monthly_is_based_on_weekday=True) 44 | 45 | self.everymonthweekday2 = Schedule.objects.create( 46 | start_date=datetime.date(2014, 1, 1), 47 | end_date=datetime.date(2015, 8, 31), 48 | repeat_type=ScheduleRepeatType.MONTHLY, 49 | monthly_is_based_on_weekday=True) 50 | 51 | self.everymonthweekday3 = Schedule.objects.create( 52 | start_date=datetime.date(2014, 1, 29), 53 | end_date=datetime.date(2015, 8, 31), 54 | repeat_type=ScheduleRepeatType.MONTHLY, 55 | repeat_every=2, 56 | monthly_is_based_on_weekday=True) 57 | 58 | self.fiveoccurrences = Schedule.objects.create( 59 | start_date=datetime.date(2014, 1, 29), 60 | end_after_occurrences=5, 61 | repeat_type=ScheduleRepeatType.MONTHLY, 62 | repeat_every=2, 63 | monthly_is_based_on_weekday=True) 64 | 65 | self.yearly = Schedule.objects.create( 66 | start_date=datetime.date(2012, 2, 29), 67 | end_after_occurrences=3, 68 | repeat_type=ScheduleRepeatType.YEARLY, 69 | repeat_every=2) 70 | 71 | self.yearly2 = Schedule.objects.create( 72 | start_date=datetime.date(2015, 1, 1), 73 | end_date=datetime.date(2038, 1, 1), 74 | repeat_type=ScheduleRepeatType.YEARLY, 75 | end_after_occurrences=4) 76 | 77 | def test_lookup_simple(self): 78 | lookup = list(Schedule.objects.lookup(datetime.date(2014, 6, 30))) 79 | self.assertTrue((self.simple.start_date, self.simple, 0) in lookup) 80 | 81 | def test_lookup_every3days(self): 82 | lookup = list(Schedule.objects.lookup(datetime.date(2014, 6, 30))) 83 | self.assertTrue((datetime.date(2014, 6, 30), self.every3days, 1) in lookup) 84 | 85 | def test_lookup_every2daysuntil(self): 86 | lookup = list(Schedule.objects.lookup(datetime.date(2014, 6, 30))) 87 | self.assertTrue((datetime.date(2014, 6, 30), self.every2daysuntil, 1) in lookup) 88 | 89 | def test_lookup_period(self): 90 | lookup = list(Schedule.objects.lookup(datetime.date(2014, 7, 7), datetime.date(2014, 7, 30))) 91 | lookup = [l[:2] for l in lookup] 92 | 93 | self.assertTrue(len(lookup) > 0) 94 | 95 | self.assertFalse((datetime.date(2014, 7, 6), self.everyday) in lookup) 96 | self.assertTrue((datetime.date(2014, 7, 7), self.everyday) in lookup) 97 | self.assertTrue((datetime.date(2014, 7, 30), self.everyday) in lookup) 98 | self.assertFalse((datetime.date(2014, 7, 31), self.everyday) in lookup) 99 | 100 | self.assertTrue((datetime.date(2014, 7, 14), self.every2daysuntil) in lookup) 101 | self.assertFalse((datetime.date(2014, 7, 16), self.every2daysuntil) in lookup) 102 | 103 | self.assertFalse((datetime.date(2014, 7, 6), self.every3days) in lookup) 104 | self.assertTrue((datetime.date(2014, 7, 9), self.every3days) in lookup) 105 | self.assertTrue((datetime.date(2014, 7, 30), self.every3days) in lookup) 106 | self.assertFalse((datetime.date(2014, 8, 2), self.every3days) in lookup) 107 | 108 | self.assertTrue((datetime.date(2014, 7, 14), self.every2weeksmonwedfri) in lookup) 109 | self.assertTrue((datetime.date(2014, 7, 28), self.every2weeksmonwedfri) in lookup) 110 | 111 | def test_next_date_for_weeks(self): 112 | dates = [] 113 | date = self.every2weeksmonwedfri.start_date 114 | while date <= datetime.date(2014, 7, 30): 115 | dates.append(date) 116 | date = self.every2weeksmonwedfri.next_date(date) 117 | 118 | expected = [ 119 | datetime.date(2014, 6, 30), 120 | datetime.date(2014, 7, 2), 121 | datetime.date(2014, 7, 4), 122 | datetime.date(2014, 7, 14), 123 | datetime.date(2014, 7, 16), 124 | datetime.date(2014, 7, 18), 125 | datetime.date(2014, 7, 28), 126 | datetime.date(2014, 7, 30) 127 | ] 128 | 129 | self.assertEqual(dates, expected) 130 | 131 | def test_next_date_for_months(self): 132 | dates = [] 133 | date = self.everymonth.start_date 134 | while date <= self.everymonth.end_date: 135 | dates.append(date) 136 | date = self.everymonth.next_date(date) 137 | 138 | expected = [ 139 | datetime.date(2014, 1, 15), 140 | datetime.date(2014, 2, 15), 141 | datetime.date(2014, 3, 15), 142 | datetime.date(2014, 4, 15), 143 | datetime.date(2014, 5, 15), 144 | datetime.date(2014, 6, 15), 145 | datetime.date(2014, 7, 15), 146 | datetime.date(2014, 8, 15) 147 | ] 148 | 149 | self.assertEqual(dates, expected) 150 | 151 | def test_next_date_for_months_based_on_weekday(self): 152 | dates = [] 153 | date = self.everymonthweekday.start_date 154 | while date <= self.everymonthweekday.end_date: 155 | dates.append(date) 156 | date = self.everymonthweekday.next_date(date) 157 | 158 | expected = [ 159 | datetime.date(2014, 1, 15), 160 | datetime.date(2014, 2, 19), 161 | datetime.date(2014, 3, 19), 162 | datetime.date(2014, 4, 16), 163 | datetime.date(2014, 5, 21), 164 | datetime.date(2014, 6, 18), 165 | datetime.date(2014, 7, 16), 166 | datetime.date(2014, 8, 20), 167 | datetime.date(2014, 9, 17), 168 | datetime.date(2014, 10, 15), 169 | datetime.date(2014, 11, 19), 170 | datetime.date(2014, 12, 17), 171 | datetime.date(2015, 1, 21), 172 | datetime.date(2015, 2, 18), 173 | datetime.date(2015, 3, 18), 174 | datetime.date(2015, 4, 15), 175 | datetime.date(2015, 5, 20), 176 | datetime.date(2015, 6, 17), 177 | datetime.date(2015, 7, 15), 178 | datetime.date(2015, 8, 19) 179 | ] 180 | 181 | self.assertEqual(dates, expected) 182 | 183 | def test_next_date_for_months_based_on_weekday2(self): 184 | dates = [] 185 | date = self.everymonthweekday2.start_date 186 | while date <= self.everymonthweekday2.end_date: 187 | dates.append(date) 188 | date = self.everymonthweekday2.next_date(date) 189 | 190 | expected = [ 191 | datetime.date(2014, 1, 1), 192 | datetime.date(2014, 2, 5), 193 | datetime.date(2014, 3, 5), 194 | datetime.date(2014, 4, 2), 195 | datetime.date(2014, 5, 7), 196 | datetime.date(2014, 6, 4), 197 | datetime.date(2014, 7, 2), 198 | datetime.date(2014, 8, 6), 199 | datetime.date(2014, 9, 3), 200 | datetime.date(2014, 10, 1), 201 | datetime.date(2014, 11, 5), 202 | datetime.date(2014, 12, 3), 203 | datetime.date(2015, 1, 7), 204 | datetime.date(2015, 2, 4), 205 | datetime.date(2015, 3, 4), 206 | datetime.date(2015, 4, 1), 207 | datetime.date(2015, 5, 6), 208 | datetime.date(2015, 6, 3), 209 | datetime.date(2015, 7, 1), 210 | datetime.date(2015, 8, 5) 211 | ] 212 | 213 | self.assertEqual(dates, expected) 214 | 215 | def test_next_date_for_months_based_on_weekday3(self): 216 | dates = [] 217 | date = self.everymonthweekday3.start_date 218 | while date <= self.everymonthweekday3.end_date: 219 | dates.append(date) 220 | date = self.everymonthweekday3.next_date(date) 221 | 222 | expected = [ 223 | datetime.date(2014, 1, 29), 224 | datetime.date(2014, 3, 26), 225 | datetime.date(2014, 5, 28), 226 | datetime.date(2014, 7, 30), 227 | datetime.date(2014, 9, 24), 228 | datetime.date(2014, 11, 26), 229 | datetime.date(2015, 1, 28), 230 | datetime.date(2015, 3, 25), 231 | datetime.date(2015, 5, 27), 232 | datetime.date(2015, 7, 29) 233 | ] 234 | 235 | self.assertEqual(dates, expected) 236 | 237 | def test_lookup_end_after_occurrences(self): 238 | schedule_qs = Schedule.objects.filter(pk=self.fiveoccurrences.pk) 239 | lookup = list(Schedule.objects.lookup( 240 | datetime.date(2014, 1, 1), 241 | datetime.date(2014, 12, 31), 242 | schedule_qs)) 243 | 244 | expected = [ 245 | (datetime.date(2014, 1, 29), self.fiveoccurrences, 0), 246 | (datetime.date(2014, 3, 26), self.fiveoccurrences, 1), 247 | (datetime.date(2014, 5, 28), self.fiveoccurrences, 2), 248 | (datetime.date(2014, 7, 30), self.fiveoccurrences, 3), 249 | (datetime.date(2014, 9, 24), self.fiveoccurrences, 4) 250 | ] 251 | 252 | self.assertEqual(lookup, expected) 253 | 254 | def test_lookup_yearly(self): 255 | schedule_qs = Schedule.objects.filter(pk=self.yearly.pk) 256 | lookup = list(Schedule.objects.lookup( 257 | datetime.date(2012, 1, 1), 258 | datetime.date(2020, 12, 31), 259 | schedule_qs)) 260 | 261 | expected = [ 262 | (datetime.date(2012, 2, 29), self.yearly, 0), 263 | (datetime.date(2014, 2, 28), self.yearly, 1), 264 | (datetime.date(2016, 2, 29), self.yearly, 2) 265 | ] 266 | 267 | # for l in lookup: 268 | # print l 269 | 270 | self.assertEqual(lookup, expected) 271 | 272 | def test_occurrence_lookup(self): 273 | self.assertEqual(self.every2weeksmonwedfri[25], datetime.date(2014, 10, 22)) 274 | 275 | def test_description(self): 276 | self.assertEqual(six.text_type(self.everymonthweekday3), 277 | 'every two months on the last wednesday from 01/29/2014 until 08/31/2015') 278 | 279 | self.assertEqual(six.text_type(self.fiveoccurrences), 280 | 'every two months on the last wednesday from 01/29/2014 until 5 occurences took place') 281 | 282 | self.assertEqual(six.text_type(self.yearly), 283 | 'every two years from 02/29/2012 until 3 occurences took place') 284 | 285 | self.assertEqual(six.text_type(self.every2weeksmonwedfri), 286 | 'every two weeks on monday, wednesday, friday from 06/30/2014') 287 | 288 | self.assertEqual(six.text_type(self.everymonthweekday), 289 | 'every month on the 3rd wednesday from 01/15/2014 until 08/31/2015') 290 | 291 | self.assertEqual(six.text_type(self.everymonth), 292 | 'every month on the 15th from 01/15/2014 until 08/31/2014') 293 | 294 | self.assertEqual(six.text_type(self.simple), 295 | 'on 06/30/2014') 296 | 297 | self.assertEqual(six.text_type(self.yearly2), 298 | 'every year from 01/01/2015 until 01/01/2038 or until 4 occurences took place') 299 | 300 | with self.assertRaises(ValueError): 301 | self.simple.next_date(self.simple.start_date) 302 | 303 | def test_imports(self): 304 | from tinyschedule import admin, forms, views 305 | 306 | 307 | -------------------------------------------------------------------------------- /tinyschedule/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.2' 2 | -------------------------------------------------------------------------------- /tinyschedule/admin.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from django.contrib import admin 3 | 4 | from .models import Schedule 5 | 6 | 7 | class ScheduleAdmin(admin.ModelAdmin): 8 | list_display = ( 9 | '__str__', 10 | 'start_date', 11 | 'end_date', 12 | 'end_after_occurrences', 13 | 'repeat_type', 14 | 'repeat_every', 15 | 'monday', 16 | 'tuesday', 17 | 'wednesday', 18 | 'thursday', 19 | 'friday', 20 | 'saturday', 21 | 'sunday', 22 | 'monthly_is_based_on_weekday' 23 | ) 24 | list_filter = ('repeat_type',) 25 | date_hierarchy = 'start_date' 26 | admin.site.register(Schedule, ScheduleAdmin) 27 | -------------------------------------------------------------------------------- /tinyschedule/forms.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from django import forms 3 | from .models import Schedule 4 | 5 | 6 | class ScheduleForm(forms.ModelForm): 7 | class Meta: 8 | model = Schedule 9 | exclude = () 10 | -------------------------------------------------------------------------------- /tinyschedule/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | from django.db import models, migrations 5 | import datetime 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Schedule', 16 | fields=[ 17 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), 18 | ('start_date', models.DateField(default=datetime.datetime.now)), 19 | ('end_date', models.DateField(null=True, blank=True)), 20 | ('end_after_occurrences', models.PositiveIntegerField(default=0)), 21 | ('repeat_type', models.CharField(default='none', max_length=32, choices=[('none', 'None'), ('daily', 'Daily'), ('weekly', 'Weekly'), ('monthly', 'Monthly'), ('yearly', 'Yearly')])), 22 | ('repeat_every', models.PositiveIntegerField(default=1)), 23 | ('monthly_is_based_on_weekday', models.BooleanField(default=False)), 24 | ('monday', models.BooleanField(default=False)), 25 | ('tuesday', models.BooleanField(default=False)), 26 | ('wednesday', models.BooleanField(default=False)), 27 | ('thursday', models.BooleanField(default=False)), 28 | ('friday', models.BooleanField(default=False)), 29 | ('saturday', models.BooleanField(default=False)), 30 | ('sunday', models.BooleanField(default=False)), 31 | ], 32 | options={ 33 | 'abstract': False, 34 | }, 35 | bases=(models.Model,), 36 | ), 37 | ] 38 | -------------------------------------------------------------------------------- /tinyschedule/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jgeskens/django-tinyschedule/270c0167a77c210e644b7e1c1ada119cd67144dd/tinyschedule/migrations/__init__.py -------------------------------------------------------------------------------- /tinyschedule/models.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from django.db import models 3 | from django.db.models import Q 4 | from django.utils import formats 5 | from django.template.defaultfilters import pluralize 6 | from django.contrib.humanize.templatetags.humanize import ordinal, apnumber 7 | 8 | import datetime 9 | import six 10 | 11 | 12 | class ScheduleRepeatType(object): 13 | NONE = 'none' 14 | DAILY = 'daily' 15 | WEEKLY = 'weekly' 16 | MONTHLY = 'monthly' 17 | YEARLY = 'yearly' 18 | 19 | choices = ( 20 | (NONE, 'None'), 21 | (DAILY, 'Daily'), 22 | (WEEKLY, 'Weekly'), 23 | (MONTHLY, 'Monthly'), 24 | (YEARLY, 'Yearly'), 25 | ) 26 | 27 | choices_dict = dict(choices) 28 | 29 | pluralized_instances = ( 30 | (DAILY, 'day,days'), 31 | (WEEKLY, 'week,weeks'), 32 | (MONTHLY, 'month,months'), 33 | (YEARLY, 'year,years'), 34 | ) 35 | 36 | pluralized_instances_dict = dict(pluralized_instances) 37 | 38 | 39 | class WeekDay(object): 40 | MONDAY = 'monday' 41 | TUESDAY = 'tuesday' 42 | WEDNESDAY = 'wednesday' 43 | THURSDAY = 'thursday' 44 | FRIDAY = 'friday' 45 | SATURDAY = 'saturday' 46 | SUNDAY = 'sunday' 47 | 48 | choices = ( 49 | (MONDAY, 'monday'), 50 | (TUESDAY, 'tuesday'), 51 | (WEDNESDAY, 'wednesday'), 52 | (THURSDAY, 'thursday'), 53 | (FRIDAY, 'friday'), 54 | (SATURDAY, 'saturday'), 55 | (SUNDAY, 'sunday'), 56 | ) 57 | 58 | choices_dict = dict(choices) 59 | 60 | 61 | def add_month(date, override_day=0): 62 | date_day = date.day if override_day == 0 else override_day 63 | if date.month == 12: 64 | return datetime.date(date.year + 1, 1, date_day) 65 | else: 66 | return datetime.date(date.year, date.month + 1, date_day) 67 | 68 | 69 | def add_month_based_on_weekday(date): 70 | # Is the weekday of this date the last one? 71 | is_last_weekday = (date + datetime.timedelta(weeks=1)).month != date.month 72 | 73 | # Some magic which pushes and pulls some weeks until 74 | # it fits right. 75 | new_date = date + datetime.timedelta(weeks=4) 76 | if (new_date.day + 6) // 7 < (date.day + 6) // 7: 77 | new_date += datetime.timedelta(weeks=1) 78 | next_month = add_month(date, override_day=1) 79 | if new_date.month == (next_month.month - 1 if next_month.month > 1 else 12): 80 | new_date += datetime.timedelta(weeks=1) 81 | elif new_date.month == (next_month.month + 1 if next_month.month < 12 else 1): 82 | new_date += datetime.timedelta(weeks=-1) 83 | 84 | # If the weekdate of the original date was the last one, 85 | # and there is some room left, add a week extra so this 86 | # will result in a last weekday of the month again. 87 | if is_last_weekday and (new_date + datetime.timedelta(weeks=1)).month == new_date.month: 88 | new_date += datetime.timedelta(weeks=1) 89 | 90 | return new_date 91 | 92 | 93 | class ScheduleManager(models.Manager): 94 | def lookup(self, date, end_date=None, schedules_queryset=None): 95 | end_date = end_date or date 96 | schedules_queryset = schedules_queryset or self.all() 97 | for schedule in schedules_queryset.filter( 98 | start_date__gte=date, 99 | end_date__isnull=True, 100 | repeat_type=ScheduleRepeatType.NONE 101 | ).filter(start_date__lte=end_date): 102 | yield schedule.start_date, schedule, 0 103 | 104 | def check_repeating_patterns(schedules): 105 | for schedule in schedules: 106 | for i, occurrence in enumerate(schedule.iterate_occurrences(end_date)): 107 | if occurrence >= date: 108 | yield occurrence, schedule, i 109 | 110 | for schedule_pair in check_repeating_patterns( 111 | schedules_queryset.filter( 112 | (Q(start_date__lte=date) | Q(start_date__lte=end_date)) 113 | & 114 | (Q(end_date__gte=date) | Q(end_date__gte=end_date)) 115 | ).exclude(repeat_type=ScheduleRepeatType.NONE) 116 | ): 117 | yield schedule_pair 118 | 119 | for schedule_pair in check_repeating_patterns( 120 | schedules_queryset.filter( 121 | Q(start_date__lte=date) | Q(start_date__lte=end_date) 122 | ).filter( 123 | end_date__isnull=True, 124 | ).exclude(repeat_type=ScheduleRepeatType.NONE) 125 | ): 126 | yield schedule_pair 127 | 128 | @six.python_2_unicode_compatible 129 | class AbstractSchedule(models.Model): 130 | start_date = models.DateField(default=datetime.datetime.now) 131 | end_date = models.DateField(blank=True, null=True) 132 | end_after_occurrences = models.PositiveIntegerField(default=0) 133 | repeat_type = models.CharField(max_length=32, choices=ScheduleRepeatType.choices, default=ScheduleRepeatType.NONE) 134 | repeat_every = models.PositiveIntegerField(default=1) 135 | monthly_is_based_on_weekday = models.BooleanField(blank=True, default=False) 136 | monday = models.BooleanField(blank=True, default=False) 137 | tuesday = models.BooleanField(blank=True, default=False) 138 | wednesday = models.BooleanField(blank=True, default=False) 139 | thursday = models.BooleanField(blank=True, default=False) 140 | friday = models.BooleanField(blank=True, default=False) 141 | saturday = models.BooleanField(blank=True, default=False) 142 | sunday = models.BooleanField(blank=True, default=False) 143 | 144 | objects = ScheduleManager() 145 | 146 | class Meta: 147 | abstract = True 148 | 149 | @property 150 | def humanized_weekdays(self): 151 | return ', '.join(weekday_name for weekday_slug, weekday_name in WeekDay.choices if getattr(self, weekday_slug)) 152 | 153 | def _description_builder(self): 154 | if self.repeat_type != ScheduleRepeatType.NONE: 155 | yield 'every' 156 | if self.repeat_every > 1: 157 | yield apnumber(self.repeat_every) 158 | yield pluralize(self.repeat_every, ScheduleRepeatType.pluralized_instances_dict[self.repeat_type]) 159 | if self.repeat_type == ScheduleRepeatType.WEEKLY and \ 160 | any(getattr(self, weekday_entry[0]) for weekday_entry in WeekDay.choices): 161 | yield 'on' 162 | yield self.humanized_weekdays 163 | elif self.repeat_type == ScheduleRepeatType.MONTHLY and self.monthly_is_based_on_weekday: 164 | week_position = (datetime.date(self.start_date.year, self.start_date.month, 1).weekday() + self.start_date.day) / 7 165 | is_last_weekday = (self.start_date + datetime.timedelta(weeks=1)).month != self.start_date.month 166 | if is_last_weekday: 167 | yield 'on the last %s' % WeekDay.choices[self.start_date.weekday()][1] 168 | else: 169 | yield 'on the %s %s' % (ordinal(week_position + 1), WeekDay.choices[self.start_date.weekday()][1]) 170 | elif self.repeat_type == ScheduleRepeatType.MONTHLY and not self.monthly_is_based_on_weekday: 171 | yield 'on the' 172 | yield ordinal(self.start_date.day) 173 | yield 'from' 174 | yield formats.date_format(self.start_date, 'SHORT_DATE_FORMAT') 175 | 176 | if self.end_date is not None: 177 | yield 'until' 178 | yield formats.date_format(self.end_date, 'SHORT_DATE_FORMAT') 179 | 180 | if self.end_after_occurrences > 0: 181 | if self.end_date: 182 | yield 'or' 183 | yield 'until' 184 | yield six.text_type(self.end_after_occurrences) 185 | yield pluralize(self.end_after_occurrences, 'occurence,occurences') 186 | yield 'took place' 187 | else: 188 | yield 'on' 189 | yield formats.date_format(self.start_date, 'SHORT_DATE_FORMAT') 190 | 191 | def __str__(self): 192 | return ' '.join(self._description_builder()) 193 | 194 | def iterate_occurrences(self, end_date=None): 195 | occurrences = 0 196 | current = self.start_date 197 | while (end_date is None or current <= end_date) and \ 198 | (not self.end_date or current <= self.end_date) and \ 199 | (self.end_after_occurrences == 0 or occurrences < self.end_after_occurrences): 200 | occurrences += 1 201 | yield current 202 | current = self.next_date(current) 203 | 204 | def __getitem__(self, item): 205 | if not isinstance(item, six.string_types): 206 | for i, occurrence in enumerate(self.iterate_occurrences()): 207 | if item == i: 208 | return occurrence 209 | else: 210 | return super(AbstractSchedule, self).__getitem__(item) 211 | 212 | def next_date(self, date): 213 | """ 214 | Based on this schedule, give the next valid date after ``date``. 215 | It is only guaranteed that the resulting next date is valid when the 216 | given ``date`` is already valid. 217 | """ 218 | if self.repeat_type == ScheduleRepeatType.DAILY: 219 | return date + datetime.timedelta(days=self.repeat_every) 220 | elif self.repeat_type == ScheduleRepeatType.WEEKLY: 221 | current = date 222 | for i in range(7): 223 | current = current + datetime.timedelta(days=1) 224 | if current.weekday() == 0: 225 | # When we arrive on Monday, skip some weeks if needed. 226 | current = current + datetime.timedelta(days=7 * (self.repeat_every - 1)) 227 | if getattr(self, WeekDay.choices[current.weekday()][0]): 228 | return current 229 | elif self.repeat_type == ScheduleRepeatType.MONTHLY: 230 | current = date 231 | for i in range(self.repeat_every): 232 | # FIXME: catch ValueError and ignore bad months. Works like Google Calendar 233 | current = add_month_based_on_weekday(current) \ 234 | if self.monthly_is_based_on_weekday \ 235 | else add_month(current) 236 | return current 237 | elif self.repeat_type == ScheduleRepeatType.YEARLY: 238 | try: 239 | return datetime.date(date.year + self.repeat_every, 240 | self.start_date.month, 241 | self.start_date.day) 242 | except ValueError: 243 | assert self.start_date.day == 29 and self.start_date.month == 2 244 | return datetime.date(date.year + self.repeat_every, 2, 28) 245 | 246 | raise ValueError('repeat_type "%s" is not supported' % self.repeat_type) 247 | 248 | 249 | class Schedule(AbstractSchedule): 250 | pass 251 | -------------------------------------------------------------------------------- /tinyschedule/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27, py35 3 | 4 | [testenv] 5 | setenv = 6 | PYTHONPATH = {toxinidir}:{toxinidir}/schedule 7 | commands = python runtests.py 8 | deps = 9 | -r{toxinidir}/requirements-test.txt 10 | --------------------------------------------------------------------------------