def __str__(self):
replacements = {
'name': self.staffMember.fullName,
'subbed': _(' subbed: '),
'month': month_name[self.event.month or 0],
'year': self.event.year,
}
if not self.replacedStaffMember:
return '%(name)s %(subbed)s: %(month)s %(year)s' % replacements
replacements.update({'subbed': _(' subbed for '), 'staffMember': self.replacedStaffMember.staffMember.fullName})
return '%(name)s %(subbed)s %(staffMember)s: %(month)s %(year)s' % replacements
python类month_name()的实例源码
danceschool_tags.py 文件源码
项目:django-danceschool
作者: django-danceschool
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def readable_month(month):
try:
return month_name[month]
except (TypeError,IndexError):
return None
def series_month(self,obj):
return '%s %s' % (month_name[obj.month or 0],obj.year or '')
def render_to_csv(self, context):
statement = context['statement']
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="financialStatementByMonth.csv"'
writer = csv.writer(response, csv.excel)
response.write(u'\ufeff'.encode('utf8')) # BOM (optional...Excel needs it to open UTF-8 file properly)
header_list = [
_('Month Name'),
_('Revenues: Net'),
_('Expenses: Instruction'),
_('Expenses: Venue'),
_('Expenses: Other'),
_('Expenses: Total'),
_('Registrations'),
_('Net Profit'),
]
writer.writerow(header_list)
for x in statement['statementByMonth']:
this_row_data = [
x['month_name'],
x['revenues'],
x['expenses']['instruction'],
x['expenses']['venue'],
x['expenses']['other'],
x['expenses']['total'],
x['registrations'],
x['net_profit'],
]
writer.writerow(this_row_data)
return response
def get_invoice(user_name, user_id, month):
html = """
<p>Anzee Corporation</p><br>
<b><p>Account Name: """ + user_name + """</p>
<p>Invoice for month of: """ + str(calendar.month_name[month]) + """</p></b>
<br><br>
<p><b>Payments and Usage:</b></p>
<table align="center" width="50%">
<thead>
<tr>
<th align="left" width="50%">Charge Type</th>
<th align="right" width="50%">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>Payments Done</td>
<td align="right">$""" + str(get_payments(user_id, month)) + """</td>
</tr>
<tr>
<td>Total Usage</td>
<td align="right">$""" + str(get_usage(user_id, month)) + """</td>
</tr>
</tbody>
</table>
<br><br>
"""
return html
def create_calendar(year,month):
markup = types.InlineKeyboardMarkup()
#First row - Month and Year
row=[]
row.append(types.InlineKeyboardButton(calendar.month_name[month]+" "+str(year),callback_data="ignore"))
markup.row(*row)
#Second row - Week Days
week_days=["M","T","W","R","F","S","U"]
row=[]
for day in week_days:
row.append(types.InlineKeyboardButton(day,callback_data="ignore"))
markup.row(*row)
my_calendar = calendar.monthcalendar(year, month)
for week in my_calendar:
row=[]
for day in week:
if(day==0):
row.append(types.InlineKeyboardButton(" ",callback_data="ignore"))
else:
row.append(types.InlineKeyboardButton(str(day),callback_data="calendar-day-"+str(day)))
markup.row(*row)
#Last row - Buttons
row=[]
row.append(types.InlineKeyboardButton("<",callback_data="previous-month"))
row.append(types.InlineKeyboardButton(" ",callback_data="ignore"))
row.append(types.InlineKeyboardButton(">",callback_data="next-month"))
markup.row(*row)
return markup
def __calc_month(self):
# Set self.f_month and self.a_month using the calendar module.
a_month = [calendar.month_abbr[i].lower() for i in range(13)]
f_month = [calendar.month_name[i].lower() for i in range(13)]
self.a_month = a_month
self.f_month = f_month
def get_date_form(answer=None, error_messages=None):
"""
Returns a date form metaclass with appropriate validators. Used in both date and
date range form creation.
:param error_messages: The messages during validation
:param answer: The answer on which to base this form
:return: The generated DateForm metaclass
"""
class DateForm(Form):
day = StringField()
year = StringField()
validate_with = [OptionalForm()]
if not error_messages:
date_messages = {}
else:
date_messages = error_messages.copy()
if answer['mandatory'] is True:
if 'validation' in answer and 'messages' in answer['validation'] \
and 'MANDATORY_DATE' in answer['validation']['messages']:
date_messages['MANDATORY_DATE'] = answer['validation']['messages']['MANDATORY_DATE']
validate_with = [DateRequired(message=date_messages['MANDATORY_DATE'])]
if 'validation' in answer and 'messages' in answer['validation'] \
and 'INVALID_DATE' in answer['validation']['messages']:
date_messages['INVALID_DATE'] = answer['validation']['messages']['INVALID_DATE']
validate_with += [DateCheck(date_messages['INVALID_DATE'])]
# Set up all the calendar month choices for select
month_choices = [('', 'Select month')] + [(str(x), calendar.month_name[x]) for x in range(1, 13)]
DateForm.month = SelectField(choices=month_choices, default='', validators=validate_with)
return DateForm
def get_month_year_form(answer, error_messages):
"""
Returns a month year form metaclass with appropriate validators. Used in both date and
date range form creation.
:param answer: The answer on which to base this form
:param error_messages: The messages to use upon this form during validation
:return: The generated MonthYearDateForm metaclass
"""
class MonthYearDateForm(Form):
year = StringField()
validate_with = [OptionalForm()]
if answer['mandatory'] is True:
error_message = error_messages['MANDATORY_DATE']
if 'validation' in answer and 'messages' in answer['validation'] \
and 'MANDATORY_DATE' in answer['validation']['messages']:
error_message = answer['validation']['messages']['MANDATORY_DATE']
validate_with = [DateRequired(message=error_message)]
if 'validation' in answer and 'messages' in answer['validation'] \
and 'INVALID_DATE' in answer['validation']['messages']:
error_message = answer['validation']['messages']['INVALID_DATE']
validate_with += [MonthYearCheck(error_message)]
else:
validate_with += [MonthYearCheck()]
# Set up all the calendar month choices for select
month_choices = [('', 'Select month')] + [(str(x), calendar.month_name[x]) for x in range(1, 13)]
MonthYearDateForm.month = SelectField(choices=month_choices, default='', validators=validate_with)
return MonthYearDateForm
def _monthToInt( month ):
months = {m.lower(): idx for idx, m in enumerate(calendar.month_name)}
try:
return months[month.lower()]
except:
return -1
def __calc_month(self):
# Set self.f_month and self.a_month using the calendar module.
a_month = [calendar.month_abbr[i].lower() for i in range(13)]
f_month = [calendar.month_name[i].lower() for i in range(13)]
self.a_month = a_month
self.f_month = f_month
def dateFormatter(self, date):
month = calendar.month_name[date.month]
weekday = calendar.day_name[date.weekday()]
day = date.day
year = date.year
results = str(weekday) + ", " + str(month) + " " + str(day) + ", " + str(year)
return results
def __calc_month(self):
# Set self.f_month and self.a_month using the calendar module.
a_month = [calendar.month_abbr[i].lower() for i in range(13)]
f_month = [calendar.month_name[i].lower() for i in range(13)]
self.a_month = a_month
self.f_month = f_month
def month_name(no_month):
if isinstance(no_month, datetime):
no_month = no_month.month
return calendar.month_name[no_month]
def tandem_choose_date(request, year=datetime.now().year, month=datetime.now().month, template_name='signup/tandem_choose_date.html'):
month, year = int(month), int(year)
c = calendar.Calendar()
c.setfirstweekday(calendar.SUNDAY)
cal = c.monthdatescalendar(year, month)
_events = TandemDay.objects.filter(date__range=(cal[0][0], cal[len(cal) - 1][6]))
events = {}
for e in _events:
if e.date.month not in events:
events[e.date.month] = {}
if e.date.day not in events[e.date.month]:
events[e.date.month][e.date.day] = []
events[e.date.month][e.date.day].append(e)
print(events)
data = {}
data['title'] = "Tandem Sign Up"
data['month_name'] = calendar.month_name[month]
data['year'] = year
data['month'] = month
data['previous'] = {'month': (month - 1 + 11) % 12 + 1, 'year': year - (1 if month == 1 else 0)}
data['next'] = {'month': (month - 1 + 1) % 12 + 1, 'year': year + (1 if month == 12 else 0)}
data['calendar'] = cal
data['events'] = events
data['nofollow'] = (True if year < 2017 or year > datetime.now().year + 2 else False)
return render(request, template_name, data)
def __calc_month(self):
# Set self.f_month and self.a_month using the calendar module.
a_month = [calendar.month_abbr[i].lower() for i in range(13)]
f_month = [calendar.month_name[i].lower() for i in range(13)]
self.a_month = a_month
self.f_month = f_month
def __calc_month(self):
# Set self.f_month and self.a_month using the calendar module.
a_month = [calendar.month_abbr[i].lower() for i in range(13)]
f_month = [calendar.month_name[i].lower() for i in range(13)]
self.a_month = a_month
self.f_month = f_month
def __calc_month(self):
# Set self.f_month and self.a_month using the calendar module.
a_month = [calendar.month_abbr[i].lower() for i in range(13)]
f_month = [calendar.month_name[i].lower() for i in range(13)]
self.a_month = a_month
self.f_month = f_month
def standardize_act_target(tgt_url):
''' Produce label for identified Act target based on URL. This is cleaner
than pulling the text and accounting for typos and inconsistencies.'''
surl = tgt_url.split("/")
date = surl[3].split("-")
date = "{} {}, {}".format(calendar.month_name[int(date[1])], date[2], date[0])
try:
tgt_title = "Act of {}, ch. {} {}".format(date, surl[4].strip("ch"), surl[5].strip("s"))
except:
try:
if "ch" in surl[4]:
tgt_title = "Act of {}, ch. {}".format(date, surl[4].strip("ch"))
elif "s" in surl[4]:
tgt_title = "Act of {}, {}".format(date, surl[4].strip("s"))
except:
tgt_title = "Act of {}".format(date)
try: surl[4] = surl[4].lstrip("ch")
except: pass
try: surl[5] = surl[5].lstrip("s")
except: pass
tgt_url = "/".join(x for x in surl)
try:
tgt_url_broad = "/".join(tgt_url.split("/")[0:6])
except:
tgt_url_broad = "/".join(tgt_url.split("/")[0:5])
return tgt_title, tgt_url, tgt_url_broad
def standardize_act_target(tgt_url):
''' Produce label for identified Act target based on URL. This is cleaner
than pulling the text and accounting for typos and inconsistencies.'''
surl = tgt_url.split("/")
date = surl[3].split("-")
date = "{} {}, {}".format(calendar.month_name[int(date[1])], date[2], date[0])
try:
tgt_title = "Act of {}, ch. {} {}".format(date, surl[4].strip("ch"), surl[5].strip("s"))
except:
try:
if "ch" in surl[4]:
tgt_title = "Act of {}, ch. {}".format(date, surl[4].strip("ch"))
elif "s" in surl[4]:
tgt_title = "Act of {}, {}".format(date, surl[4].strip("s"))
except:
tgt_title = "Act of {}".format(date)
try: surl[4] = surl[4].lstrip("ch")
except: pass
try: surl[5] = surl[5].lstrip("s")
except: pass
tgt_url = "/".join(x for x in surl)
try:
tgt_url_broad = "/".join(tgt_url.split("/")[0:6])
except:
tgt_url_broad = "/".join(tgt_url.split("/")[0:5])
return tgt_title, tgt_url, tgt_url_broad