Store published date in module metadata, and display it on draft pages
This commit is contained in:
@@ -35,13 +35,13 @@ def get_course_location_for_item(location):
|
||||
return location
|
||||
|
||||
|
||||
def get_lms_link_for_item(item):
|
||||
def get_lms_link_for_item(location):
|
||||
if settings.LMS_BASE is not None:
|
||||
lms_link = "{lms_base}/courses/{course_id}/jump_to/{location}".format(
|
||||
lms_base=settings.LMS_BASE,
|
||||
# TODO: These will need to be changed to point to the particular instance of this problem in the particular course
|
||||
course_id = modulestore().get_containing_courses(item.location)[0].id,
|
||||
location=item.location,
|
||||
course_id = modulestore().get_containing_courses(location)[0].id,
|
||||
location=location,
|
||||
)
|
||||
else:
|
||||
lms_link = None
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from util.json_request import expect_json
|
||||
import json
|
||||
import os
|
||||
import logging
|
||||
import sys
|
||||
import mimetypes
|
||||
import StringIO
|
||||
import exceptions
|
||||
import json
|
||||
import logging
|
||||
import mimetypes
|
||||
import os
|
||||
import StringIO
|
||||
import sys
|
||||
import time
|
||||
from collections import defaultdict
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -154,7 +155,7 @@ def edit_subsection(request, location):
|
||||
|
||||
item = modulestore().get_item(location)
|
||||
|
||||
lms_link = get_lms_link_for_item(item)
|
||||
lms_link = get_lms_link_for_item(location)
|
||||
|
||||
# make sure that location references a 'sequential', otherwise return BadRequest
|
||||
if item.location.category != 'sequential':
|
||||
@@ -183,7 +184,8 @@ def edit_unit(request, location):
|
||||
|
||||
item = modulestore().get_item(location)
|
||||
|
||||
lms_link = get_lms_link_for_item(item)
|
||||
# The non-draft location
|
||||
lms_link = get_lms_link_for_item(item.location._replace(revision=None))
|
||||
|
||||
component_templates = defaultdict(list)
|
||||
|
||||
@@ -212,16 +214,24 @@ def edit_unit(request, location):
|
||||
|
||||
unit_state = compute_unit_state(item)
|
||||
|
||||
try:
|
||||
published_date = time.strftime('%B %d, %Y', item.metadata.get('published_date'))
|
||||
except TypeError:
|
||||
published_date = None
|
||||
|
||||
return render_to_response('unit.html', {
|
||||
'unit': item,
|
||||
'unit_location': published_location,
|
||||
'components': components,
|
||||
'component_templates': component_templates,
|
||||
'lms_link': lms_link,
|
||||
'draft_preview_link': lms_link,
|
||||
'published_preview_link': lms_link,
|
||||
'subsection': containing_subsection,
|
||||
'section': containing_section,
|
||||
'create_new_unit_template': Location('i4x', 'edx', 'templates', 'vertical', 'Empty'),
|
||||
'unit_state': unit_state,
|
||||
'release_date': None,
|
||||
'published_date': published_date,
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
.rendered-component {
|
||||
.xmodule_display {
|
||||
padding: 40px 20px 20px;
|
||||
}
|
||||
|
||||
@@ -410,7 +410,8 @@
|
||||
#delete-draft,
|
||||
#publish-draft,
|
||||
.component-actions,
|
||||
.new-component-item {
|
||||
.new-component-item,
|
||||
#published-alert {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -423,6 +424,7 @@
|
||||
#save-draft,
|
||||
#delete-draft,
|
||||
#publish-draft,
|
||||
#published-alert,
|
||||
#create-draft, {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -8,14 +8,22 @@
|
||||
new CMS.Views.UnitEdit({
|
||||
el: $('.main-wrapper'),
|
||||
model: new CMS.Models.Module({
|
||||
id: '${unit.location.url()}'
|
||||
id: '${unit_location}'
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</%block>
|
||||
<%block name="content">
|
||||
<div class="main-wrapper edit-state-${unit_state}" data-id="${unit.location.url()}">
|
||||
<div class="main-wrapper edit-state-${unit_state}" data-id="${unit_location}">
|
||||
<div class="inner-wrapper">
|
||||
<div class="alert" id="published-alert">
|
||||
<p class="alert-message"><strong>You are editing a draft.</strong>
|
||||
% if published_date:
|
||||
This unit was originally published on ${published_date}.
|
||||
% endif
|
||||
</p>
|
||||
<a href="${published_preview_link}" target="_blank" class="alert-action secondary">Preview the published version</a>
|
||||
</div>
|
||||
<div class="main-column">
|
||||
<article class="unit-body window">
|
||||
<p class="unit-name-input"><label>Display Name:</label><input type="text" value="${unit.display_name}" class="unit-display-name-input" /></p>
|
||||
@@ -60,7 +68,7 @@
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<div class="sidebar wip-box">
|
||||
<div class="sidebar">
|
||||
<div class="unit-properties window">
|
||||
<h4>Unit Properties</h4>
|
||||
<div class="window-contents">
|
||||
@@ -79,7 +87,7 @@
|
||||
<div class="row unit-actions">
|
||||
<a id="save-draft" href="#" class="save-button">Save Draft</a>
|
||||
<a id="delete-draft" href="#" class="save-button">Delete Draft</a>
|
||||
<a href="${lms_link}" target="_blank" class="preview-button">Preview</a>
|
||||
<a href="${draft_preview_link}" target="_blank" class="preview-button">Preview</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from datetime import datetime
|
||||
|
||||
from . import ModuleStoreBase, Location
|
||||
from .exceptions import ItemNotFoundError
|
||||
@@ -141,7 +142,10 @@ class DraftModuleStore(ModuleStoreBase):
|
||||
Save a current draft to the underlying modulestore
|
||||
"""
|
||||
draft = self.get_item(location)
|
||||
metadata = {}
|
||||
metadata.update(draft.metadata)
|
||||
metadata['published_date'] = tuple(datetime.utcnow().timetuple())
|
||||
super(DraftModuleStore, self).update_item(location, draft.definition.get('data', {}))
|
||||
super(DraftModuleStore, self).update_children(location, draft.definition.get('children', []))
|
||||
super(DraftModuleStore, self).update_metadata(location, draft.metadata)
|
||||
super(DraftModuleStore, self).update_metadata(location, metadata)
|
||||
self.delete_item(location)
|
||||
|
||||
Reference in New Issue
Block a user