feat: content not visible to guest users

This commit is contained in:
Shivam Mishra 2019-05-29 13:11:34 +05:30
parent 87a7438d38
commit ae2871f962
5 changed files with 55 additions and 37 deletions

View File

@ -1,5 +1,5 @@
{% extends "templates/base.html" %}
{% block title %}{% endblock %}
{% block title %}{{ content.name or 'Content Page' }}{% endblock %}
{% block head_include %}
<style>
@ -73,30 +73,6 @@
<div class="my-5">
{{ content.description }}
</div>
{% block script %}
<script src="https://cdn.plyr.io/3.5.3/plyr.js"></script>
<script>
const player = new Plyr('#player');
frappe.ready(() => {
next = document.getElementById('nextButton')
next.disabled = false;
})
function handle(url) {
frappe.call('ping').then((r) => {
frappe.call("add_activity",
{
course: {{ course }},
content_type: {{ content_type }},
content: {{ content.name }},
}
)
})
}
</script>
{% endblock %}
{% endmacro %}
{% macro article() %}
@ -133,4 +109,30 @@
</div>
</div>
</section>
{% endblock %}
{% block script %}
{% if content_type=='Video' %}
<script src="https://cdn.plyr.io/3.5.3/plyr.js"></script>
{% endif %}
<script>
{% if content_type=='Video' %}
const player = new Plyr('#player');
{% endif %}
frappe.ready(() => {
next = document.getElementById('nextButton')
next.disabled = false;
})
function handle(url) {
frappe.call("add_activity",
{
course: "{{ course }}",
content_type: "{{ content_type }}",
content: "{{ content.name }}",
}
)
}
</script>
{% endblock %}

View File

@ -5,15 +5,17 @@ import frappe
no_cache = 1
def get_context(context):
if frappe.session.user == "Guest":
frappe.local.flags.redirect_location = '/lms'
raise frappe.Redirect
context.course = frappe.form_dict['course']
context.topic = frappe.form_dict['topic']
content = frappe.form_dict['content']
context.content_type = frappe.form_dict['type']
context.content = frappe.get_doc(context.content_type, content).as_dict()
context.previous = get_previous_content(context.topic, context.course, context.content, context.content_type)
context.next = get_next_content(context.topic, context.course, context.content, context.content_type)
def get_next_content(topic, course, content, content_type):

View File

@ -35,7 +35,11 @@
{% macro card(topic, index, length) %}
<div class="col-sm-{{ 12 if length%3 == 1 and index == 1 else 6 if length%3 == 2 and index in [1,2] else 4}} mb-4 text-left">
<div class="card h-100">
<a href="/lms/content?course={{ course.name }}&topic={{ topic.name }}&type={{ topic.topic_content[0].content_type }}&content={{ topic.topic_content[0].content }}" class="no-decoration no-underline">
{% if frappe.session.user == 'Guest' %}
<div>
{% else %}
<a href="/lms/content?course={{ course.name }}&topic={{ topic.name }}&type={{ topic.topic_content[0].content_type }}&content={{ topic.topic_content[0].content }}" class="no-decoration no-underline">
{% endif %}
{% if topic.hero_image %}
<div class="card-hero-img" style="background-image: url({{ topic.hero_image }})"></div>
{% else %}
@ -48,21 +52,29 @@
<div>
<ol class="list-unstyled">
{% for content in topic.topic_content %}
<li><a class="text-muted" href="/lms/content?course={{ course.name }}&topic={{ topic.name }}&type={{ content.content_type }}&content={{ content.content }}">{{ content.content }}</li></a>
<li>
{% if frappe.session.user == 'Guest' %}
<span class="text-muted">{{ content.content }}</span>
{% else %}
<a class="text-muted" href="/lms/content?course={{ course.name }}&topic={{ topic.name }}&type={{ content.content_type }}&content={{ content.content }}">
{{ content.content }}
</a>
{% endif %}
</li>
{% endfor %}
</ol>
</div>
</div>
{% if index==1 %}
<div class='card-footer'>
<i class="fa fa-check-circle text-success"></i> Completed
{% if frappe.session.user == 'Guest' %}
</div>
{% else %}
{% else %}
<div class='card-footer'>
<i class="fa fa-circle-o text-warning"></i> In Progress
{% if index==1 %} <span class="indicator green"> Completed </span>
{% else %} <span class="indicator orange"> Completed </span>
{% endif %}
</div>
{% endif %}
</a>
</a>
{% endif %}
</div>
</div>
{% endmacro %}

View File

@ -62,7 +62,7 @@
<h1>{{ education_settings.portal_title }}</h1>
<p class='lead'>{{ education_settings.description }}</p>
<p class="mt-4">
<a class="btn btn-primary btn-lg" style="width: 170px;" href="/pricing">Start Learning</a>
<a class="btn btn-primary btn-lg" style="width: 170px;" href="{{ '/login#signup' if frappe.session.user == 'Guest' else '/lms/all-programs' }}">Start Learning</a>
</p>
<a href="https://erpnext.com" target="blank" class="mt-0 small text-muted">Go to erpnext.com</a>
</div>

View File

@ -3,7 +3,9 @@
<h1>{{ title}}</h1>
<p class='lead' style="max-width: 100%;">{{ description }}</p>
<p class="mt-4">
{% if frappe.session.user == 'Guest' %}
<a id="signup" class="btn btn-primary btn-lg" style="width: 170px;" href="/login#signup" hidden=true>Sign Up</a>
{% endif %}
</p>
</div>