# Path: course/models/news.py
# class News(models.Model):
#     def __str__(self):
#     def render_entry(self):
#     def render_date(self):
# 
# Path: course/forms.py
# class NewsForm(ModelForm):
#     class Meta:
#         model = News
#         fields = [
#             'headline',
#             'entry'
#         ]
# 
# 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 django.http import HttpRequest
from course.models import news
from course.forms import NewsForm
from util.error.reporting import db_error
            cur_news.save()
            return redirect('index')

    else:
        form = NewsForm(instance=cur_news)
    return render(
        request,
        'news/edit.html',
        {
            'title': _('Edit News'),
            'create': False,
            'form': form,
            'news_id': news_id
        }
    )


@login_required
@permission_required('news.delete_news')
def delete(request: HttpRequest, news_id: str):
    """
    Delete a news entry.

    :param request: request object
    :param news_id: id for the news
    :return:
    """
    try:
        cur_news = news.News.objects.get(id=news_id)
    except news.News.DoesNotExist:

# Path: course/models/news.py
# class News(models.Model):
#     def __str__(self):
#     def render_entry(self):
#     def render_date(self):
# 
# Path: course/forms.py
# class NewsForm(ModelForm):
#     class Meta:
#         model = News
#         fields = [
#             'headline',
#             'entry'
#         ]
# 
# 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/news.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 django.http import HttpRequest
from course.models import news
from course.forms import NewsForm
from util.error.reporting import db_error

            cur_news.save()
            return redirect('index')

    else:
        form = NewsForm(instance=cur_news)
    return render(
        request,
        'news/edit.html',
        {
            'title': _('Edit News'),
            'create': False,
            'form': form,
            'news_id': news_id
        }
    )


@login_required
@permission_required('news.delete_news')
def delete(request: HttpRequest, news_id: str):
    """
    Delete a news entry.

    :param request: request object
    :param news_id: id for the news
    :return:
    """
    try:
        cur_news = news.News.objects.get(id=news_id)
    except news.News.DoesNotExist:

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