{ "info": { "author": "Johnny Lee", "author_email": "jleeothon@outlook.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3.4", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": "==========\ntimesickle\n==========\n\nMock dates for Django.\n\nVersion 0.2\n\n **Warning**: Until release of version 1, API is bound to change.\n\n---------\nRationale\n---------\n\nImagine you have to test a feature that calculates arrears based on days passed from the due date. You probably want to suggest the amount based on days until **today**. Then you want to do some manual testing and try it with different dates. That's where timesickle comes in. You probably *don't* want to do a nasty::\n\n import datetime\n # ...\n if __debug__:\n date = datetime.date.today()\n else:\n date = datetime.date(2014, 1, 1)\n # don't do this ^\n \nAlso, if the mock date is to be checked from different points in the code, you don't want to repeat the above code.\n\nTo transit easily from a \"real today\" and a \"mock today\" in different parts of your code, use ``timesickle``.\n\nRecommendations for use of this piece of software:\n\n Be careful with this technique, though. I would encourage you to write backend functions that receive dates instead of calculating \"now\" or \"today\" inside their bodies. The resolution of what \"today\" is should be left to the enclosing logic. For example, have model instance fields be told the date they should work with, but calculate this date in the views.\n\n..\n\n **Disclaimer.** Don't use this software for a full-scale project.\n\n------------\nInstallation\n------------\n\n*A more proper installation might be due.*\n\nTo install the latest version, run::\n\n pip install git+git://github.com/jleeothon/timesickle.git\n\nIn ``settings.py``, add ``'timesickle'`` under ``INSTALLED_APPS``::\n\n INSTALLED_APPS = (\n # django\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n # third party\n 'timesickle',\n # my apps\n 'awesomeapp',\n )\n\nIf you want to install a previous version, go figure. I don't know how to do that (but if you know, I don't mind you teaching me).\n\n-------\nTesting\n-------\n\nTo test the installation, run::\n\n python manage.py test \"timesickle\"\n \nIf the tests fail, you should::\n\n1. not use my software (|||\u275b\ufe35\u275b.)\n2. tell me, that is, file an issue on this repository o(^^o\n\n-----\nUsage\n-----\n\nIn ``settings.py``, set a ``MOCK_NOW`` object. This will define the variables in the ``timesickle`` module: \"now\", \"today\", \"tomorrow\", \"tomorrow_sametime\", \"yesterday\", and \"yesterday_sametime\"::\n\n # settings.py\n import datetime\n \n MOCK_NOW = datetime.datetime(2014, 05, 17, 18, 30, 0)\n\nThe above will set the mock date and time to IHOT, 6:30 PM.\n\n If you don't set the ``MOCK_NOW`` object, timesickle's dates will be based on the server's current time (``datetime.datetime.now()``).\n\nDepending on your logging settings, if you let the ``\"INFO\"`` logging level print to console, you will see the calculated values for the forementioned variables.\n\nYou can also set extra dates or date-times using a dictionary called \"SICKLE_DATES\" in your settings::\n\n # settings.py\n \n SICKLE_DATES = {\n 'pichincha_battle': datetime.date(1822, 5, 24),\n }\n\nThen, you can check this dates from ``timesickle.dates`` as either an attribute or a dictionary lookup (you might prefer ``\\w+`` names to look for them more comfortably)::\n\n import timesickle\n \n print(timesickle.dates.pichincha_battle)\n print(timesickle.dates['pichincha_battle']\n\n~~~~~~~~~~~~~~~~\nUse in templates\n~~~~~~~~~~~~~~~~\n\nYou can also use the tags included in the library. As far as they intend, they work pretty similar to the ``{% now \"SOMEFORMAT\" %}`` tag::\n\n {% load sickletime %}\n \n \n Right now it is: {% sicklenow \"SHORT_DATETIME_FORMAT\" %},\n then obviously today is {% sickletoday \"SHORT_DATE_FORMAT\" %}\n \n \n\n---------\nProposals\n---------\n\nThis mocking if dates is intended for small scale projects. It doesn't even consider time zones, so be careful. *Be specially careful if you need time-zone-aware functionality*.\n\nWe could also use a database to store the ``timesickle.dates`` objects, but this makes the whole project more complex and more difficult to maintain. This is only for small-scale development and test purposes.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jleeothon/timesickle", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "django-timesickle", "package_url": "https://pypi.org/project/django-timesickle/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-timesickle/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/jleeothon/timesickle" }, "release_url": "https://pypi.org/project/django-timesickle/0.2/", "requires_dist": null, "requires_python": null, "summary": "Template name resolution for Django class-based views", "version": "0.2" }, "last_serial": 1198115, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "32b1f19e770c6970d9caae2901087600", "sha256": "66dab4d56eedd50b1f164af2ac6ba7b389de19b028052ec051f826be1ec95cc5" }, "downloads": -1, "filename": "django-timesickle-0.2.tar.gz", "has_sig": false, "md5_digest": "32b1f19e770c6970d9caae2901087600", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5465, "upload_time": "2014-08-21T20:19:14", "url": "https://files.pythonhosted.org/packages/8a/17/8c8e56318343d5f387f1262767b0fd99d9a3d97421431f28ca575256822c/django-timesickle-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "32b1f19e770c6970d9caae2901087600", "sha256": "66dab4d56eedd50b1f164af2ac6ba7b389de19b028052ec051f826be1ec95cc5" }, "downloads": -1, "filename": "django-timesickle-0.2.tar.gz", "has_sig": false, "md5_digest": "32b1f19e770c6970d9caae2901087600", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5465, "upload_time": "2014-08-21T20:19:14", "url": "https://files.pythonhosted.org/packages/8a/17/8c8e56318343d5f387f1262767b0fd99d9a3d97421431f28ca575256822c/django-timesickle-0.2.tar.gz" } ] }