<commit_before># Python
import simplejson

# Django
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404
from django.views.generic import base

# restframework
from rest_framework import generics
from rest_framework import permissions

# AstroBin apps
from astrobin.models import Image # TODO: model will be moved to astrobin_apps_images
from common.mixins import AjaxableResponseMixin

# This app
from astrobin_apps_platesolving.models import Solution
from astrobin_apps_platesolving.serializers import SolutionSerializer
from astrobin_apps_platesolving.solver import Solver


class SolveView(base.View):
    def post(self, request, *args, **kwargs):
        image = get_object_or_404(Image, pk = kwargs.pop('pk'))
        solution = image.solution

        if solution is None:
            solution = Solution()
            solution.save()

            image.solution = solution
            image.save()

        if solution.submission_id is None:
            solver = Solver()
            thumb = image.thumbnail_raw('regular', {'revision_label': 0})
            submission = solver.solve(thumb.file)
            solution.status = Solver.PENDING
            solution.submission_id = submission
            solution.save()

        context = {
            'solution': solution.id,
            'submission': solution.submission_id,
        }
        return HttpResponse(simplejson.dumps(context), mimetype='application/json')


class SolutionUpdateView(base.View):
    def post(self, request, *args, **kwargs):
        solution = get_object_or_404(Solution, pk = kwargs.pop('pk'))
        solver = Solver()
        status = solver.status(solution.submission_id)<commit_msg>Fix problem with invalid plate solving submissions.<commit_after># Python
import simplejson

# Django
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404
from django.views.generic import base

# restframework
from rest_framework import generics
from rest_framework import permissions

# AstroBin apps
from astrobin.models import Image # TODO: model will be moved to astrobin_apps_images
from common.mixins import AjaxableResponseMixin

# This app
from astrobin_apps_platesolving.models import Solution
from astrobin_apps_platesolving.serializers import SolutionSerializer
from astrobin_apps_platesolving.solver import Solver


class SolveView(base.View):
    def post(self, request, *args, **kwargs):
        image = get_object_or_404(Image, pk = kwargs.pop('pk'))
        solution = image.solution

        if solution is None:
            solution = Solution()
            solution.save()

            image.solution = solution
            image.save()

        if solution.submission_id is None:
            solver = Solver()
            thumb = image.thumbnail_raw('regular', {'revision_label': 0})
            submission = solver.solve(thumb.file)
            solution.status = Solver.PENDING
            solution.submission_id = submission
            solution.save()

        context = {
            'solution': solution.id,
            'submission': solution.submission_id,
        }
        return HttpResponse(simplejson.dumps(context), mimetype='application/json')


class SolutionUpdateView(base.View):
    def post(self, request, *args, **kwargs):
        solution = get_object_or_404(Solution, pk = kwargs.pop('pk'))
        solver = Solver()
        status = solver.status(solution.submission_id)

        if status == Solver.MISSING:
            solution.status = status
            solution.submission_id = None
            solution.save()
{'fraction_non_alphanumeric': 0.08141788978122404, 'fraction_numerical': 0.007200221545278316, 'mean_word_length': 3.0044345898004434, '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': '3215602', 'n_tokens_mistral': 1018, 'n_tokens_neox': 961, 'n_words': 255}