-
Notifications
You must be signed in to change notification settings - Fork 119
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
#355 #477
Open
jcszymansk
wants to merge
23
commits into
pyvec:master
Choose a base branch
from
jcszymansk:issue395
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+182
−11
Open
#355 #477
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
933f935
yml with descriptions
jcszymansk bfed96e
shamelessly copy czech plurals from pyvec :-)
jcszymansk f8e24da
stupid yml mistake
jcszymansk cbbb517
basic list skel, no styles or data
jcszymansk 29d4fe9
add active runs
jcszymansk 97d9ca8
remove unnecessary print
jcszymansk 991c8c2
add all_runs, sessions_delivered
jcszymansk c265049
safe_courses now a function
jcszymansk 773b93b
add sessions_available
jcszymansk 799b18c
cheatsheets
jcszymansk 58c999d
make it look a little better
jcszymansk b517b67
yml with descriptions
jcszymansk a72077b
shamelessly copy czech plurals from pyvec :-)
jcszymansk 24ba12e
stupid yml mistake
jcszymansk 4d95b9b
basic list skel, no styles or data
jcszymansk 6e0440b
add active runs
jcszymansk a32a4fd
remove unnecessary print
jcszymansk e8037e7
add all_runs, sessions_delivered
jcszymansk 9a62b82
safe_courses now a function
jcszymansk 43bfee9
add sessions_available
jcszymansk 9a8a9c7
cheatsheets
jcszymansk 4a8ce40
make it look a little better
jcszymansk 7861f5e
Merge branch 'issue395' of github.com:jacekszymanski/naucse.python.cz…
jcszymansk 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 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,40 @@ | ||
entries: | ||
|
||
- label: active_runs | ||
text: | ||
- '%d právě probíhající kurz' | ||
- '%d právě probíhající kurzy' | ||
- '%d právě probíhajících kurzů' | ||
|
||
- label: all_runs | ||
text: | ||
- '%d kurz celkem' | ||
- '%d kurzy celkem' | ||
- '%d kurzů celkem' | ||
|
||
- label: sessions_delivered | ||
text: | ||
- '%d lekci odučeno' | ||
- '%d lekce odučeno' | ||
- '%d lekcí odučeno' | ||
|
||
- label: sessions_available | ||
text: | ||
- 'materiály pro %d lekci' | ||
- 'materiály pro %d různé lekce' | ||
- 'materiály pro %d různých lekcí' | ||
|
||
- label: cheatsheets | ||
text: | ||
- '%d tahák' | ||
- '%d taháky' | ||
- '%d taháků' | ||
|
||
- label: contributors | ||
text: | ||
- '%d autor' | ||
- '%d autoři' | ||
- '%d autorů' | ||
|
||
- label: price | ||
text: '%d Kč' |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -28,8 +28,11 @@ | |
from naucse.utils.views import does_course_return_info | ||
from naucse.utils.views import raise_errors_from_forks | ||
from naucse.utils.views import page_content_cache_key, get_edit_info | ||
from naucse.utils.views import czech_plural | ||
from naucse.validation import DisallowedStyle, DisallowedElement, InvalidHTML | ||
|
||
import yaml | ||
|
||
# so it can be mocked | ||
import naucse.utils.views | ||
|
||
|
@@ -44,7 +47,6 @@ | |
|
||
_cached_model = None | ||
|
||
|
||
@LocalProxy | ||
def model(): | ||
"""Return the root of the naucse model | ||
|
@@ -97,10 +99,19 @@ def session_url(course, session, coverpage='front'): | |
coverpage=coverpage) | ||
|
||
|
||
def load_stat_labels(): | ||
datafile = os.path.join(os.path.dirname(__file__), 'data/stats.yml') | ||
with open(datafile) as fstr: | ||
stat_labels = yaml.load(fstr) | ||
|
||
return stat_labels | ||
|
||
|
||
@app.route('/') | ||
def index(): | ||
return render_template("index.html", | ||
edit_info=get_edit_info(Path("."))) | ||
edit_info=get_edit_info(Path(".")), | ||
stat_labels=load_stat_labels()) | ||
|
||
|
||
@app.route('/runs/') | ||
|
@@ -172,23 +183,28 @@ def runs(year=None, all=None): | |
edit_info=get_edit_info(model.runs_edit_path)) | ||
|
||
|
||
def safe_courses(): | ||
courses = [] | ||
|
||
for course in model.courses.values(): | ||
if not course.is_link(): | ||
if not course.is_meta: | ||
courses.append(course) | ||
elif naucse.utils.views.forks_enabled() and does_course_return_info(course): | ||
courses.append(course) | ||
|
||
return courses | ||
|
||
@app.route('/courses/') | ||
def courses(): | ||
# since even the basic info about the forked courses can be broken, | ||
# we need to make sure the required info is provided. | ||
# If ``RAISE_FORK_ERRORS`` is set, exceptions are raised here, | ||
# otherwise the course is ignored completely. | ||
safe_courses = [] | ||
|
||
for course in model.courses.values(): | ||
if not course.is_link(): | ||
if not course.is_meta: | ||
safe_courses.append(course) | ||
elif naucse.utils.views.forks_enabled() and does_course_return_info(course): | ||
safe_courses.append(course) | ||
courses = safe_courses() | ||
|
||
return render_template("course_list.html", | ||
courses=safe_courses, | ||
courses=courses, | ||
title="Seznam online kurzů Pythonu", | ||
edit_info=get_edit_info(model.courses_edit_path)) | ||
|
||
|
@@ -920,3 +936,75 @@ def course_calendar_ics(course): | |
abort(404) | ||
|
||
return Response(str(calendar), mimetype="text/calendar") | ||
|
||
def active_runs(): | ||
today = datetime.date.today() | ||
|
||
runs = (model.runs_from_year(today.year) + | ||
model.runs_from_year(today.year - 1) + | ||
model.runs_from_year(today.year - 2)) | ||
ongoing = [run for run in runs if | ||
run.start_date <= today and run.end_date >= today] | ||
|
||
return len(ongoing) | ||
|
||
def all_runs(): | ||
all_years = list(model.safe_run_years.keys()) | ||
|
||
return sum([len(model.runs_from_year(year)) for year in all_years]) | ||
|
||
def sessions_delivered(): | ||
today = datetime.date.today() | ||
all_years = list(model.safe_run_years.keys()) | ||
|
||
all_runs = [] | ||
for year in all_years: | ||
all_runs.extend(model.runs_from_year(year)) | ||
|
||
all_sessions = [] | ||
for run in all_runs: | ||
all_sessions.extend(list(run.sessions.values())) | ||
|
||
return len([session for session in all_sessions if session.date < today]) | ||
|
||
def sessions_available(): | ||
uniq_sessions = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tady by podle mě bylo lepší použít set, nepotřebujeme si ukládat tu lekci samotnou, stačí ten slug. |
||
for course in safe_courses(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
for session in course.sessions.values(): | ||
uniq_sessions[session.slug] = session | ||
|
||
return len(uniq_sessions) | ||
|
||
def cheatsheets(): | ||
sheets = 0 | ||
for course in safe_courses(): | ||
for session in course.sessions.values(): | ||
for material in session.materials: | ||
if (material.url_type == 'cheatsheet'): | ||
sheets += 1 | ||
|
||
return sheets | ||
|
||
|
||
# This could use some caching, but for now it's the simplest way | ||
def basic_stat(name): | ||
if name == 'active_runs': | ||
return active_runs() | ||
elif name == 'all_runs': | ||
return all_runs() | ||
elif name == 'sessions_delivered': | ||
return sessions_delivered() | ||
elif name == 'sessions_available': | ||
return sessions_available() | ||
elif name == 'cheatsheets': | ||
return cheatsheets() | ||
else: # contributors, price | ||
return 0 | ||
|
||
@app.template_filter('fill_label') | ||
def fill_label(label): | ||
stat_number = basic_stat(label['label']) | ||
|
||
formatstr = czech_plural(label['text'], stat_number) | ||
|
||
return formatstr % stat_number |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Myslím, že je název tento fuknce lehce matoucí, myslím že něco jako
count_all_runs
by bylo lepší, přeci jen to nevrací kurzy, ale jejich počet...