def classify_index(request, token_str): token = get_object_or_404(Token, token=token_str) if request.method == 'POST': chosen_category_id = int(request.POST.get('category')) paper_id = request.POST.get('paper') paper = get_object_or_404(Paper, pk=paper_id) category = None sub_category = None if chosen_category_id != -1: category = get_object_or_404(Category, pk=chosen_category_id) classification = Classification(token=token, paper=paper, category=category, sub_category=sub_category) classification.save() classifications_done = Classification.objects.filter(token=token) done = classifications_done.count() paper_query = Paper.objects.exclude(pk__in=classifications_done.values("paper__pk")) left = paper_query.count() paper = None if left > 0: # idx = randint(0, left - 1) paper = paper_query.first() categories = Category.objects.all() return render(request, "classification/index.html", {'token': token, 'paper': paper, 'categories': categories, 'done': done, 'total': left + done})
def create_classification(request): """ Create a new classification with a label in the current language. """ parameters = request.data language = translation.get_language() if not Language.objects.filter(code=language).exists(): raise SuspiciousOperation(_("The language is not supported")) if Classification.objects.filter(name=parameters['name']).exists(): raise SuspiciousOperation(_("A classification already exists with this name")) classification = Classification() classification.name = parameters['name'] classification.set_label(language, parameters['label']) classification.description = parameters['description'] classification.save() response = { 'id': classification.pk, 'name': classification.name, 'can_modify': classification.can_modify, 'can_delete': classification.can_delete, 'label': classification.get_label(), 'description': classification.description, 'num_classification_ranks': 0 } return HttpResponseRest(request, response)
def __init__(self, vc: Classification): self.ref_length = vc.update_cached_c_hgvs() self.vc_id = vc.id self.chgvs = vc.get(SpecialEKeys.C_HGVS) vc.save()