<commit_before>from django import forms
from django.urls import reverse

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Div, Layout, Field, Reset, Submit

from cognitive.apps.atlas.query import Assertion, Disorder, Task, Battery, ConceptClass, Concept

class TaskForm(forms.Form):
    term_name = forms.CharField(required=True)
    definition_text = forms.CharField(required=True)

class ConceptForm(forms.Form):
    name = forms.CharField(required=True, label="Term:")
    definition_text = forms.CharField(required=True, widget=forms.Textarea(),
                                      label="Your Definition:")
    concept_class = ConceptClass()
    choices = [(x['id'], "-yes- " + str(x['name'])) for x in concept_class.all()]
    choices.insert(0, (None, "-no-"))
    cc_label = "In your opinion, does this concept belong to a larger class of concepts?"
    concept_class = forms.ChoiceField(choices=choices, label=cc_label, required=False)
    def __init__(self, concept_id, *args, **kwargs):
        if not args[0].get('submit'):
            concept = Concept()
            con_class = concept.get_relation(concept_id, "CLASSIFIEDUNDER",
                                             label="concept_class")
            if con_class:
                args[0]['concept_class'] = con_class[0]['id']
        super(ConceptForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.add_input(Submit('submit', 'Submit'))
        self.helper.add_input(Reset('concept-cancel', 'Cancel', type="button"))
        self.helper.form_action = reverse('update_concept', kwargs={'uid': concept_id,})
        self.helper.layout = Layout(
            Div(
                Field('name'),
                Field('definition_text'),
                Field('concept_class'),
                css_class="formline"
            )
        )

class ContrastForm(forms.Form):
    name = forms.CharField(required=True)

class ConditionForm(forms.Form):
    condition_text = forms.CharField(required=True)
    condition_description = forms.CharField(required=True)

class ImplementationForm(forms.Form):
    implementation_uri = forms.URLField(required=True)
    implementation_name = forms.CharField(required=True)
    implementation_description = forms.CharField(required=True)

    def __init__(self, *args, **kwargs):
        super(ImplementationForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.add_input(Submit('submit', 'Submit'))
        self.helper.add_input(Reset('implementation-cancel', 'Cancel'))<commit_msg>add form for creating/updating concept classes<commit_after>from django import forms
from django.urls import reverse

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Div, Layout, Field, Reset, Submit

from cognitive.apps.atlas.query import Assertion, Disorder, Task, Battery, ConceptClass, Concept

class TaskForm(forms.Form):
    term_name = forms.CharField(required=True)
    definition_text = forms.CharField(required=True)

class ConceptForm(forms.Form):
    name = forms.CharField(required=True, label="Term:")
    definition_text = forms.CharField(required=True, widget=forms.Textarea(),
                                      label="Your Definition:")
    concept_class = ConceptClass()
    choices = [(x['id'], "-yes- " + str(x['name'])) for x in concept_class.all()]
    choices.insert(0, (None, "-no-"))
    cc_label = "In your opinion, does this concept belong to a larger class of concepts?"
    concept_class = forms.ChoiceField(choices=choices, label=cc_label, required=False)
    def __init__(self, concept_id, *args, **kwargs):
        if not args[0].get('submit'):
            concept = Concept()
            con_class = concept.get_relation(concept_id, "CLASSIFIEDUNDER",
                                             label="concept_class")
            if con_class:
                args[0]['concept_class'] = con_class[0]['id']
        super(ConceptForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.add_input(Submit('submit', 'Submit'))
        self.helper.add_input(Reset('concept-cancel', 'Cancel', type="button"))
        self.helper.form_action = reverse('update_concept', kwargs={'uid': concept_id,})
        self.helper.layout = Layout(
            Div(
                Field('name'),
                Field('definition_text'),
                Field('concept_class'),
                css_class="formline"
            )
        )

class ConceptClassForm(forms.Form):
    name = forms.CharField(required=True, label="Category Name:)
    description = forms.CharField(required=True, widget=forms.Textarea(),
                                  label="Your Definition:")

    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.add_input(Submit('submit', 'Submit'))
        self.helper.add_input(Reset('cancel', 'Cancel', type="button"))
        self.helper.form_action = reverse('add_concept_class')

class ContrastForm(forms.Form):
    name = forms.CharField(required=True)

class ConditionForm(forms.Form):
    condition_text = forms.CharField(required=True)
    condition_description = forms.CharField(required=True)

class ImplementationForm(forms.Form):
    implementation_uri = forms.URLField(required=True)
    implementation_name = forms.CharField(required=True)
    implementation_description = forms.CharField(required=True)

    def __init__(self, *args, **kwargs):
        super(ImplementationForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.add_input(Submit('submit', 'Submit'))
        self.helper.add_input(Reset('implementation-cancel', 'Cancel'))
{'fraction_non_alphanumeric': 0.12614165087023954, 'fraction_numerical': 0.0013785972772703773, 'mean_word_length': 3.205797101449275, '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': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7531148', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1592, 'n_words': 324}