-
Notifications
You must be signed in to change notification settings - Fork 52
Style/grid #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Style/grid #106
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
f6c619b
Hello Wrold
aviadamar 1ee94e4
Creating Html Template
aviadamar 96b80de
First Calendar Monthly View - HTML\CSS only
aviadamar 4614585
Merge branch 'main' of https://github.com/PythonFreeCourse/calendar i…
aviadamar 82249b5
Calendar dates calculation intigrating with html, HTML\CSS improvments.
aviadamar d2208d6
Merge branch 'main' of https://github.com/PythonFreeCourse/calendar i…
aviadamar 178e904
Tests for calender_grid.py, changing function according to currection…
aviadamar f385c56
linting bug fixing
aviadamar c2aa519
before merge with develop
aviadamar 3a563cc
after merge with develop
aviadamar 6f9a2ba
Creating a Day object and days subclasses, changing all function and …
aviadamar a17e89b
Fixing Conflicts
aviadamar 75abb99
fix lintings
aviadamar d2577aa
fix lintings
aviadamar e76ed53
tests next week scroll
aviadamar 19768ca
js updates
aviadamar b288c49
Calendar Scrolling with javascript
aviadamar 5621485
Calendar infinit scrolling and functions changes, bus fixing
aviadamar 10b836c
Fix lintings
aviadamar 43dd46e
Fix lintings
aviadamar 248a0ba
Calendar infinit scrolling ducplicates weeks bug fixed
aviadamar 59b7fe3
seetings global parameters for calendar.py
aviadamar efa6b2d
Js - changing to fetch, removing jquery, fixing hint tpying, adding W…
aviadamar 1df4cd5
Front end bug fixing
aviadamar 2e02b65
Fix linting
aviadamar e02bd14
Fix lintings
aviadamar 2271a3c
Fix lintings
aviadamar 126c92e
gixing js bugs
aviadamar 8af556c
fixing syntax
aviadamar bc3322f
Get user local date and time when enter calendar.
aviadamar a60c7c8
Fix lintings
aviadamar 60849ab
bug fixging and pull develop update
aviadamar b8e6044
Fix lintings
aviadamar 0b601e2
Fix lintings
aviadamar 9ca2183
Bugs fixing
aviadamar 79b2f5c
Bugs fixing
aviadamar e4c662d
Js fixing bugs and syntext.
aviadamar 03e4349
Bugs fixing
aviadamar 982daea
Bugs fixing
aviadamar 19de078
JS alerts removal
aviadamar b97279f
Fix Lintings
aviadamar 6516f7c
Js syntext fixing
aviadamar d496b07
Bugs fixing
aviadamar 41b7bd4
Bugs fixing
aviadamar 66d8972
Js fixing varibales and adding div element to request.
aviadamar 4f54e25
Js global parameters fixing
aviadamar f0bd6ac
Develop update
aviadamar b9a0c0b
Develop Update
aviadamar 5cbf776
Js - eliminate global parameters
aviadamar 901f88f
Linting fixing
aviadamar 445a962
Fix Lintings
aviadamar dd0f480
Js fixings
aviadamar 1e8e206
Fix flake8
aviadamar 85d904f
syntac fixing
aviadamar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from http import HTTPStatus | ||
|
||
from app.dependencies import templates | ||
from app.routers import calendar_grid as cg | ||
from fastapi import APIRouter, Request | ||
from fastapi.responses import HTMLResponse | ||
from starlette.responses import Response | ||
|
||
router = APIRouter( | ||
prefix="/calendar/month", | ||
tags=["calendar"], | ||
responses={404: {"description": "Not found"}}, | ||
) | ||
|
||
ADD_DAYS_ON_SCROLL: int = 42 | ||
|
||
|
||
@router.get("/") | ||
async def calendar(request: Request) -> Response: | ||
user_local_time = cg.Day.get_user_local_time() | ||
day = cg.create_day(user_local_time) | ||
return templates.TemplateResponse( | ||
"calendar/calendar.html", | ||
{ | ||
"request": request, | ||
"day": day, | ||
"week_days": cg.Week.DAYS_OF_THE_WEEK, | ||
"weeks_block": cg.get_month_block(day) | ||
} | ||
) | ||
|
||
|
||
@router.get("/{date}") | ||
async def update_calendar(request: Request, date: str) -> HTMLResponse: | ||
last_day = cg.Day.convert_str_to_date(date) | ||
next_weeks = cg.create_weeks(cg.get_n_days(last_day, ADD_DAYS_ON_SCROLL)) | ||
template = templates.get_template('calendar/add_week.html') | ||
content = template.render(weeks_block=next_weeks) | ||
return HTMLResponse(content=content, status_code=HTTPStatus.OK) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
import calendar | ||
import itertools | ||
import locale | ||
from datetime import date, datetime, timedelta | ||
from typing import Dict, Iterator, List, Tuple | ||
|
||
import pytz | ||
|
||
MONTH_BLOCK: int = 6 | ||
|
||
locale.setlocale(locale.LC_TIME, ("en", "UTF-8")) | ||
|
||
|
||
class Day: | ||
"""A Day class. | ||
|
||
Args: | ||
date (datetime): A single datetime date. | ||
Arguments: | ||
date (datetime): A single datetime date. | ||
sday (str): The day name. | ||
dailyevents (List): List of tuples represent daily event information. | ||
events (List): List of tuples represent time event name. | ||
EX: [("09AP", "Meeting with yam")] | ||
css (Dict): All css classes represent day. | ||
""" | ||
|
||
def __init__(self, date: datetime): | ||
self.date: datetime = date | ||
self.sday: str = self.date.strftime("%A") | ||
self.dailyevents: List[Tuple] = [] | ||
self.events: List[Tuple] = [] | ||
self.css: Dict[str, str] = { | ||
'day_container': 'day', | ||
'date': 'day-number', | ||
'daily_event': 'month-event', | ||
'daily_event_front': ' '.join([ | ||
'daily', | ||
'front', | ||
'background-warmyellow' | ||
]), | ||
'daily_event_back': ' '.join([ | ||
'daily', | ||
'back', | ||
'text-darkblue', | ||
'background-lightgray' | ||
]), | ||
'event': 'event', | ||
} | ||
|
||
def __str__(self) -> str: | ||
return self.date.strftime("%d") | ||
|
||
def display(self) -> str: | ||
"""Returns day date inf the format of 00 MONTH 00""" | ||
return self.date.strftime("%d %B %y").upper() | ||
|
||
def set_id(self) -> str: | ||
"""Returns day date inf the format of 00-mon-0000""" | ||
return self.date.strftime("%d-%b-%Y") | ||
|
||
@classmethod | ||
def get_user_local_time(cls) -> datetime: | ||
greenwich = pytz.timezone('GB') | ||
return greenwich.localize(datetime.now()) | ||
|
||
@classmethod | ||
def convert_str_to_date(cls, date_string: str) -> datetime: | ||
return datetime.strptime(date_string, '%d-%b-%Y') | ||
|
||
@classmethod | ||
def is_weekend(cls, date: date) -> bool: | ||
"""Returns true if this day is represent a weekend.""" | ||
return date.strftime("%A") in Week.DAYS_OF_THE_WEEK[-2:] | ||
|
||
|
||
class DayWeekend(Day): | ||
def __init__(self, date: datetime): | ||
super().__init__(date) | ||
self.css = { | ||
'day_container': 'day ', | ||
'date': ' '.join(['day-number', 'text-gray']), | ||
'daily_event': 'month-event', | ||
'daily_event_front': ' '.join([ | ||
'daily', | ||
'front', | ||
'background-warmyellow' | ||
]), | ||
'daily_event_back': ' '.join([ | ||
'daily', | ||
'back', | ||
'text-darkblue', | ||
'background-lightgray' | ||
]), | ||
'event': 'event', | ||
} | ||
|
||
|
||
class Today(Day): | ||
def __init__(self, date: datetime): | ||
super().__init__(date) | ||
self.css = { | ||
'day_container': ' '.join([ | ||
'day', | ||
'text-darkblue', | ||
'background-yellow' | ||
]), | ||
'date': 'day-number', | ||
'daily_event': 'month-event', | ||
'daily_event_front': ' '.join([ | ||
'daily', | ||
'front', | ||
'text-lightgray', | ||
'background-darkblue' | ||
]), | ||
'daily_event_back': ' '.join([ | ||
'daily', | ||
'back', | ||
'text-darkblue', | ||
'background-lightgray' | ||
]), | ||
'event': 'event', | ||
} | ||
|
||
|
||
class FirstDayMonth(Day): | ||
def __init__(self, date: datetime): | ||
super().__init__(date) | ||
self.css = { | ||
'day_container': ' '.join([ | ||
'day', | ||
'text-darkblue', | ||
'background-lightgray' | ||
]), | ||
'date': 'day-number', | ||
'daily_event': 'month-event', | ||
'daily_event_front': ' '.join([ | ||
'daily front', | ||
'text-lightgray', | ||
'background-red' | ||
]), | ||
'daily_event_back': ' '.join([ | ||
'daily', | ||
'back', | ||
'text-darkblue', | ||
'background-lightgray' | ||
]), | ||
'event': 'event', | ||
} | ||
|
||
def __str__(self) -> str: | ||
return self.date.strftime("%d %b %y").upper() | ||
|
||
|
||
class Week: | ||
WEEK_DAYS: int = 7 | ||
DAYS_OF_THE_WEEK: List[str] = calendar.day_name | ||
|
||
def __init__(self, days: List[Day]): | ||
self.days: List[Day] = days | ||
|
||
|
||
def create_day(day: datetime) -> Day: | ||
"""Return the currect day object according to given date.""" | ||
if day == date.today(): | ||
return Today(day) | ||
if int(day.day) == 1: | ||
return FirstDayMonth(day) | ||
if Day.is_weekend(day): | ||
return DayWeekend(day) | ||
return Day(day) | ||
|
||
|
||
def get_next_date(date: datetime) -> Iterator[Day]: | ||
"""Generate date objects from a starting given date.""" | ||
yield from ( | ||
create_day(date + timedelta(days=i)) | ||
for i in itertools.count(start=1) | ||
) | ||
|
||
|
||
def get_date_before_n_days(date: datetime, n: int) -> datetime: | ||
"""Returns the date before n days.""" | ||
return date - timedelta(days=n) | ||
|
||
|
||
def get_first_day_month_block(date: datetime) -> datetime: | ||
aviadamar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Returns the first date in a month block of given date.""" | ||
return list(calendar.Calendar().itermonthdates(date.year, date.month))[0] | ||
|
||
|
||
def get_n_days(date: datetime, n: int) -> Iterator[Day]: | ||
"""Generate n dates from a starting given date.""" | ||
next_date_gen = get_next_date(date) | ||
yield from itertools.islice(next_date_gen, n) | ||
|
||
|
||
def create_weeks( | ||
days: Iterator[Day], | ||
length: int = Week.WEEK_DAYS | ||
) -> List[Week]: | ||
"""Return lists of Weeks objects.""" | ||
ndays: List[Day] = list(days) | ||
num_days: int = len(ndays) | ||
return [Week(ndays[i:i + length]) for i in range(0, num_days, length)] | ||
|
||
|
||
def get_month_block(day: Day, n: int = MONTH_BLOCK) -> List[Week]: | ||
"""Returns a 2D list represent a n days calendar from current month.""" | ||
current = get_first_day_month_block(day.date) - timedelta(days=1) | ||
num_of_days = Week.WEEK_DAYS * n | ||
return create_weeks(get_n_days(current, num_of_days)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.