<commit_before>from django.core.urlresolvers import reverse_lazy
from django.views.generic.edit import UpdateView

from common.mixins import PrivateMixin
from common.utils import app_from_label
from data_import.views import BaseDataRetrievalView
from .models import DataFile, UserData


class DataRetrievalView(BaseDataRetrievalView):
    """
    Initiate 23andMe data retrieval task.
    """
    datafile_model = DataFile


class UploadView(PrivateMixin, UpdateView, DataRetrievalView):
    """
    Allow the user to upload a 23andMe file.
    """
    model = UserData
    fields = ['genome_file']
    template_name = 'twenty_three_and_me/upload.html'
    success_url = reverse_lazy('my-member-research-data')

    def get_context_data(self, **kwargs):
        context = super(UploadView, self).get_context_data(**kwargs)

        context.update({
            'app': app_from_label('twenty_three_and_me'),
        })

        return context

    def form_valid(self, form):
        """
        Save updated model, then trigger retrieval task and redirect.
        """
        response = super(UploadView, self).form_valid(form)

        self.trigger_retrieval_task(self.request)

        return response

    def get_object(self, queryset=None):
        return UserData.objects.get(user=self.request.user.pk)<commit_msg>🔧 WIP for 23andMe direct S3 upload<commit_after>from time import time

from django.core.urlresolvers import reverse_lazy

from s3upload.views import DropzoneS3UploadFormView

from common.mixins import PrivateMixin
from common.utils import app_from_label
from data_import.views import BaseDataRetrievalView

from .models import DataFile, UserData


class DataRetrievalView(BaseDataRetrievalView):
    """
    Initiate 23andMe data retrieval task.
    """
    datafile_model = DataFile


class UploadView(PrivateMixin, DropzoneS3UploadFormView, DataRetrievalView):
    """
    Allow the user to upload a 23andMe file.
    """
    model = UserData
    fields = ['genome_file']
    template_name = 'twenty_three_and_me/upload.html'
    success_url = reverse_lazy('my-member-research-data')

    def get_upload_to(self):
        return ('member/{}/uploaded-data/data-selfie/{}/'
                .format(self.request.user.id, int(time())))

    def get_upload_to_validator(self):
        return (r'^member/{}/uploaded-data/data-selfie/\d+/'
                .format(self.request.user.id))

    def get_context_data(self, **kwargs):
        context = super(UploadView, self).get_context_data(**kwargs)

        context.update({
            'app': app_from_label('twenty_three_and_me'),
        })

        return context

    def form_valid(self, form):
        """
        Save updated model, then trigger retrieval task and redirect.
        """
        user_data = self.get_object()

        user_data.genome_file = form.cleaned_data.get('key_name')
        user_data.save()

        self.trigger_retrieval_task(self.request)

        return super(UploadView, self).form_valid(form)

    def get_object(self, queryset=None):
        return UserData.objects.get(user=self.request.user.pk)
{'fraction_non_alphanumeric': 0.09829197550757332, 'fraction_numerical': 0.0045117628101836935, 'mean_word_length': 3.299168975069252, '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': '1199312', 'n_tokens_mistral': 973, 'n_tokens_neox': 926, 'n_words': 199}