Exemple #1
0
def mes(ano=None, mes=None):
    if ano is None:
        ano, mes = localtime()[:2]
    elif mes is None:
        mes = localtime()[1]
    calendario = LocaleHTMLCalendar(locale='pt_BR.utf8')
    html_mes = calendario.formatmonth(ano, mes)
    return template(HTML,
                    ano=ano,
                    mes=mes,
                    calendario=html_mes,
                    prox_mes=prox_mes(ano, mes))
def contractor_calendar(queryset):
    for s in queryset:
        eventdict = defaultdict(str)
        conevents = s.contractorschedule_set.all().exclude(start_date__gt=last_day_of_month(datetime.datetime.today())) \
                                                  .exclude(start_date__lt=first_day_of_month(datetime.datetime.today()))
        if conevents.exists():
            counter = conevents.count()  #2
            n = 1
            for i in conevents:
                y, m = i.start_date.year, i.start_date.month
                event = ""
                #event = "<ul class=\"calendar-event\"><li style=\"background-color:#"+ i.background_color +"\">" +\
                #         i.start_date.strftime("%I:%M")+" "+ i.title +" "+ i.end_date.strftime("%I:%M") +"</li></ul>"
                #loop through the days of the month
                if i.start_date.day != i.end_date.day or i.start_date.month != i.end_date.month:
                    if i.start_date.month != i.end_date.month:
                        chunkofdays = range(i.start_date.day,
                                            monthrange(y, m)[1] + 1)
                    else:
                        chunkofdays = range(i.start_date.day,
                                            i.end_date.day + 1)
                    for days in chunkofdays:  #chunkofdays is an array of the day numbers [1-8]
                        if days == chunkofdays[-1]:
                            eventend = ""
                            #eventend = "<ul class=\"calendar-event\"><li style=\"background-color:#"+ i.background_color +"\">"  +\
                            #             i.start_date.strftime("%I:%M")+" "+ i.title +" "+ i.end_date.strftime("%I:%M") +"</li></ul>"
                            eventdict[days] += eventend
                        else:
                            eventstart = ""
                            #eventstart = "<ul class=\"calendar-event\"><li style=\"background-color:#"+ i.background_color +"\">" +\
                            #             i.start_date.strftime("%I:%M")+" "+ i.title + "</li></ul>"
                            eventdict[days] += eventstart
                for j in range(1, monthrange(y, m)[1] + 1):  #1-31

                    if i.start_date.day == j and j not in eventdict and i.start_date.day == i.end_date.day:
                        eventdict[j] = event
                    #add to a day with an event
                    if i.start_date.day == j and eventdict[
                            j] != "" and eventdict[j] is not None and eventdict[
                                j] != event and i.start_date.day == i.end_date.day:
                        eventdict[j] += event

                    #change day from none to event
                    if i.start_date.day == j and eventdict[
                            j] is None and i.start_date.day == i.end_date.day:
                        eventdict[j] = event

                    if j == monthrange(y, m)[1] and n == counter:
                        htmlcalendar = GenericCalendar(y, m).formatmonth(
                            y, m, eventdict)
                    elif j == monthrange(y, m)[1] and n != counter:
                        n += 1
            return htmlcalendar

        else:
            todaysdate = date.today()
            y, m = todaysdate.year, todaysdate.month
            htmlcalendar = LocaleHTMLCalendar().formatmonth(y, m)
            return htmlcalendar
Exemple #3
0
 def __init__(self, firstweekday=0, locale=None, eventsList = []):
     LocaleHTMLCalendar.__init__(self, firstweekday, locale)
     self.eventsList = eventsList
Exemple #4
0
def mes():
    ano, mes = localtime()[:2]
    calendario = LocaleHTMLCalendar(locale='pt_BR.utf8')
    html_mes = calendario.formatmonth(ano, mes)
    return template(HTML, ano=ano, mes=mes, calendario=html_mes)
 def render_GET(self,request):
     d = LocaleHTMLCalendar()
     return "%s" % d.formatyearpage(self.year,2,encoding='utf-8')
 def __init__(self):
     LocaleHTMLCalendar.__init__(self,locale='zh_CN.UTF-8')
Exemple #7
0
 def render_GET(self, request):
     d = LocaleHTMLCalendar()
     return "%s" % d.formatyearpage(self.year, 2, encoding='utf-8')
#!/usr/bin/env python

from calendar import LocaleHTMLCalendar
from datetime import datetime
import locale
now = datetime.now()
calendar = LocaleHTMLCalendar(locale=locale.getlocale())
calendar_table = calendar.formatmonth(now.year, now.month)
calendar_table = calendar_table.replace('border="0"', 'border="1"')

print('\x1bP;HTML|')
print(calendar_table)
print('\x1bP')