from django.db import models
from django.utils.translation import ugettext_lazy, ugettext as _
import django_countries
import jsonfield.fields
class PublicHolidayManager(models.Manager):
def on(self, date, country, province=None):
"""
If no province is provided, any holiday that falls on that day
for that country will return True
"""
# TODO: handle country names as well as codes.
qs = self.get_query_set().filter(date=date, country=country)
if province:
qs = qs.filter(models.Q(provinces=None) | models.Q(provinces__contains=province))
return qs.exists()
class PublicHoliday(models.Model):
"""
A PublicHoliday is an object that can be associated with a country, and
zero or more provinces. The semantic meaning of no listed provinces is
that the PublicHoliday is nationwide.
The provinces list should be CSV list of provinces from the django
localflavor module.
This is a seperate app, that relies on django-countries, with my
province patches applied, and django-jsonfield.
"""
#: Every PublicHoliday must have a name.
name = models.CharField(max_length=128)
#: PublicHolidays are single-day events, and do not automatically repeat.
date = models.DateField()
#: Each PublicHoliday can only apply to one country.
country = django_countries.CountryField()
#: Each PublicHoliday can apply to all, or a subset of provinces in
#: a country.
provinces = jsonfield.fields.JSONField(null=True, blank=True,
help_text=_(u'No selected provinces means that all provinces are affected.'))
objects = PublicHolidayManager()
class Meta:
app_label = 'public_holidays'
verbose_name = u'public holiday'
verbose_name_plural = u'public holidays'
ordering = ('date', 'country')
unique_together = (
('name', 'date', 'country'),
)
def __unicode__(self):
return "%s (%s) [%s]" % (self.name, self.date.year, self.country)
def public_holiday_on(date, country, province):
return PublicHoliday.objects.on(date, country, province)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:django-public-holidays-0.1.3.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
django-public-holidays-0.1.3.tar.gz (13个子文件)
django-public-holidays-0.1.3
PKG-INFO 474B
public_holidays
models.py 2KB
templates
public_holidays
year.html 422B
year.csv 0B
year.json 309B
__init__.py 38B
views.py 1008B
admin.py 625B
api.py 831B
urls.py 199B
fixtures
au_public_holidays.json 16KB
forms.py 793B
setup.py 803B
共 13 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- SMC真空气动元件样本.pdf
- TBI导轨样本.pdf
- 机械设计真空吸附滑台取料机sw18可编辑非常好的设计图纸100%好用.zip
- 机械设计直线电机双动子贴膜摆盘机step非常好的设计图纸100%好用.zip
- matlab学习的成长心得
- 机械设计载盘试偏光片贴合机step非常好的设计图纸100%好用.zip
- CPC导轨资料.pdf
- kuka机器人_KR30-3各轴分解图以及保养.pdf
- 安川ES165爆炸图.pdf
- 德国kammerer丝杠.pdf
- TBI样本.pdf
- 德国制造带给我们的启示.pdf
- 滚珠螺旋传动设计基础.pdf
- 滚珠丝杠基础知识.ppt
- 三协滚珠丝杆介绍.pdf
- 莱恩.PDF
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功