def day_treatment(request, treatment_date=None):
    required_date = treatment_date.split('-')
    today_date = datetime.today()
    required_date = datetime(int(required_date[0]), int(required_date[1]),
                             int(required_date[2]))

    if required_date < today_date and not (request.user.is_staff
                                           or request.user.is_superuser):
        messages.error(request, "התאריך שבחרת עבר ולא ניתן לתת בו שירות.")
        result = HttpResponseRedirect(reverse('calendar:calendar'))

    else:
        context = dict()
        # test = get_object_or_404(Treatments, date=treatment_date) // for 1 item only!
        required_date = treatment_date.split('-')
        day = required_date[2]
        context['day'] = day
        context['month'] = CalendarView().formatmonthname(required_date[1])
        context['year'] = required_date[0]
        calendar = TreatmentsCalendar(int(required_date[0]),
                                      int(required_date[1]))
        html_calendar = calendar.formatmonth(withyear=True)
        context['calendar'] = mark_safe(html_calendar)
        html_holidays = calendar.format_holidays(day)
        context['holidays'] = mark_safe(html_holidays)
        html_treatments = calendar.format_treatments(day, request.user)
        context['treatments'] = mark_safe(html_treatments)
        path_previous_month_format = f"?month={required_date[0]}-{required_date[1]}"
        context['previous'] = path_previous_month_format

        result = render(request, 'calendarapp/calendar_day_treatments.html',
                        context)

    return result
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        today_date = get_date(self.request.GET.get('month', None))
        calendar = TreatmentsCalendar(today_date.year, today_date.month)
        html_calendar = calendar.formatmonth(withyear=True)
        context['calendar'] = mark_safe(html_calendar)
        context['prev_month'] = prev_month(today_date)
        context['next_month'] = next_month(today_date)
        context['month'] = self.formatmonthname(today_date.month)
        context['year'] = today_date.year

        return context
Beispiel #3
0
 def get_context_data(self, **kwargs):
     """Return context which is html_calendar."""
     context = super().get_context_data(**kwargs)
     this_day = get_date(self.request.GET.get('month', None))
     calendar = Calendar(this_day.year, this_day.month)
     html_calendar = calendar.formatmonth(withyear=True)
     context['calendar'] = mark_safe(html_calendar)
     context['prev_month'] = prev_month(this_day)
     context['next_month'] = next_month(this_day)
     context['day'] = datetime.today().day
     context['month'] = datetime.today().month
     context['year'] = datetime.today().year
     return context
Beispiel #4
0
This would mean that from the command line you would call `python3 14_cal.py 4 2015` to 
print out a calendar for April in 2015, but if you omit either the year or both values, 
it should use today’s date to get the month and year.
"""

import sys
import calendar
from datetime import datetime

args = sys.argv
this_year = datetime.now().year
this_month = datetime.now().month
calendar = calendar.TextCalendar()

if len(args) == 1:
    print('\n', calendar.formatmonth(this_year, this_month))
elif len(args) == 2:
    if args[1].isdigit():
        this_month = int(args[1])
        print('\n', calendar.formatmonth(this_year, this_month))
    else:
        print('\nInvalid month. Please a number.\n')
elif len(args) == 3:
    if args[1].isdigit() and args[2].isdigit():
        this_month = int(args[1])
        this_year = int(args[2])
        print('\n', calendar.formatmonth(this_year, this_month))
    else:
        print(
            '\nMonth and year need to be in number format.\ne.g. "14_cal.py [month] [year]'
        )
Beispiel #5
0
def calendar(date, entries=None):
    calendar = EntryCalendar(date)
    return calendar.formatmonth(int(date.year), int(date.month))
Beispiel #6
0
def calendar_one(a=current_month, b=current_year):
    return calendar.formatmonth(b, a)
Beispiel #7
0
 - If the user doesn't specify any input, your program should 
   print the calendar for the current month. The 'datetime'
   module may be helpful for this.
 - If the user specifies one argument, assume they passed in a
   month and render the calendar for that month of the current year.
 - If the user specifies two arguments, assume they passed in
   both the month and the year. Render the calendar for that 
   month and year.
 - Otherwise, print a usage statement to the terminal indicating
   the format that your program expects arguments to be given.
   Then exit the program.
"""

import sys
import calendar
from datetime import datetime

calendar = calendar.TextCalendar(firstweekday=0)

if len(sys.argv) == 1:
    # Nothing specified, current month and year
    month = datetime.today().month
    year = datetime.today().year
    print(calendar.formatmonth(year, month))
elif len(sys.argv) == 2:
    print(calendar.formatmonth(datetime.today().year, int(sys.argv[1])))
elif len(sys.argv) == 3:
    # Calendar specified
    print(calendar.formatmonth(int(sys.argv[2]), int(sys.argv[1])))
else:
    print("Usage: calendar.py month [year]")
Beispiel #8
0
def month_calendar(month=datetime.today().month, year=datetime.today().year):
    print(calendar.formatmonth(year, month, 5))
Beispiel #9
0
   month and year.
 - Otherwise, print a usage statement to the terminal indicating
   the format that your program expects arguments to be given.
   Then exit the program.
"""

import sys
import calendar
from datetime import datetime

calendar = calendar.TextCalendar(calendar.MONDAY)
current_time = datetime.now()
year = int(current_time.strftime('%Y'))
month = int(current_time.strftime('%-m'))
if len(sys.argv) == 1:
    current = calendar.formatmonth(year, month)
    print(current)
elif len(sys.argv) == 2:
    try:
        if int(sys.argv[1]) < 0 or int(sys.argv[1]) > 13:
            print(
                'The first argument should be an int from 1 to 12 for the month'
            )
        else:
            month = int(sys.argv[1])
            current = calendar.formatmonth(year, month)
            print(current)
    except ValueError:
        print('It should be an int')
elif len(sys.argv) == 3:
    try:
Beispiel #10
0
 - If the user specifies two arguments, assume they passed in
   both the month and the year. Render the calendar for that 
   month and year.
 - Otherwise, print a usage statement to the terminal indicating
   the format that your program expects arguments to be given.
   Then exit the program.
"""

import calendar
import datetime

inputs = input("Type your input as: month year").split(" ")

now = datetime.date

if inputs is None:
    calendar = calendar.TextCalendar()
    format = calendar.formatmonth(now.year, now.month)
    print(format)

elif len(inputs) == 1:
    calendar = calendar.TextCalendar()
    calendar2 = calendar.formatmonth(now.year, inputs[0])
    print(format)
elif len(inputs) == 2:
    calendar = calendar.TextCalendar()
    calendar2 = calendar.formatmonth(inputs[1], inputs[0])
    print(format)
else:
    print("Please input your calendar month and year like: 04 2019")
    exit(1)