<commit_before>from django.shortcuts import render_to_response
from django.template import RequestContext
from notification.models import notices_for, NoticeType

def notices(request):
    notice_types = NoticeType.objects.all()
    if request.user.is_authenticated():
        notices = notices_for(request.user)
    else:
        notices = None
    return render_to_response("notification/notices.html", {
        "notices": notices,
        "notice_types": notice_types,
    }, context_instance=RequestContext(request))<commit_msg>Views for archive and delete Notice.<commit_after>from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.contrib.auth.decorators import login_required, permission_required

from notification.models import *

def notices(request):
    notice_types = NoticeType.objects.all()
    if request.user.is_authenticated():
        notices = notices_for(request.user)
    else:
        notices = None
    return render_to_response("notification/notices.html", {
        "notices": notices,
        "notice_types": notice_types,
    }, context_instance=RequestContext(request))

@login_required
def archive(request, noticeid=None, next_page=None):
    if noticeid:
        try:
            notice = Notice.objects.get(id=noticeid)
            if request.user == notice.user or request.user.is_superuser:
                notice.archive()
            else:   # you can archive other users' notices
                    # only if you are superuser.
                return HttpResponseRedirect(next_page)
        except Notice.DoesNotExist:
            return HttpResponseRedirect(next_page)
    return HttpResponseRedirect(next_page)

@login_required
def delete(request, noticeid=None, next_page=None):
    if noticeid:
        try:
            notice = Notice.objects.get(id=noticeid)
            if request.user == notice.user or request.user.is_superuser:
                notice.delete()
            else:   # you can delete other users' notices
                    # only if you are superuser.
                return HttpResponseRedirect(next_page)
        except Notice.DoesNotExist:
            return HttpResponseRedirect(next_page)
    return HttpResponseRedirect(next_page)
{'fraction_non_alphanumeric': 0.0776275621456607, 'fraction_numerical': 0.0, 'mean_word_length': 3.038732394366197, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2186667', 'n_tokens_mistral': 612, 'n_tokens_neox': 592, 'n_words': 145}