本文整理汇总了Python中snisi_core.models.Periods.MonthPeriod.find_create_by_date方法的典型用法代码示例。如果您正苦于以下问题:Python MonthPeriod.find_create_by_date方法的具体用法?Python MonthPeriod.find_create_by_date怎么用?Python MonthPeriod.find_create_by_date使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snisi_core.models.Periods.MonthPeriod
的用法示例。
在下文中一共展示了MonthPeriod.find_create_by_date方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: boundaries
# 需要导入模块: from snisi_core.models.Periods import MonthPeriod [as 别名]
# 或者: from snisi_core.models.Periods.MonthPeriod import find_create_by_date [as 别名]
def boundaries(cls, date_obj):
date_obj = normalize_date(date_obj, as_aware=True)
start = date_obj.replace(day=29, hour=0, minute=0,
second=0, microsecond=0)
end = MonthPeriod.find_create_by_date(date_obj,
dont_create=True).following() \
.start_on - ONE_MICROSECOND_DELTA
return (start, end)
示例2: following_week
# 需要导入模块: from snisi_core.models.Periods import MonthPeriod [as 别名]
# 或者: from snisi_core.models.Periods.MonthPeriod import find_create_by_date [as 别名]
def following_week(cls, reference):
idx = cls.week_classes.index(reference.__class__)
if idx == len(cls.week_classes) - 1:
ncls = cls.week_classes[0]
nmonth = MonthPeriod.find_create_by_date(reference.middle())
at = nmonth.next().middle()
else:
ncls = cls.week_classes[idx + 1]
at = reference.middle()
return ncls.find_create_by_date(at)
示例3: previous_week
# 需要导入模块: from snisi_core.models.Periods import MonthPeriod [as 别名]
# 或者: from snisi_core.models.Periods.MonthPeriod import find_create_by_date [as 别名]
def previous_week(cls, reference):
idx = cls.week_classes.index(reference.__class__)
if idx == 0:
ncls = cls.week_classes[-1]
nmonth = MonthPeriod.find_create_by_date(reference.middle())
at = nmonth.previous().middle()
else:
ncls = cls.week_classes[idx - 1]
at = reference.middle()
return ncls.find_create_by_date(at)
示例4: _check
# 需要导入模块: from snisi_core.models.Periods import MonthPeriod [as 别名]
# 或者: from snisi_core.models.Periods.MonthPeriod import find_create_by_date [as 别名]
def _check(self, **options):
# period
period = MonthPeriod.find_create_by_date(self.get('submit_time'))
self.set('clean_period', period)
# entity (district)
entity = Entity.get_or_none(self.get('district'),
type_slug='health_district')
if entity is None:
self.add_error("Aucun District ne correspond "
"au code {}".format(self.get('district')),
field='district', blocking=True)
self.set('clean_entity', entity)
# check auth for user at district
user_district = self.get('submitter').location.get_health_district()
if (user_district is None
or not user_district == entity
or self.get('submitter').role.slug
not in ('tt_tso', 'tt_opt', 'tt_amo',
'tt_surgeon', 'charge_sis')):
self.add_error("Vous n'êtes pas autorisé à créer un rapport de "
"mission pour ce district: {}".format(entity),
blocking=True, field='submitter')
# expected reporting defines if report is expeted or not
expected_reporting = ExpectedReporting.get_or_none(
report_class__slug='cat_mission',
period=period,
within_period=True,
entity=entity,
within_entity=False)
self.set('expected_reporting', expected_reporting)
# should have already been checked in checker.
if expected_reporting is None:
self.add_error("Aucune mission cataracte attendue à {} pour "
"la période de {}".format(entity, period),
blocking=True)
if expected_reporting.completion_status \
== ExpectedReporting.COMPLETION_COMPLETE:
self.add_error("Aucune mission cataracte attendue à {} pour "
"la période de {}".format(entity, period),
blocking=True)
# no creation if exist open
open_missions = CATMissionR.objects.filter(
entity=entity,
created_by=self.get('submitter'),
).exclude(completion_status=CATMissionR.COMPLETE)
if open_missions.count():
self.add_error("Vous avez déjà une mission en cours à {}. "
"Cloturez la d'abord.".format(entity, period),
blocking=True)
# started_on must be <= today
today = datetime.date.today()
started_on = parse_date_string(self.get('started_on'), as_date=True)
if started_on is None:
self.add_error("La date de démarrage est incorrecte: "
"{}.".format(self.get('started_on')),
blocking=True, field='started_on')
if started_on > today:
self.add_error("La date de démarrage est dans "
"le futur: {}.".format(started_on),
blocking=True, field='started_on')
if started_on < today - datetime.timedelta(days=21):
self.add_error("La date de démarrage est trop "
"ancienne: {}.".format(started_on),
blocking=True, field='started_on')
self.set('clean_started_on', started_on)
# operator type
operator_type = {
'amo': cat_models.AMO,
'tso': cat_models.TSO,
'opt': cat_models.OPT,
'surgeon': cat_models.SURGEON,
}.get(self.get('operator_type').lower())
if operator_type not in cat_models.OPERATOR_TYPES.keys():
self.add_error("Profil agent innatendu: "
"{}.".format(self.get('operator_type')),
blocking=True, field='operator')
self.set('clean_operator_type', operator_type)
# strategy
strategy = {
'fixed': cat_models.FIXED,
'mobile': cat_models.MOBILE,
'advanced': cat_models.ADVANCED
}.get(self.get('strategy').lower())
if strategy not in cat_models.STRATEGIES.keys():
self.add_error("Strategie innatendue: "
"{}.".format(self.get('strategy')),
blocking=True, field='strategy')
#.........这里部分代码省略.........
示例5: cataract_mission_browser
# 需要导入模块: from snisi_core.models.Periods import MonthPeriod [as 别名]
# 或者: from snisi_core.models.Periods.MonthPeriod import find_create_by_date [as 别名]
def cataract_mission_browser(request,
entity_slug=None,
period_str=None,
**kwargs):
context = {}
root = request.user.location
cluster = Cluster.get_or_none('cataract')
entity = Entity.get_or_none(entity_slug)
if entity is None:
entity = root
if entity is None:
raise Http404("Aucune entité pour le code {}".format(entity_slug))
# make sure requested entity is in cluster
ensure_entity_in_cluster(cluster, entity)
# check permissions on this entity and raise 403
provider_allowed_or_denied(request.user, 'access_cataract', entity)
# mission browser is reserved to district-level and above
ensure_entity_at_least(entity, 'health_district')
def period_from_strid(period_str, reportcls=None):
period = None
if period_str:
try:
period = Period.from_url_str(period_str).casted()
except:
pass
return period
period = period_from_strid(period_str)
if period is None:
period = MonthPeriod.current()
try:
first_period = MonthPeriod.find_create_by_date(
CATMissionR.objects.all()
.order_by('period__start_on')[0].period.middle())
except IndexError:
first_period = MonthPeriod.current()
all_periods = MonthPeriod.all_from(first_period)
context.update({
'all_periods': [(p.strid(), p) for p in reversed(all_periods)],
'period': period,
'base_url': get_base_url_for_period(
view_name='cataract_missions', entity=entity,
period_str=period_str or period.strid())
})
context.update(entity_browser_context(
root=root, selected_entity=entity,
full_lineage=['country', 'health_region', 'health_district'],
cluster=cluster))
# retrieve list of missions for that period
missions = CATMissionR.objects.filter(
period=period,
entity__slug__in=[e.slug for e in entity.get_health_districts()])
context.update({'missions': missions})
return render(request,
kwargs.get('template_name', 'cataract/missions_list.html'),
context)
示例6: cataract_dashboard
# 需要导入模块: from snisi_core.models.Periods import MonthPeriod [as 别名]
# 或者: from snisi_core.models.Periods.MonthPeriod import find_create_by_date [as 别名]
def cataract_dashboard(request,
entity_slug=None,
perioda_str=None,
periodb_str=None,
**kwargs):
context = {}
root = request.user.location
cluster = Cluster.get_or_none('cataract')
entity = Entity.get_or_none(entity_slug)
if entity is None:
entity = root
if entity is None:
raise Http404("Aucune entité pour le code {}".format(entity_slug))
# make sure requested entity is in cluster
ensure_entity_in_cluster(cluster, entity)
# check permissions on this entity and raise 403
provider_allowed_or_denied(request.user, 'access_cataract', entity)
# mission browser is reserved to district-level and above
ensure_entity_at_least(entity, 'health_district')
def period_from_strid(period_str, reportcls=None):
period = None
if period_str:
try:
period = Period.from_url_str(period_str).casted()
except:
pass
return period
perioda = period_from_strid(perioda_str)
periodb = period_from_strid(periodb_str)
if periodb is None:
periodb = MonthPeriod.current()
if perioda is None:
perioda = periodb
if perioda is None or periodb is None:
raise Http404("Période incorrecte.")
if perioda > periodb:
t = perioda
perioda = periodb
periodb = t
del(t)
try:
first_period = MonthPeriod.find_create_by_date(
CATMissionR.objects.all().order_by(
'period__start_on')[0].period.middle())
except IndexError:
first_period = MonthPeriod.current()
all_periods = MonthPeriod.all_from(first_period)
periods = MonthPeriod.all_from(perioda, periodb)
context.update({
'all_periods': [(p.strid(), p) for p in reversed(all_periods)],
'periods': periods,
'perioda': perioda,
'periodb': periodb,
'base_url': get_base_url_for_periods(
view_name='cataract_dashboard',
entity=entity,
perioda_str=perioda_str or perioda.strid(),
periodb_str=periodb_str or periodb.strid())
})
context.update(entity_browser_context(
root=root, selected_entity=entity,
full_lineage=['country', 'health_region', 'health_district'],
cluster=cluster))
# retrieve Indicator Table
from snisi_cataract.indicators import (MissionDataSummary,
CumulativeSurgeryData)
missions_followup = MissionDataSummary(entity=entity,
periods=periods)
cumulative_surgeries = CumulativeSurgeryData(entity=entity,
periods=periods)
context.update({
'missions_followup': missions_followup,
'cumulative_surgeries': cumulative_surgeries,
})
return render(request,
kwargs.get('template_name', 'cataract/dashboard.html'),
context)