<commit_before>from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django import forms

from devilry.core.models import Feedback
from devilry.ui.widgets import RstEditWidget

from devilry.ui.messages import UiMessages
from django.utils.translation import ugettext as _

class FeedbackForm(forms.ModelForm):
    """ A ModelForm for the :class:`devilry.core.models.Feedback`-class. """
    class Meta:
        model = Feedback
        fields = ('text', 'format', 'published')
        widgets = {
                #'text': forms.Textarea(attrs={'cols': 90, 'rows': 25})
                'text': RstEditWidget
        }

def parse_feedback_form(request, delivery_obj, prefix='feedback'):
    try:
        feedback_obj = delivery_obj.feedback
    except Feedback.DoesNotExist, e:
        feedback_obj = Feedback(delivery=delivery_obj)
    feedback_obj.last_modified_by = request.user
    if request.method == 'POST':
        return FeedbackForm(request.POST, instance=feedback_obj, prefix=prefix)
    else:
        return FeedbackForm(instance=feedback_obj, prefix=prefix)

def redirect_after_successful_save(request, delivery_obj):
    if not delivery_obj.feedback.published:
        messages = UiMessages()<commit_msg>Now send email when feedback is published<commit_after>from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django import forms

from devilry.core.models import Feedback
from devilry.ui.widgets import RstEditWidget

from devilry.ui.messages import UiMessages
from django.utils.translation import ugettext as _
from devilry.core.devilry_email import send_email

class FeedbackForm(forms.ModelForm):
    """ A ModelForm for the :class:`devilry.core.models.Feedback`-class. """
    class Meta:
        model = Feedback
        fields = ('text', 'format', 'published')
        widgets = {
                #'text': forms.Textarea(attrs={'cols': 90, 'rows': 25})
                'text': RstEditWidget
        }

def parse_feedback_form(request, delivery_obj, prefix='feedback'):
    try:
        feedback_obj = delivery_obj.feedback
    except Feedback.DoesNotExist, e:
        feedback_obj = Feedback(delivery=delivery_obj)
    feedback_obj.last_modified_by = request.user
    if request.method == 'POST':
        return FeedbackForm(request.POST, instance=feedback_obj, prefix=prefix)
    else:
        return FeedbackForm(instance=feedback_obj, prefix=prefix)

def redirect_after_successful_save(request, delivery_obj):
    if delivery_obj.feedback.published:
        assignment = delivery_obj.assignment_group.parentnode
        period = assignment.parentnode
        subject = period.parentnode
        
        email_message = "Your assignment has been corrected."
        email_message += "\n\n"
        email_message += "Subject: %s - %s\n" % (subject.long_name, period.long_name)
        email_message += "Assignment: %s\n" % (assignment.long_name)
        #email_message += "Time of : %s\n" % latest.time_of_delivery.strftime(DATETIME_FORMAT)
            
        send_email(request.user, 
                   "New feedback - %s" % (subject.short_name), 
                   email_message)
    else:
        messages = UiMessages()
{'fraction_non_alphanumeric': 0.0920011719894521, 'fraction_numerical': 0.0023439789041898623, 'mean_word_length': 3.4453125, 'pattern_counts': {'":': 0, '<': 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': '4427422', 'n_tokens_mistral': 1002, 'n_tokens_neox': 956, 'n_words': 230}