Skip to content

Commit

Permalink
Merge pull request #41 from Elthan/master
Browse files Browse the repository at this point in the history
Fixes in preparation for release; solves problem introduced with feature #32
  • Loading branch information
torgeirl committed Jul 25, 2018
2 parents d0495ab + 94b41f6 commit 97c2d86
Show file tree
Hide file tree
Showing 29 changed files with 415 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ coverage.xml
*.log
*.pot
**/migrations/
/staticfiles/


# Sphinx documentation
Expand Down
8 changes: 6 additions & 2 deletions docs/develop/databasedumps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Importing the test data
***********************
The easiest method of importing the test database is to use the ``recreate_devdb`` Invoke task::

$ inv recreate_devdb
$ inv recreate-devdb

.. warning:: This will destroy your current database.

Expand Down Expand Up @@ -45,10 +45,14 @@ To add new data, you just need to do add data to the database manually, or progr

Adding data manually (I.E.: Using the Django admin UI)
======================================================
To add data manually, you should first run the ``recreate_devdb`` management
To add data manually, you should first run the ``recreate-devdb`` management
command to make sure you start out with the current up-to-date dataset. Then you
can use the web-UI or the Django shell to add data. Finally, run::

$ inv dump-to-db

which is short for::
$ python manage.py dumpscript trix_core > trix/project/develop/dumps/dev/data.py


Expand Down
15 changes: 7 additions & 8 deletions docs/sysadmin/deploy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,17 @@ Trix is configured through a ``trix_settings.py`` file. Start by copying the fol

# Set this to False to turn of debug mode in production
DEBUG = False
TEMPLATE_DEBUG = DEBUG

****
LDAP
****
To enable LDAP authenication, ``trix_settings.py`` would need to include an authenication backend
with LDAP support, the URI for the LDAP server and its DN template, and possiblely some
`customization <https://django-auth-ldap.readthedocs.io/en/latest/authentication.html#customizing-authentication>`_
To enable LDAP authenication, ``trix_settings.py`` would need to include an authenication backend
with LDAP support, the URI for the LDAP server and its DN template, and possiblely some
`customization <https://django-auth-ldap.readthedocs.io/en/latest/authentication.html#customizing-authentication>`_
to adjust for how the usernames are stored in Trix's database.

As an example, the settings for UiO would need to adjust for the LDAP username not being a full
email adresse by overwriting ``ldap_to_django_username()`` and ``django_to_ldap_username()``
As an example, the settings for UiO would need to adjust for the LDAP username not being a full
email adresse by overwriting ``ldap_to_django_username()`` and ``django_to_ldap_username()``
functions of ``django_auth_ldap.backend.LDAPBackend``.

Add the following to you ``trix_settings.py`` file (but adjust the DN template)::
Expand All @@ -98,11 +97,11 @@ Add the following to you ``trix_settings.py`` file (but adjust the DN template):
Create a ``trix_uio_ldap_auth.py`` as follows (but adjust the email suffix)::

from django_auth_ldap.backend import LDAPBackend

class TrixUioLDAPBackend(LDAPBackend):
def ldap_to_django_username(self, username):
return u'{}@example.com'.format(username)

def django_to_ldap_username(self, username):
return username.split('@')[0]

Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from trix.project.develop.developtasks import *
from trix.project.develop.developtasks import * # noqa
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ max-line-length = 120
# Excludes:
# - exclude dev/data.py because that is autogenerated
# - exclude bower_components because some of the components contain .py files.
exclude = .git,.tox,__pycache,bower_components,trix/project/develop/dumps/dev/data.py
exclude = .git,.tox,__pycache,bower_components,trix/project/develop/dumps/dev/data.py,docs/conf.py,\
**/migrations/*

# See http://flake8.readthedocs.org/en/latest/warnings.html
# See http://flake8.pycqa.org/en/latest/user/error-codes.html
ignore = F403
2 changes: 1 addition & 1 deletion trix/project/default/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
],
'APP_DIRS': True,
'OPTIONS': {
'debug': True,
'debug': DEBUG,
'context_processors': [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
Expand Down
8 changes: 6 additions & 2 deletions trix/project/develop/settings/common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
Common development settings.
"""
from trix.project.default.settings import *
from django_dbdev.backends.postgres import DBSETTINGS
from trix.project.default.settings import * # noqa
from trix.project.default.settings import INSTALLED_APPS, MIDDLEWARE
# from django_dbdev.backends.postgres import DBSETTINGS

DEBUG = True
ROOT_URLCONF = 'trix.project.develop.urls'
Expand All @@ -23,3 +24,6 @@
MIDDLEWARE += [
'debug_toolbar.middleware.DebugToolbarMiddleware',
]

# For testing collectstatic
STATIC_ROOT = 'staticfiles'
2 changes: 1 addition & 1 deletion trix/project/develop/settings/develop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .common import *
from .common import * # noqa

LANGUAGE_CODE = 'nb'
2 changes: 1 addition & 1 deletion trix/project/develop/settings/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .common import *
from .common import * # noqa

# We test against the english original text
LANGUAGE_CODE = 'en'
Expand Down
3 changes: 2 additions & 1 deletion trix/project/production/herokudemosettings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
Settings for the Heroku demo.
"""
from .settings import *
from .settings import * # noqa
import os


BASE_DIR = os.path.dirname(
Expand Down
4 changes: 2 additions & 2 deletions trix/project/production/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from trix.project.default.settings import *

from trix.project.default.settings import * # noqa
from trix.project.default.settings import INSTALLED_APPS

ROOT_URLCONF = 'trix.project.production.urls'

Expand Down
6 changes: 3 additions & 3 deletions trix/project/settingsproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
DJANGOENV = os.environ.get('DJANGOENV', 'develop')

if DJANGOENV == 'develop': # Used for local development
from trix.project.develop.settings.develop import *
from trix.project.develop.settings.develop import * # noqa
elif DJANGOENV == 'test': # Used when running the Django tests locally
from trix.project.develop.settings.test import *
from trix.project.develop.settings.test import * # noqa
elif DJANGOENV == 'production': # Used in production demo on Heroku
from trix.project.production.herokudemosettings import *
from trix.project.production.herokudemosettings import * # noqa
else:
raise ValueError('Invalid value for the DJANGOENV environment variable: {}'.format(DJANGOENV))
1 change: 0 additions & 1 deletion trix/trix_admin/cradmin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.contrib.auth.decorators import login_required
from django.utils.translation import ugettext_lazy as _
from cradmin_legacy import crinstance
from django.core.urlresolvers import reverse
from trix.trix_admin.views import roleselect
from cradmin_legacy import crmenu

Expand Down
2 changes: 1 addition & 1 deletion trix/trix_admin/formfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def prepare_value(self, value):
tags = self.to_python(value)
return u', '.join([tag.tag for tag in tags])
else:
return trix_models.Tag.objects.filter(id__in=value).to_unicode()
return trix_models.Tag.objects.filter(tag__in=value).to_unicode()
else:
return ''

Expand Down
6 changes: 5 additions & 1 deletion trix/trix_admin/templates/trix_admin/roleselect.django.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% extends "cradmin_legacy/roleselect.django.html" %}
{% load i18n %}
{% load cradmin_legacy_tags %}


{% block title %}{% trans "Select course" %}{% endblock title %}
{% block body %}
Expand All @@ -10,7 +12,9 @@
</a>
</div>

{{ block.super }}
<div class="trix-roleselect">
{{ block.super }}
</div>

<div class="container" style="margin-top: 40px;">
<h2>{% trans "Documentation" %}</h2>
Expand Down
3 changes: 1 addition & 2 deletions trix/trix_admin/views/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core import serializers
from django.shortcuts import get_object_or_404
from django.template import defaultfilters
from django.template.defaultfilters import truncatechars, urlencode
from django.template.defaultfilters import truncatechars
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse
from django.views.generic import TemplateView
Expand All @@ -15,7 +15,6 @@
from cradmin_legacy.viewhelpers import delete
from cradmin_legacy.viewhelpers import multiselect
from cradmin_legacy import crispylayouts
from cradmin_legacy import viewhelpers
from cradmin_legacy import crapp
from crispy_forms import layout
from crispy_forms.utils import flatatt
Expand Down
8 changes: 4 additions & 4 deletions trix/trix_admin/views/permalinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from cradmin_legacy.viewhelpers import create
from cradmin_legacy.viewhelpers import update
from cradmin_legacy.viewhelpers import delete
from cradmin_legacy import viewhelpers
from cradmin_legacy import crapp
from crispy_forms import layout

Expand Down Expand Up @@ -106,25 +105,26 @@ def form_saved(self, permalink):
permalink.tags.add(course.course_tag)


class PermalinkCreateView(PermalinkCreateUpdateMixin, viewhelpers.create.CreateView):
class PermalinkCreateView(PermalinkCreateUpdateMixin, create.CreateView):
"""
View used to create new permalinks.
"""


class PermalinkUpdateView(PermalinkQuerysetForRoleMixin,
PermalinkCreateUpdateMixin,
viewhelpers.update.UpdateView):
update.UpdateView):
"""
View used to create edit existing permalinks.
"""


class PermalinkDeleteView(PermalinkQuerysetForRoleMixin, viewhelpers.delete.DeleteView):
class PermalinkDeleteView(PermalinkQuerysetForRoleMixin, delete.DeleteView):
"""
View used to delete existing permalinks.
"""
model = trix_models.Permalink
template_name = "trix_admin/delete.django.html"


class App(crapp.App):
Expand Down
123 changes: 123 additions & 0 deletions trix/trix_core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2018-07-25 13:46
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_active', models.BooleanField(default=True, help_text='User is active? Inactive users can not log in.', verbose_name='Is active?')),
('is_admin', models.BooleanField(default=False, help_text='User is superuser? Superusers have full access to the admin UI.', verbose_name='Is superuser?')),
('email', models.EmailField(max_length=255, unique=True)),
],
options={
'ordering': ['email'],
'verbose_name': 'User',
'verbose_name_plural': 'Users',
},
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255, verbose_name='Title')),
('text', models.TextField(help_text='Write the assignment here.', verbose_name='Assignment text')),
('solution', models.TextField(blank=True, default=b'', help_text='If you want your students to be able to view a suggested solution, write the solution here.', verbose_name='Solution')),
('created_datetime', models.DateTimeField(auto_now_add=True, verbose_name='Created')),
('lastupdate_datetime', models.DateTimeField(auto_now=True, verbose_name='Last changed')),
],
options={
'ordering': ['-lastupdate_datetime'],
'verbose_name': 'Assignment',
'verbose_name_plural': 'Assignments',
},
),
migrations.CreateModel(
name='Course',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('description', models.TextField(blank=True, default=b'', verbose_name='Description')),
],
options={
'ordering': ['course_tag'],
'verbose_name': 'Course',
'verbose_name_plural': 'Courses',
},
),
migrations.CreateModel(
name='HowSolved',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('howsolved', models.CharField(choices=[(b'bymyself', 'Solved by myself'), (b'withhelp', 'Solved with help')], max_length=10)),
('assignment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='trix_core.Assignment')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Permalink',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(blank=True, default=b'', max_length=255, verbose_name='Title')),
('description', models.TextField(blank=True, default=b'', verbose_name='Description')),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='trix_core.Course', verbose_name='Course')),
],
options={
'ordering': ['title'],
'verbose_name': 'Permalink',
'verbose_name_plural': 'Permalinks',
},
),
migrations.CreateModel(
name='Tag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tag', models.CharField(max_length=30, unique=True)),
('category', models.CharField(blank=True, choices=[(b'', 'No category'), (b'c', 'Course'), (b'p', 'Period')], default=b'', max_length=1)),
],
options={
'ordering': ['tag'],
'verbose_name': 'Tag',
'verbose_name_plural': 'Tags',
},
),
migrations.AddField(
model_name='permalink',
name='tags',
field=models.ManyToManyField(to='trix_core.Tag', verbose_name='Tags'),
),
migrations.AddField(
model_name='course',
name='active_period',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='active_period_set', to='trix_core.Tag'),
),
migrations.AddField(
model_name='course',
name='admins',
field=models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='course',
name='course_tag',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='course_set', to='trix_core.Tag'),
),
migrations.AddField(
model_name='assignment',
name='tags',
field=models.ManyToManyField(to='trix_core.Tag', verbose_name='Tags'),
),
]
Binary file added trix/trix_core/migrations/0001_initial.pyc
Binary file not shown.
20 changes: 20 additions & 0 deletions trix/trix_core/migrations/0002_assignment_hidden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2018-07-25 13:47
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('trix_core', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='assignment',
name='hidden',
field=models.NullBooleanField(choices=[(True, 'Yes'), (False, 'No')], default=False, verbose_name='Hide assignment from students'),
),
]
Empty file.
Binary file added trix/trix_core/migrations/__init__.pyc
Binary file not shown.

0 comments on commit 97c2d86

Please sign in to comment.