<commit_before>from backend.models import Question
from backend.serializers import *
from rest_framework import generics, viewsets
from django.contrib.auth.models import User
from rest_framework import permissions
from backend.permissions import IsOwnerOrReadOnly, IsAdminOrReadOnly, PostAllowed
from rest_framework import filters
from rest_framework.decorators import detail_route
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.authtoken.models import Token
from rest_framework.exceptions import ValidationError
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver
import smtplib
from backend.exceptions import ServiceUnavailable
smtp_user = "SMTP USER"
smtp_pwd = "<PASSWORD>"
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
    if created:
        Token.objects.create(user=instance)
class QuestionByCountyList(APIView):
    def get(self, request, county, format=None):
        questions = Question.objects.filter(county=county).all()
        serializer = QuestionSerializer(questions, many=True)
        return Response(serializer.data)

class QuestionByAudienceList(APIView):
    def get(self, request, audience, format=None):
        questions = Question.objects.filter(audiences=audience).all()
        serializer = QuestionSerializer(questions, many=True)
        return Response(serializer.data)

class QuestionByCategoryList(APIView):
    def get(self, request, category, format=None):
        questions = Question.objects.filter(category=category).all()
        serializer = QuestionSerializer(questions, many=True)
        return Response(serializer.data)

class QuestionViewSet(viewsets.ModelViewSet):
    queryset = Question.objects.all()
    serializer_class = QuestionSerializer
    permission_classes = (IsOwnerOrReadOnly,)
    filter_backends = (filters.SearchFilter,)
    search_fields = ('question',)
    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)
    def create(self, request, *args, **kwargs):
        langs = request.data['translations'].keys()
        questions = [question_pair['question'] for question_pair in request.data['translations'].values()]

        sender = '<EMAIL>'
        receivers = ['<EMAIL>']
        message = "From: <EMAIL>\n"
        message += "To: " + ", ".join(receivers) + "\n"
        message += "Subject: [" + " ".join(langs) + "] New Question : "+questions[0]+"\n\n"
        message += "\n".join(questions)

        with smtplib.SMTP('YOUR MAIL SERVER WITH SUBMISSION PORT HERE') as smtpObj:
            smtpObj.starttls()
            smtpObj.ehlo()
            smtpObj.login(smtp_user, smtp_pwd)
            smtpObj.sendmail(sender, receivers, message)
            return Response(request.data)
        """try:
            smtpObj = smtplib.SMTP('mail.germany-says-welcome.de')
            smtpObj.ehlo()
            smtpObj.starttls()
            smtpObj.ehlo
            smtpObj.login(smtp_user, smtp_pwd)
            smtpObj.sendmail(sender, receivers, message)
            return Response(request.data)
        except smtplib.SMTPException:
            raise ServiceUnavailable("Couldn't store question")"""



class POIViewSet(viewsets.ModelViewSet):
    queryset = POI.objects.all()
    serializer_class = POISerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,
                          IsOwnerOrReadOnly,)
    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)
<commit_msg>Suddenly these Whitespaces appeared, guess where they came from ...<commit_after>from backend.models import Question
from backend.serializers import *
from rest_framework import generics, viewsets
from django.contrib.auth.models import User
from rest_framework import permissions
from backend.permissions import IsOwnerOrReadOnly, IsAdminOrReadOnly, PostAllowed
from rest_framework import filters
from rest_framework.decorators import detail_route
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.authtoken.models import Token
from rest_framework.exceptions import ValidationError
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver
import smtplib
from backend.exceptions import ServiceUnavailable
smtp_user = "SMTP USER"
smtp_pwd = "<PASSWORD>"
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
    if created:
        Token.objects.create(user=instance)
class QuestionByCountyList(APIView):
    def get(self, request, county, format=None):
        questions = Question.objects.filter(county=county).all()
        serializer = QuestionSerializer(questions, many=True)
        return Response(serializer.data)

class QuestionByAudienceList(APIView):
    def get(self, request, audience, format=None):
        questions = Question.objects.filter(audiences=audience).all()
        serializer = QuestionSerializer(questions, many=True)
        return Response(serializer.data)

class QuestionByCategoryList(APIView):
    def get(self, request, category, format=None):
        questions = Question.objects.filter(category=category).all()
        serializer = QuestionSerializer(questions, many=True)
        return Response(serializer.data)

class QuestionViewSet(viewsets.ModelViewSet):
    queryset = Question.objects.all()
    serializer_class = QuestionSerializer
    permission_classes = (IsOwnerOrReadOnly,)
    filter_backends = (filters.SearchFilter,)
    search_fields = ('question',)
    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)
    def create(self, request, *args, **kwargs):
        langs = request.data['translations'].keys()
        questions = [question_pair['question'] for question_pair in request.data['translations'].values()]

        sender = '<EMAIL>'
        receivers = ['<EMAIL>']
        message = "From: <EMAIL>\n"
        message += "To: " + ", ".join(receivers) + "\n"
        message += "Subject: [" + " ".join(langs) + "] New Question : "+questions[0]+"\n\n"
        message += "\n".join(questions)


        try:
            with smtplib.SMTP('YOUR MAIL SERVER WITH SUBMISSION PORT HERE') as smtpObj:
                smtpObj.starttls()
                smtpObj.ehlo()
                smtpObj.login(smtp_user, smtp_pwd)
                smtpObj.sendmail(sender, receivers, message)
                return Response(request.data)
        except smtplib.SMTPException:
            raise ServiceUnavailable("Couldn't store question")



class POIViewSet(viewsets.ModelViewSet):
    queryset = POI.objects.all()
    serializer_class = POISerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,
                          IsOwnerOrReadOnly,)
    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)

{'fraction_non_alphanumeric': 0.09913487448588852, 'fraction_numerical': 0.00028364770954474543, 'mean_word_length': 3.7907608695652173, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1637705', 'n_tokens_mistral': 1989, 'n_tokens_neox': 1959, 'n_words': 445}