本文整理汇总了Python中remo.base.utils.number2month函数的典型用法代码示例。如果您正苦于以下问题:Python number2month函数的具体用法?Python number2month怎么用?Python number2month使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了number2month函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_reports_for_year
def get_reports_for_year(user, start_year, end_year=None,
allow_empty=False, private=True):
"""Return a list of reports for year."""
reports_list = {}
tmp_date = datetime.today()
up = user.userprofile
today = datetime(year=tmp_date.year, month=tmp_date.month, day=1)
date_joined = up.date_joined_program
tmp_date = go_fwd_n_months(date_joined)
month_first_report = datetime(year=tmp_date.year,
day=1, month=tmp_date.month)
if not end_year:
end_year = start_year
for year in range(max(start_year, date_joined.year), end_year+1):
reports = user.reports.filter(month__year=year)
if (reports.count() == 0 and private == True):
reports_list[year] = None
continue
else:
reports_list[year] = []
for month in range(1, 13):
month_details = {'name': number2month(month, full_name=False),
'fullname': number2month(month, full_name=True)}
if reports.filter(month__month=month).exists():
report = reports.get(month__month=month)
month_details['report'] = report
month_details['class'] = 'exists'
month_details['link'] = get_report_view_url(report)
else:
month_details['report'] = None
date = datetime(year=year, month=month, day=1)
if (private or month_first_report > date or date >= today):
month_details['class'] = 'unavailable'
month_details['link'] = '#'
else:
month_details['class'] = 'editable'
link = reverse('reports_edit_report',
kwargs={'display_name': up.display_name,
'year': year,
'month': month_details['fullname']})
month_details['link'] = link
reports_list[year].append(month_details)
return reports_list
示例2: get_reports_for_year
def get_reports_for_year(user, start_year, end_year=None, allow_empty=False,
permission=REPORTS_PERMISSION_LEVEL['anonymous']):
"""Return a list of reports for year."""
reports_list = {}
tmp_date = datetime.today()
up = user.userprofile
today = datetime(year=tmp_date.year, month=tmp_date.month, day=1)
date_joined = up.date_joined_program
tmp_date = go_fwd_n_months(date_joined)
month_first_report = datetime(year=tmp_date.year,
day=1, month=tmp_date.month)
if not end_year:
end_year = start_year
for year in range(max(start_year, date_joined.year), end_year+1):
reports = user.reports.filter(month__year=year)
reports_list[year] = []
for month in range(1, 13):
month = datetime(year=year, month=month, day=1)
month_details = {'name': number2month(month.month,
full_name=False),
'fullname': number2month(month.month,
full_name=True)}
if (reports.filter(month=month).exists() and
((permission > 1 and month == today) or (month < today))):
report = reports.get(month=month)
month_details['report'] = report
month_details['class'] = 'exists'
month_details['link'] = get_report_view_url(report)
else:
month_details['report'] = None
if (permission < 3 or month_first_report > month or
month > today):
month_details['class'] = 'unavailable'
month_details['link'] = '#'
else:
month_details['class'] = 'editable'
link = reverse('reports_edit_report',
kwargs={'display_name': up.display_name,
'year': year,
'month': month_details['fullname']})
month_details['link'] = link
reports_list[year].append(month_details)
return reports_list
示例3: handle
def handle(self, *args, **options):
"""Prepares a list of reps to be notified and the required
template variables.
"""
date = go_back_n_months(datetime.today(), 1)
rep_group = Group.objects.get(name='Rep')
reps = (rep_group.user_set
.exclude(userprofile__registration_complete=False)
.exclude(reports__month__year=date.year,
reports__month__month=date.month))
reps_without_report = reps.values_list('id', flat=True)
month = number2month(date.month)
subject = self.SUBJECT % month
data = {'year': date.year, 'month': month}
if options['dry_run']:
email_reps = reps.values_list('email', flat=True)
for recipient in email_reps:
msg = 'Second notification sent to %s' % recipient
print(msg)
else:
send_remo_mail(reps_without_report, subject,
self.EMAIL_TEMPLATE, data)
示例4: _get_url_args
def _get_url_args(self):
args = [self.user.userprofile.display_name,
self.report_date.year,
utils.number2month(self.report_date.month),
self.report_date.day,
self.id]
return args
示例5: get_comment_delete_url
def get_comment_delete_url(obj):
"""Return the delete url of a comment."""
up = obj.report.user.userprofile
month_name = number2month(obj.report.month.month)
return reverse('reports_delete_report_comment',
kwargs={'display_name': up.display_name,
'year': obj.report.month.year,
'month': month_name,
'comment_id': obj.id})
示例6: handle
def handle(self, *args, **options):
"""Prepares a list of reps to be notified and the required
template variables.
"""
rep_group = Group.objects.get(name="Rep")
reps = rep_group.user_set.exclude(userprofile__registration_complete=False)
date = go_back_n_months(datetime.datetime.today(), 1)
data = {"year": date.year, "month": number2month(date.month)}
send_remo_mail(reps, self.SUBJECT, self.EMAIL_TEMPLATE, data)
示例7: test_invalid_date
def test_invalid_date(self, mocked_now_date, mocked_waffle_switch):
mocked_waffle_switch.return_value = False
UserFactory.create(userprofile__is_rotm_nominee=True)
UserFactory.create(userprofile__is_rotm_nominee=True)
UserFactory.create(username='remobot')
mocked_now_date.return_value = datetime(now().year, now().month, 5)
poll_name = ('Rep of the month for {0}'.format(
number2month(now().month)))
create_rotm_poll()
poll = Poll.objects.filter(name=poll_name)
ok_(not poll.exists())
示例8: get_comment_delete_url
def get_comment_delete_url(obj):
"""Return the delete url of a comment."""
up = obj.user.userprofile
month_name = number2month(obj.report.month.month)
return reverse(
"reports_delete_report_comment",
kwargs={
"display_name": up.display_name,
"year": obj.report.month.year,
"month": month_name,
"comment_id": obj.id,
},
)
示例9: handle
def handle(self, *args, **options):
"""Prepares a list of reps to be notified and the required
template variables.
"""
rep_group = Group.objects.get(name='Rep')
reps = (rep_group.user_set
.exclude(userprofile__registration_complete=False)
.values_list('id', flat=True))
date = go_back_n_months(datetime.datetime.today(), 1)
month = number2month(date.month)
subject = self.SUBJECT % month
data = {'year': date.year, 'month': month}
send_remo_mail(reps, subject, self.EMAIL_TEMPLATE, data)
示例10: test_nominate_notification_base
def test_nominate_notification_base(self, mocked_date, mail_mock):
UserFactory.create(groups=['Mentor'])
subject = 'Nominate Rep of the month'
mentor_alias = settings.REPS_MENTORS_LIST
mocked_date.return_value = datetime(now().year, now().month, 1)
send_rotm_nomination_reminder()
ok_(mail_mock.called)
eq_(mail_mock.call_count, 1)
expected_call_list = [call(recipients_list=[mentor_alias],
subject=subject,
data={'month': number2month(now().month)},
email_template=ANY)]
eq_(mail_mock.call_args_list, expected_call_list)
示例11: send_rotm_nomination_reminder
def send_rotm_nomination_reminder():
""" Send an email reminder to all mentors.
The first day of each month, the mentor group receives an email reminder
in order to nominate Reps for the Rep of the month voting.
"""
now_date = now().date()
if now_date.day == ROTM_REMINDER_DAY:
data = {'month': number2month(now_date.month)}
subject = 'Nominate Rep of the month'
template = 'emails/mentors_rotm_reminder.txt'
send_remo_mail(subject=subject,
email_template=template,
recipients_list=[settings.REPS_MENTORS_LIST],
data=data)
示例12: handle
def handle(self, *args, **options):
"""Prepares a list of reps to be notified and the required
template variables.
"""
rep_group = Group.objects.get(name='Rep')
reps = rep_group.user_set.exclude(
userprofile__registration_complete=False)
date = go_back_n_months(datetime.datetime.today(), 1)
reps_without_report = reps.exclude(reports__month__year=date.year,
reports__month__month=date.month)
data = {'year': date.year, 'month': number2month(date.month)}
send_remo_mail(reps_without_report, self.SUBJECT,
self.EMAIL_TEMPLATE, data)
示例13: current_report
def current_report(request, edit=False):
display_name = request.user.userprofile.display_name
previous_month = utils.go_back_n_months(datetime.date.today(),
first_day=True)
month_name = utils.number2month(previous_month.month)
report = utils.get_object_or_none(
Report, user__userprofile__display_name=display_name,
month=previous_month)
view = 'reports_view_report'
if edit or not report:
view = 'reports_edit_report'
redirect_url = reverse(view, kwargs={'display_name': display_name,
'year': previous_month.year,
'month': month_name})
return redirect(redirect_url)
示例14: handle
def handle(self, *args, **options):
"""Prepares a list of reps to be notified and the required
template variables.
"""
rep_group = Group.objects.get(name="Rep")
reps = rep_group.user_set.exclude(userprofile__registration_complete=False)
date = go_back_n_months(datetime.datetime.today(), 2)
reps_without_report = reps.exclude(reports__month__year=date.year, reports__month__month=date.month)
mentors = [rep.userprofile.mentor.id for rep in reps_without_report]
month = number2month(date.month)
subject = self.SUBJECT % month
data = {"year": date.year, "month": month, "reps_without_report": reps_without_report}
send_remo_mail(mentors, subject, self.EMAIL_TEMPLATE, data)
示例15: test_base
def test_base(self, mocked_now_date):
nominee_1 = UserFactory.create(userprofile__is_rotm_nominee=True)
nominee_2 = UserFactory.create(userprofile__is_rotm_nominee=True)
UserFactory.create(username='remobot')
mocked_now_date.return_value = datetime(now().year, now().month, 11)
poll_name = ('Rep of the month for {0}'.format(
number2month(now().month)))
create_rotm_poll()
poll = Poll.objects.filter(name=poll_name)
range_poll = RangePoll.objects.get(poll=poll)
range_poll_choices = RangePollChoice.objects.filter(
range_poll=range_poll)
ok_(poll.exists())
eq_(poll.count(), 1)
eq_(set([choice.nominee for choice in range_poll_choices]),
set([nominee_1, nominee_2]))