<commit_before>from django.core.files.storage import DefaultStorage
from rest_framework import views, viewsets
from rest_framework.parsers import MultiPartParser
from rest_framework.response import Response

from .models import Microsite
from .serializers import MicrositeSerializer


class MicrositeViewSet(viewsets.ModelViewSet):
    queryset = Microsite.objects.all()
    serializer_class = MicrositeSerializer


class FileUploadView(views.APIView):
    parser_classes = (MultiPartParser,)

    def post(self, request, microsite_id, format=None):
        file_obj = request.data['file']
        microsite = Microsite.objects.get(id=microsite_id)
        microsite.values['logo_path'] = self.handle_uploaded_file(file_obj, request.GET.get('filename'))
        microsite.save()
        return Response(status=204)

    def handle_uploaded_file(self, content, filename):
        storage = DefaultStorage()
        name = storage.save(filename, content)
        return storage.url(name)<commit_msg>accept field_name as a parameter<commit_after>from django.core.files.storage import DefaultStorage
from rest_framework import views, viewsets
from rest_framework.parsers import MultiPartParser
from rest_framework.response import Response

from .models import Microsite
from .serializers import MicrositeSerializer


class MicrositeViewSet(viewsets.ModelViewSet):
    queryset = Microsite.objects.all()
    serializer_class = MicrositeSerializer


class FileUploadView(views.APIView):
    parser_classes = (MultiPartParser,)

    def post(self, request, microsite_id, format=None):
        file_obj = request.data['file']
        field_name = request.data['field_name']
        microsite = Microsite.objects.get(id=microsite_id)
        microsite.values[field_name] = self.handle_uploaded_file(file_obj, request.GET.get('filename'))
        microsite.save()
        return Response(status=204)

    def handle_uploaded_file(self, content, filename):
        storage = DefaultStorage()
        name = storage.save(filename, content)
        return storage.url(name)
{'fraction_non_alphanumeric': 0.0854368932038835, 'fraction_numerical': 0.002912621359223301, 'mean_word_length': 4.4668435013262595, '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': '7143030', 'n_tokens_mistral': 595, 'n_tokens_neox': 557, 'n_words': 127}