<commit_before>"""Forms for games."""
from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, HTML, Submit, Button, Fieldset
from django import forms
from django.forms import Textarea, CheckboxSelectMultiple
from core.models import Game
from core.models import MyFile


class GameForm(forms.ModelForm):
    """Form for game creation and editing."""
    my_game_file = forms.FileField(required=False)
    game_version = forms.IntegerField(min_value=1, required=False)

    class Meta:
        model = Game
        exclude = ['owner', 'date_published']
        widgets = {
            'description': Textarea(attrs={'cols': 100, 'rows': 15}),
            'tags': CheckboxSelectMultiple(),
        }

    def __init__(self, *args, **kwargs):
        """Setup the form to work with crispy_forms."""
        super(GameForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_id = 'game-form'
        self.helper.layout = Layout(
            Fieldset(
                '{{ heading }}',
                'name',
                'description',
                HTML("""{% if form.image.value %}<img class="img-responsive" src="{{ MEDIA_URL }}{{ form.image.value }}">
                {% endif %}"""),
                'image',
                'tags',
                'group',
                'event_name',
                'game_version',
                'my_game_file'
            ),
            FormActions(
                Submit('submit', 'Submit'),
                Button('cancel', 'Cancel', onclick='history.go(-1);', css_class="btn-default")
            )
        )

    def save(self, commit=True):
        game = super(GameForm, self).save(commit=False)
        game.save()
        my_file = self.cleaned_data['my_game_file']
        if my_file:
            my_file = MyFile(name=self.cleaned_data['game_version'], game_file=my_file)
            my_file.save()
            game.game_file.add(my_file)
        return game

    def clean_game_version(self):
        version = self.cleaned_data.get('game_version')<commit_msg>Save tags when saving game.<commit_after>"""Forms for games."""
from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, HTML, Submit, Button, Fieldset
from django import forms
from django.forms import Textarea, CheckboxSelectMultiple
from core.models import Game
from core.models import MyFile


class GameForm(forms.ModelForm):
    """Form for game creation and editing."""
    my_game_file = forms.FileField(required=False)
    game_version = forms.IntegerField(min_value=1, required=False)

    class Meta:
        model = Game
        exclude = ['owner', 'date_published']
        widgets = {
            'description': Textarea(attrs={'cols': 100, 'rows': 15}),
            'tags': CheckboxSelectMultiple(),
        }

    def __init__(self, *args, **kwargs):
        """Setup the form to work with crispy_forms."""
        super(GameForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_id = 'game-form'
        self.helper.layout = Layout(
            Fieldset(
                '{{ heading }}',
                'name',
                'description',
                HTML("""{% if form.image.value %}<img class="img-responsive" src="{{ MEDIA_URL }}{{ form.image.value }}">
                {% endif %}"""),
                'image',
                'tags',
                'group',
                'event_name',
                'game_version',
                'my_game_file'
            ),
            FormActions(
                Submit('submit', 'Submit'),
                Button('cancel', 'Cancel', onclick='history.go(-1);', css_class="btn-default")
            )
        )

    def save(self, commit=True):
        game = super(GameForm, self).save(commit=False)
        game.save()
        my_file = self.cleaned_data['my_game_file']
        if my_file:
            my_file = MyFile(name=self.cleaned_data['game_version'], game_file=my_file)
            my_file.save()
            game.game_file.add(my_file)

        # Save our tags
        self.save_m2m()
        return game

    def clean_game_version(self):
        version = self.cleaned_data.get('game_version')
{'fraction_non_alphanumeric': 0.1265851971408808, 'fraction_numerical': 0.0034586119437399125, 'mean_word_length': 2.178021978021978, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '724104', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1196, 'n_words': 271}