from django import forms
from rango.models import Page, Category

class CategoryForm (forms.ModelForm):
	name=forms.CharField(help_text="Please enter the category name.")
	views=forms.IntegerField(widget=forms.HiddenInput(), initial=0)
	likes=forms.IntegerField(widget=forms.HiddenInput(), initial=0)
	slug=forms.CharField(widget=forms.HiddenInput(), required=False)

	# An inline class to provide additional information on the form.

	class Meta:
	# Provide an association between the ModelForm and a model
		model=Category
		fields=('name',)

class PageForm (forms.ModelForm):
	title=forms.CharField(help_text="Please enter the title of the page.")
	url=forms.URLField(max_length=200,help_text="Please enter the URL of the page.")
	views=forms.IntegerField(widget=forms.HiddenInput(), initial=0)

	class Meta:
	# Provide an association between the ModelForm and a mod
		model=Page
		exclude=('category',)

	def clean(self):
		cleaned_data = self.cleaned_data
		url = cleaned_data.get('url')

		if url and not url.startswith('http://'):
			url = 'http://' + url
			cleaned_data['url'] = url

			return cleaned_data