added rich text functionality for questions

This commit is contained in:
tkupek 2016-03-05 13:14:33 +01:00
parent ef95803e78
commit 1ba6ed1980
9 changed files with 64 additions and 9 deletions

View file

@ -5,4 +5,4 @@ requirements:
- python - python
- django - django
- sqlite3 - sqlite3
- tinymce

Binary file not shown.

View file

@ -1,6 +1,6 @@
from django.contrib import admin from django.contrib import admin
from tkupek_elearning.elearning.models import Option, Setting, Question, UserAnswer, User, UserAnswerOptions from tkupek_elearning.elearning.models import Option, Setting, Question, UserAnswer, User
class OptionInline(admin.TabularInline): class OptionInline(admin.TabularInline):

View file

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-03-05 11:28
from __future__ import unicode_literals
from django.db import migrations, models
import tinymce.models
import tkupek_elearning.elearning.models
class Migration(migrations.Migration):
dependencies = [
('elearning', '0021_setting_token'),
]
operations = [
migrations.AlterField(
model_name='question',
name='explanation',
field=tinymce.models.HTMLField(null=True),
),
migrations.AlterField(
model_name='user',
name='last_seen',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AlterField(
model_name='user',
name='token',
field=models.CharField(default=tkupek_elearning.elearning.models.gen_token, max_length=40, null=True, unique=True),
),
]

View file

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-03-05 11:58
from __future__ import unicode_literals
from django.db import migrations
import tinymce.models
class Migration(migrations.Migration):
dependencies = [
('elearning', '0022_auto_20160305_1128'),
]
operations = [
migrations.AlterField(
model_name='question',
name='text',
field=tinymce.models.HTMLField(null=True),
),
]

View file

@ -4,6 +4,7 @@ import hashlib
import os import os
from django.db import models from django.db import models
from tinymce.models import HTMLField
def gen_token(): def gen_token():
@ -30,8 +31,8 @@ class Setting(models.Model):
class Question(models.Model): class Question(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
title = models.CharField(max_length=100, null=True) title = models.CharField(max_length=100, null=True)
text = models.TextField(null=True) text = HTMLField(null=True)
explanation = models.TextField(null=True) explanation = HTMLField(null=True)
def __unicode__(self): def __unicode__(self):
return self.title return self.title

View file

@ -35,7 +35,7 @@
{% for question, options in questions_options.items %} {% for question, options in questions_options.items %}
<div class="container question" name="question" id="question_{{ question.id }}"> <div class="container question" name="question" id="question_{{ question.id }}">
<h2>{{ question.id }}: {{ question.title }}</h2> <h2>{{ question.id }}: {{ question.title }}</h2>
<p>{{ question.text }}</p> <p>{{ question.text|safe }}</p>
<ul class="list-group "> <ul class="list-group ">
{% for option in options %} {% for option in options %}
@ -59,7 +59,7 @@
<div class="margin10 well well-sm hide" id="explanation_{{ question.id }}"> <div class="margin10 well well-sm hide" id="explanation_{{ question.id }}">
<h3>{{ settings.text_answer }}</h3> <h3>{{ settings.text_answer }}</h3>
<p>{{ question.explanation }}</p> <p>{{ question.explanation|safe }}</p>
</div> </div>
<div class="margin75"></div> <div class="margin75"></div>
</div> </div>

View file

@ -37,7 +37,8 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'tkupek_elearning.elearning' 'tkupek_elearning.elearning',
'tinymce',
] ]
MIDDLEWARE_CLASSES = [ MIDDLEWARE_CLASSES = [

View file

@ -13,7 +13,7 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include 1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
""" """
from django.conf.urls import url from django.conf.urls import url, include
from django.contrib import admin from django.contrib import admin
import tkupek_elearning.elearning.views import tkupek_elearning.elearning.views
@ -23,5 +23,5 @@ urlpatterns = [
url(r'start', tkupek_elearning.elearning.views.start), url(r'start', tkupek_elearning.elearning.views.start),
url(r'api', tkupek_elearning.elearning.views.get_answer), url(r'api', tkupek_elearning.elearning.views.get_answer),
url(r'statistic', tkupek_elearning.elearning.views.statistic), url(r'statistic', tkupek_elearning.elearning.views.statistic),
url(r'^tinymce/', include('tinymce.urls')),
] ]