Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
22de7cbb
Commit
22de7cbb
authored
Dec 20, 2012
by
Carlos Andrés Rocha
Browse files
Options
Browse Files
Download
Plain Diff
Add logic to display courses by start date and show the new overlay
parents
a0d1d98c
4d137446
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
107 additions
and
39 deletions
+107
-39
common/djangoapps/student/views.py
+5
-4
lms/djangoapps/courseware/courses.py
+58
-3
lms/djangoapps/courseware/views.py
+5
-5
lms/static/sass/shared/_course_object.scss
+25
-0
lms/templates/course.html
+3
-0
lms/templates/courseware/courses.html
+5
-13
lms/templates/index.html
+6
-14
lms/templates/static_templates/_courses-newlisting.html
+0
-0
No files found.
common/djangoapps/student/views.py
View file @
22de7cbb
...
...
@@ -40,7 +40,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError
from
datetime
import
date
from
collections
import
namedtuple
from
courseware.courses
import
get_courses_by_
university
from
courseware.courses
import
get_courses_by_
start_date
from
courseware.access
import
has_access
from
statsd
import
statsd
...
...
@@ -74,16 +74,17 @@ def index(request, extra_context={}, user=None):
domain
=
settings
.
MITX_FEATURES
.
get
(
'FORCE_UNIVERSITY_DOMAIN'
)
# normally False
if
domain
==
False
:
# do explicit check, because domain=None is valid
domain
=
request
.
META
.
get
(
'HTTP_HOST'
)
universities
=
get_courses_by_university
(
None
,
domain
=
domain
)
courses
=
get_courses_by_start_date
(
None
,
domain
=
domain
)
# Get the 3 most recent news
top_news
=
_get_news
(
top
=
3
)
context
=
{
'
universities'
:
universiti
es
,
'news'
:
top_news
}
context
=
{
'
courses'
:
cours
es
,
'news'
:
top_news
}
context
.
update
(
extra_context
)
return
render_to_response
(
'index.html'
,
context
)
def
course_from_id
(
course_id
):
"""Return the CourseDescriptor corresponding to this course_id"""
course_loc
=
CourseDescriptor
.
id_to_location
(
course_id
)
...
...
lms/djangoapps/courseware/courses.py
View file @
22de7cbb
...
...
@@ -217,11 +217,66 @@ def get_courses_by_university(user, domain=None):
'''
# TODO: Clean up how 'error' is done.
# filter out any courses that errored.
visible_courses
=
branding
.
get_visible_courses
(
domain
)
visible_courses
=
get_courses
(
user
,
domain
)
universities
=
defaultdict
(
list
)
for
course
in
visible_courses
:
if
not
has_access
(
user
,
course
,
'see_exists'
):
continue
universities
[
course
.
org
]
.
append
(
course
)
return
universities
def
get_courses
(
user
,
domain
=
None
):
'''
Returns a list of courses available, sorted by course.number
'''
courses
=
branding
.
get_visible_courses
(
domain
)
courses
=
[
c
for
c
in
courses
if
has_access
(
user
,
c
,
'see_exists'
)]
return
courses
def
get_courses_by_start_date
(
user
,
domain
=
None
):
"""
Returns a list of courses available, sorted by start date
"""
visible_courses
=
get_courses
(
user
,
domain
)
courses
=
_sort_courses_and_mark_new
(
visible_courses
)
return
courses
def
_sort_courses_and_mark_new
(
courses
):
"""Sort by course start date and mark which have not started yet"""
for
course
in
courses
:
days_to_start
=
_get_course_days_to_start
(
course
)
# Add values as attributes, so they can be used in templates
setattr
(
course
,
'_days_to_start'
,
days_to_start
)
setattr
(
course
,
'is_new'
,
days_to_start
>
1
)
courses
=
sorted
(
courses
,
key
=
lambda
d
:
d
.
_days_to_start
,
reverse
=
True
)
return
courses
def
_get_course_days_to_start
(
course
):
from
datetime
import
datetime
as
dt
from
time
import
mktime
,
gmtime
convert_to_datetime
=
lambda
ts
:
dt
.
fromtimestamp
(
mktime
(
ts
))
start_date
=
convert_to_datetime
(
course
.
start
)
# If the course has a valid advertised date, use that instead
advertised_start
=
course
.
metadata
.
get
(
'advertised_start'
,
None
)
if
advertised_start
:
try
:
start_date
=
dt
.
strptime
(
advertised_start
,
"
%
Y-
%
m-
%
dT
%
H:
%
M"
)
except
ValueError
:
pass
# Invalid date, keep using course.start
now
=
convert_to_datetime
(
gmtime
())
days_to_start
=
(
start_date
-
now
)
.
days
return
days_to_start
lms/djangoapps/courseware/views.py
View file @
22de7cbb
...
...
@@ -17,7 +17,7 @@ from django.views.decorators.cache import cache_control
from
courseware
import
grades
from
courseware.access
import
has_access
from
courseware.courses
import
(
get_course_with_access
,
get_courses_by_
university
)
from
courseware.courses
import
(
get_course_with_access
,
get_courses_by_
start_date
)
import
courseware.tabs
as
tabs
from
courseware.models
import
StudentModuleCache
from
module_render
import
toc_for_course
,
get_module
,
get_instance_module
...
...
@@ -68,9 +68,9 @@ def courses(request):
'''
Render "find courses" page. The course selection work is done in courseware.courses.
'''
universities
=
get_courses_by_university
(
request
.
user
,
courses
=
get_courses_by_start_date
(
request
.
user
,
domain
=
request
.
META
.
get
(
'HTTP_HOST'
))
return
render_to_response
(
"courseware/courses.html"
,
{
'
universities'
:
universiti
es
})
return
render_to_response
(
"courseware/courses.html"
,
{
'
courses'
:
cours
es
})
def
render_accordion
(
request
,
course
,
chapter
,
section
):
...
...
@@ -317,7 +317,7 @@ def jump_to(request, course_id, location):
except
NoPathToItem
:
raise
Http404
(
"This location is not in any class: {0}"
.
format
(
location
))
# choose the appropriate view (and provide the necessary args) based on the
# choose the appropriate view (and provide the necessary args) based on the
# args provided by the redirect.
# Rely on index to do all error handling and access control.
if
chapter
is
None
:
...
...
@@ -328,7 +328,7 @@ def jump_to(request, course_id, location):
return
redirect
(
'courseware_section'
,
course_id
=
course_id
,
chapter
=
chapter
,
section
=
section
)
else
:
return
redirect
(
'courseware_position'
,
course_id
=
course_id
,
chapter
=
chapter
,
section
=
section
,
position
=
position
)
@ensure_csrf_cookie
def
course_info
(
request
,
course_id
):
"""
...
...
lms/static/sass/shared/_course_object.scss
View file @
22de7cbb
...
...
@@ -41,6 +41,31 @@
width
:
100%
;
@include
transition
(
all
,
0
.15s
,
linear
);
.status
{
background
:
$blue
;
color
:
white
;
font-size
:
10px
;
left
:
10px
;
padding
:
2px
10px
;
@include
border-radius
(
2px
);
position
:
absolute
;
text-transform
:
uppercase
;
top
:
-6px
;
z-index
:
100
;
}
.status
:after
{
border-bottom
:
6px
solid
shade
(
$blue
,
50%
);
border-right
:
6px
solid
transparent
;
content
:
""
;
display
:
block
;
height
:
0
;
position
:
absolute
;
right
:
-6px
;
top
:
0
;
width
:
0
;
}
a
:hover
{
text-decoration
:
none
;
}
...
...
lms/templates/course.html
View file @
22de7cbb
...
...
@@ -5,6 +5,9 @@
%
>
<
%
page
args=
"course"
/>
<article
id=
"${course.id}"
class=
"course"
>
%if course.is_new:
<span
class=
"status"
>
New
</span>
%endif
<a
href=
"${reverse('about_course', args=[course.id])}"
>
<div
class=
"inner-wrapper"
>
<header
class=
"course-preview"
>
...
...
lms/templates/courseware/courses.html
View file @
22de7cbb
...
...
@@ -20,21 +20,13 @@
## I'm removing this for now since we aren't using it for the fall.
##
<
%
include
file=
"course_filter.html"
/>
<section
class=
"courses"
>
<section
class=
'university-column'
>
%for course in universities['MITx']:
<ul
class=
"courses-listing"
>
%for course in courses:
<li
class=
"courses-listing-item"
>
<
%
include
file=
"../course.html"
args=
"course=course"
/>
</li>
%endfor
</section>
<section
class=
'university-column'
>
%for course in universities['HarvardX']:
<
%
include
file=
"../course.html"
args=
"course=course"
/>
%endfor
</section>
<section
class=
'university-column last'
>
%for course in universities['BerkeleyX']:
<
%
include
file=
"../course.html"
args=
"course=course"
/>
%endfor
</section>
</ul>
</section>
</section>
</section>
lms/templates/index.html
View file @
22de7cbb
...
...
@@ -106,21 +106,13 @@
</section>
<section
class=
"courses"
>
<section
class=
'university-column'
>
%for course in universities['MITx']:
<
%
include
file=
"course.html"
args=
"course=course"
/>
<ul
class=
"courses-listing"
>
%for course in courses:
<li
class=
"courses-listing-item"
>
<
%
include
file=
"course.html"
args=
"course=course"
/>
</li>
%endfor
</section>
<section
class=
'university-column'
>
%for course in universities['HarvardX']:
<
%
include
file=
"course.html"
args=
"course=course"
/>
%endfor
</section>
<section
class=
'university-column last'
>
%for course in universities['BerkeleyX']:
<
%
include
file=
"course.html"
args=
"course=course"
/>
%endfor
</section>
</ul>
</section>
</section>
</section>
...
...
lms/templates/static_templates/_courses-newlisting.html
deleted
100644 → 0
View file @
a0d1d98c
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment