Example #1
0
def month_cal(year, month, month_iter=0):
    '''generates a month formatted calender from python standard calender lib based on provided month, year

    Arguments:
        year {date object} -- python datetime.datetime.now().year
        month {date object} -- python datetime.datetime.now().month

    Keyword Arguments:
        month_iter {int} -- iterater for creating months in the future from datetime.now() (default: {0})

    Returns:
        htmlstring -- html string calendar formatted by month
    '''

    now = datetime.datetime.now()
    cal = HTMLCalendar(firstweekday=6)
    cal = cal.formatmonth(theyear=year,
                          themonth=month + month_iter,
                          withyear=True)
    cal = cal.replace(
        '<table ',
        '<table data-month={0} data-year={1} cellpadding="10" cellspacing="10" class="m-2 text-center month" border="2" '
        .format(month + month_iter, year))
    if month_iter != 0 or year != now.year:
        cal = cal.replace(
            '<table ',
            '<table hidden data-month={0} data-year={1} cellpadding="10" cellspacing="10" class="m-2 text-center month" border="2" '
            .format(month + month_iter, year))

    return cal
Example #2
0
def calbuilder(request):
    year = int(request.POST.get('year', None))
    month = int(request.POST.get('month', None))
    cal = HTMLCalendar(calendar.SUNDAY)
    cal = cal.formatmonth(year, month)
    cal = cal.replace('<td ', '<td  width="150" height="150"')
    cal = cal.replace(
        'border="0" cellpadding="0" cellspacing="0" class="month">',
        'class="table">')
    events = Event.objects.filter(date__year=year, date__month=month)
    events_json = serializers.serialize('json', events)
    context = {'calendar': cal, 'events': events_json}
    return HttpResponse(json.dumps(context), content_type="application/json")
Example #3
0
def blog(request, post_id = 1):
    if not(request.user.is_authenticated()):
       request.user.username = '******'

    c = HTMLCalendar(6).formatmonth(date.today().year, date.today().month)
    c = c.replace('>%s</td>' % date.today().day,
                  '><u><a href=#>%s</a></u></td>' % date.today().day)
    return render_to_response('blog.html',
           {'post': Post.objects.get(id = post_id),
            'user': request.user,
            'calendar': c, })
Example #4
0
def blogs(request):
    if not(request.user.is_authenticated()):
       request.user.username = '******'

    c = HTMLCalendar(6).formatmonth(date.today().year, date.today().month)
    c = c.replace('>%s</td>' % date.today().day,
                  '><u><a href=#>%s</a></u></td>' % date.today().day)
    return render_to_response('blogs.html',
           {'blogs': Post.objects.all().order_by('-published_date'),
            'user': request.user,
            'calendar': c, }, context_instance=RequestContext(request))
Example #5
0
def blog(request, post_id=1):
    if not (request.user.is_authenticated()):
        request.user.username = '******'

    c = HTMLCalendar(6).formatmonth(date.today().year, date.today().month)
    c = c.replace('>%s</td>' % date.today().day,
                  '><u><a href=#>%s</a></u></td>' % date.today().day)
    return render_to_response(
        'blog.html', {
            'post': Post.objects.get(id=post_id),
            'user': request.user,
            'calendar': c,
        })
Example #6
0
def blogs(request):
    if not (request.user.is_authenticated()):
        request.user.username = '******'

    c = HTMLCalendar(6).formatmonth(date.today().year, date.today().month)
    c = c.replace('>%s</td>' % date.today().day,
                  '><u><a href=#>%s</a></u></td>' % date.today().day)
    return render_to_response(
        'blogs.html', {
            'blogs': Post.objects.all().order_by('-published_date'),
            'user': request.user,
            'calendar': c,
        },
        context_instance=RequestContext(request))
Example #7
0
 def calendar_with_link(year, month):
     """
     This takes a HTMLCalendar.formatmonth string as input and add a href to
     every days
     """
     HTMLCalendar_string = HTMLCalendar(0).formatmonth(int(year), int(month))
     for day in range(1,32) :
         #identify the position of the day in the string
         former = '>%s<' %(day,)
         day_link = reverse('my_profile:day_status', kwargs={'year': year,
                                                             'month': month,
                                                             'day': '{:0>2}'.format(day)})
         new = '><a href="%s" >%s</a><' %(day_link, day)
         HTMLCalendar_string = HTMLCalendar_string.replace(former, new)
     return HTMLCalendar_string
Example #8
0
    def makeCalImg(self):
        today = date.today()

        if today.day < 10:
            top = "-.4em"
            left = "-.6em"
        else:
            top = "-.3em"
            left = "-.25em"

        style = """<style>
            #day { position: relative; color: black; }
            tr { padding-top: 2px; }
            .thisday::before {
              position: absolute;
              top: TOP;
              left: LEFT;
              z-index: -1;
              content: " ";
              display: block;
              background-color: white;
              border: 2px solid black;
              width: 1.5em;
              height: 1.5em;
              border-radius: 1em;
            }
            th { padding: .1em}
            td { padding: 1px}
            th.month {display: none}
            table { font-family: courier; font-size: 14pt }
            </style>"""

        style = style.replace("TOP", top).replace("LEFT", left)
        htmlcal = HTMLCalendar().formatmonth(today.year,
                                             today.month,
                                             withyear=False)
        html = htmlcal.replace(
            ">%s<" % str(today.day),
            "><div id=day><span class=thisday>%s</span></div><" %
            str(today.day))

        styledcal = "<html>%s %s</html>" % (style, html)
        with open("cal.html", "w") as f:
            f.write(styledcal)
        imgkit.from_string(styledcal, 'cal.jpg')
Example #9
0
def index(request, year=date.today().year, month=date.today().month):
    year = int(year)
    month = int(month)

    #Verify next calendar - Pagination
    if month == 12:
        next_month = 1
        next_year = year + 1
    else:
        next_month = month + 1
        next_year = year

    # Verify previous calendar - Pagination
    if month == 1:
        prev_month = 12
        prev_year = year - 1
    else:
        prev_month = month - 1
        prev_year = year

    if year < 2000 or year > 2099:
        year = date.today().year

    cal = HTMLCalendar().formatmonth(year, month)

    if year == date.today().year and month == date.today().month:
        cal = cal.replace('>%i<' % date.today().day, ' bgcolor="#228B22"><b><u>%i</u></b><' % date.today().day)

    events = Event.objects.filter(event_date__year=year, event_date__month=month)

    context = {
        'month_name': calendar.month_name[month],
        'cal': cal,
        'year': year,
        'next_month': next_month,
        'next_year': next_year,
        'prev_month': prev_month,
        'prev_year': prev_year,
        'events': events
    }

    return render(request, 'events/calendar_base.html', context)
Example #10
0
def about(request):
    c = HTMLCalendar(6).formatmonth(date.today().year, date.today().month)
    c = c.replace('>%s</td>' % date.today().day,
                  '><u><a href=#>%s</a></u></td>' % date.today().day)
    return render_to_response('about.html', {'calendar': c})
Example #11
0
def about(request):
    c = HTMLCalendar(6).formatmonth(date.today().year, date.today().month)
    c = c.replace('>%s</td>' % date.today().day,
                  '><u><a href=#>%s</a></u></td>' % date.today().day)
    return render_to_response('about.html', {'calendar': c})