<commit_before># -*- encoding: utf-8 -*-

from django import forms
from .models import Event
from Thirdauth.validations import validate_blank, default_error_messages

class CreateEventForm(forms.ModelForm):
    class Meta:
        model = Event
        exclude = ['user','slug']
        widgets = {
        	'name': forms.TextInput(
        		attrs = {
        			'class': 'clasechida'
        		}
    		),
            'description': forms.Textarea(
            	attrs = {
            		'cols': 40, 
            		'rows': 10,
        		}
    		),
    		'date': forms.TextInput(
    			attrs = {
    				'type' : 'date',
    			}
			)
        }
    def __init__(self, *args, **kwargs):
	    super(CreateEventForm, self).__init__(*args, **kwargs)
	    for field in self.fields:
	        self.fields[field].error_messages.update(default_error_messages)
	        self.fields[field].validators=[validate_blank]
	        self.fields[field].required=True

    def val_00(self, data):
        if data == '00':
            return '24'
        else:
            return '00'

    def clean_finish_time(self):
        start_time  = self.cleaned_data.get('start_time')
    	finish_time = self.cleaned_data.get('finish_time')

        ini = str(start_time).split(':')
        fin = str(finish_time).split(':')

        ini[0] = self.val_00(ini[0])
        fin[0] = self.val_00(fin[0])

        print ini[0]
        print fin[0]


        return start_time and finish_time<commit_msg>Completed validation of the duration of an event<commit_after># -*- encoding: utf-8 -*-

from django import forms
from .models import Event
from Thirdauth.validations import validate_blank, default_error_messages

class CreateEventForm(forms.ModelForm):
    class Meta:
        model = Event
        exclude = ['user','slug']
        widgets = {
        	'name': forms.TextInput(
        		attrs = {
        			'class': 'clasechida'
        		}
    		),
            'description': forms.Textarea(
            	attrs = {
            		'cols': 40, 
            		'rows': 10,
        		}
    		),
    		'date': forms.TextInput(
    			attrs = {
    				'type' : 'date',
    			}
			)
        }
    def __init__(self, *args, **kwargs):
	    super(CreateEventForm, self).__init__(*args, **kwargs)
	    for field in self.fields:
	        self.fields[field].error_messages.update(default_error_messages)
	        self.fields[field].validators=[validate_blank]
	        self.fields[field].required=True

    def eval_00(self, data):
        if data == '00':
            return '24'
        else:
            return data

    def clean_finish_time(self):
        start_time  = self.cleaned_data.get('start_time')
    	finish_time = self.cleaned_data.get('finish_time')

        if start_time is not None:
            ini = str(start_time).split(':')
            fin = str(finish_time).split(':')

            ini[0] = self.eval_00(ini[0])
            fin[0] = self.eval_00(fin[0])

            min_fin = (int(fin[0])*60) + int(fin[1])
            min_ini = (int(ini[0])*60) + int(ini[1])

            if abs(min_fin - min_ini) < 30:
                raise forms.ValidationError('El evento no puede ser tan corto')     
        
        return start_time and finish_time
{'fraction_non_alphanumeric': 0.12608426270136308, 'fraction_numerical': 0.0161090458488228, 'mean_word_length': 1.9461678832116789, 'pattern_counts': {'":': 0, '<': 4, '<?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': '4575875', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1024, 'n_words': 203}