# Path: course/models/subject.py
# class Subject(models.Model):
#     def __str__(self):
#     def render_description(self):
#     def get_active(cls):
#     def get_visible(cls):
#     def get_inactive(cls):
#     def get_invisible(cls):
#     def active_courses(self):
#     def visible_courses(self):
#     def is_active(self):
#     def is_visible(self):
# 
# Path: course/forms.py
# class SubjectForm(ModelForm):
#     name = forms.CharField(
#         validators=[subject_name_validator,
#                     subject_disallowed_names_validator],
#         help_text=_(
#             'Name of the subject, also decides its url. '
#             'Allowed characters are word characters, numbers, spaces, '
#             '\'-\' and \'_\' and it cannot be any of '
#             + ', ').join(map(lambda a: '\'' + a + '\'', SUBJECT_DISALLOWED_NAMES)) + '.'
#     )
# 
#     class Meta:
#         model = Subject
#         fields = [
#             'name',
#             'description_en',
#             'description_de',
#         ]
# 
# Path: util/error/reporting.py
# def db_error(message):
#     """
#     Report a database error in a view.
#     """
#     return render_to_response('error/db.html', {'error': message})


from django.urls import reverse
from django.contrib.auth.decorators import login_required, permission_required
from django.shortcuts import redirect, render
from django.views.decorators.http import require_POST
from django.utils.translation import ugettext as _
from course.models import subject
from course.forms import SubjectForm
from util.error.reporting import db_error
        return db_error(_('Requested subject does not exist.'))

    if request.method == 'POST':
        form = SubjectForm(request.POST, instance=subj)

        if 'cancel' not in request.POST and form.is_valid():
            subj.save()

        return redirect('subject', subj.name)

    else:
        form = SubjectForm(instance=subj)

    return render(
        request,
        'subject/edit.html',
        {
            'title': subj.name,
            'create': False,
            'form': form,
            'subject': subj
        }
    )


@login_required()
@require_POST
@permission_required('subject.delete_subject')
def delete(request, subjectname):
    try:

# Path: course/models/subject.py
# class Subject(models.Model):
#     def __str__(self):
#     def render_description(self):
#     def get_active(cls):
#     def get_visible(cls):
#     def get_inactive(cls):
#     def get_invisible(cls):
#     def active_courses(self):
#     def visible_courses(self):
#     def is_active(self):
#     def is_visible(self):
# 
# Path: course/forms.py
# class SubjectForm(ModelForm):
#     name = forms.CharField(
#         validators=[subject_name_validator,
#                     subject_disallowed_names_validator],
#         help_text=_(
#             'Name of the subject, also decides its url. '
#             'Allowed characters are word characters, numbers, spaces, '
#             '\'-\' and \'_\' and it cannot be any of '
#             + ', ').join(map(lambda a: '\'' + a + '\'', SUBJECT_DISALLOWED_NAMES)) + '.'
#     )
# 
#     class Meta:
#         model = Subject
#         fields = [
#             'name',
#             'description_en',
#             'description_de',
#         ]
# 
# Path: util/error/reporting.py
# def db_error(message):
#     """
#     Report a database error in a view.
#     """
#     return render_to_response('error/db.html', {'error': message})


# Path: course/views/subject.py
from django.urls import reverse
from django.contrib.auth.decorators import login_required, permission_required
from django.shortcuts import redirect, render
from django.views.decorators.http import require_POST
from django.utils.translation import ugettext as _
from course.models import subject
from course.forms import SubjectForm
from util.error.reporting import db_error

        return db_error(_('Requested subject does not exist.'))

    if request.method == 'POST':
        form = SubjectForm(request.POST, instance=subj)

        if 'cancel' not in request.POST and form.is_valid():
            subj.save()

        return redirect('subject', subj.name)

    else:
        form = SubjectForm(instance=subj)

    return render(
        request,
        'subject/edit.html',
        {
            'title': subj.name,
            'create': False,
            'form': form,
            'subject': subj
        }
    )


@login_required()
@require_POST
@permission_required('subject.delete_subject')
def delete(request, subjectname):
    try:

        subj = subject.Subject.objects.get(name=subjectname)