# Path: vpw/models.py
# class Material(models.Model):
#     material_id = CharField(max_length=64, blank=True, default="")
#     material_type = IntegerField(default=1)
#     text = TextField(blank=True, default='')
#     version = IntegerField(null=True, blank=True, default=0)
#     title = CharField(max_length=255, verbose_name=_("Title"))
#     description = TextField(blank=True)
#     categories = CharField(max_length=256, blank=True, verbose_name=_("Categories"))
#     keywords = TextField(blank=True, default="")
#     language = CharField(max_length=2, blank=True, default="vi", verbose_name=_("Language"))
#     license_id = IntegerField(null=True, default=1)
#     modified = DateTimeField(auto_now=True, blank=True)
#     derived_from = CharField(max_length=64, blank=True)
#     creator = models.ForeignKey(User)
#     status = IntegerField(null=True, default=1)
#     author = CharField(max_length=100, blank=True, default="")
#     editor = CharField(max_length=100, blank=True, default="")
#     licensor = CharField(max_length=100, blank=True, default="")
#     maintainer = CharField(max_length=100, blank=True, default="")
#     translator = CharField(max_length=100, blank=True, default="")
#     coeditor = CharField(max_length=100, blank=True, default="")
# 
#     def to_dict(self):
#         material = dict()
#         material['id'] = self.id
#         material['material_id'] = self.material_id
#         material['material_type'] = int(self.material_type)
#         material['text'] = self.text
#         material['version'] = self.version
#         material['title'] = self.title
#         material['description'] = self.description
#         material['categories'] = self.categories
#         material['status'] = self.status
#         material['modified'] = self.modified
# 
#         if self.author:
#             material['author'] = self.author
# 
#         return material


import requests
from django import forms
from django.core.exceptions import ValidationError
from django.forms.models import ModelForm
from registration.forms import RegistrationForm
from tinymce.widgets import TinyMCE
from django.utils.translation import ugettext as _
from django.conf import settings
from vpw.models import Material
        fields = ['title', 'description', 'categories', 'keywords', 'language', 'derived_from',
                  'author', 'editor', 'licensor', 'maintainer', 'translator', 'coeditor', 'text']

    def clean_language(self):
        if self.cleaned_data.get('language', '00') == '00':
            raise ValidationError(_('Required'))
        return self.cleaned_data.get('language', '')

    def clean_version(self):
        if self.cleaned_data.get('version'):
            try:
                return int(self.cleaned_data['version'])
            except ValueError:
                raise ValidationError("Invalid number")
        return 0


class ModuleForm(MaterialForm):
    body = forms.CharField(widget=TinyMCE(attrs={'rows': 7}), required=False)

    def __init__(self, *args, **kwargs):
        super(ModuleForm, self).__init__(*args, **kwargs)
        if kwargs.get('instance'):
            self.fields['body'].initial = kwargs['instance'].text


class CollectionForm(MaterialForm):
    body = forms.CharField(required=False)



# Path: vpw/models.py
# class Material(models.Model):
#     material_id = CharField(max_length=64, blank=True, default="")
#     material_type = IntegerField(default=1)
#     text = TextField(blank=True, default='')
#     version = IntegerField(null=True, blank=True, default=0)
#     title = CharField(max_length=255, verbose_name=_("Title"))
#     description = TextField(blank=True)
#     categories = CharField(max_length=256, blank=True, verbose_name=_("Categories"))
#     keywords = TextField(blank=True, default="")
#     language = CharField(max_length=2, blank=True, default="vi", verbose_name=_("Language"))
#     license_id = IntegerField(null=True, default=1)
#     modified = DateTimeField(auto_now=True, blank=True)
#     derived_from = CharField(max_length=64, blank=True)
#     creator = models.ForeignKey(User)
#     status = IntegerField(null=True, default=1)
#     author = CharField(max_length=100, blank=True, default="")
#     editor = CharField(max_length=100, blank=True, default="")
#     licensor = CharField(max_length=100, blank=True, default="")
#     maintainer = CharField(max_length=100, blank=True, default="")
#     translator = CharField(max_length=100, blank=True, default="")
#     coeditor = CharField(max_length=100, blank=True, default="")
# 
#     def to_dict(self):
#         material = dict()
#         material['id'] = self.id
#         material['material_id'] = self.material_id
#         material['material_type'] = int(self.material_type)
#         material['text'] = self.text
#         material['version'] = self.version
#         material['title'] = self.title
#         material['description'] = self.description
#         material['categories'] = self.categories
#         material['status'] = self.status
#         material['modified'] = self.modified
# 
#         if self.author:
#             material['author'] = self.author
# 
#         return material


# Path: vpw/forms.py
import requests
from django import forms
from django.core.exceptions import ValidationError
from django.forms.models import ModelForm
from registration.forms import RegistrationForm
from tinymce.widgets import TinyMCE
from django.utils.translation import ugettext as _
from django.conf import settings
from vpw.models import Material

        fields = ['title', 'description', 'categories', 'keywords', 'language', 'derived_from',
                  'author', 'editor', 'licensor', 'maintainer', 'translator', 'coeditor', 'text']

    def clean_language(self):
        if self.cleaned_data.get('language', '00') == '00':
            raise ValidationError(_('Required'))
        return self.cleaned_data.get('language', '')

    def clean_version(self):
        if self.cleaned_data.get('version'):
            try:
                return int(self.cleaned_data['version'])
            except ValueError:
                raise ValidationError("Invalid number")
        return 0


class ModuleForm(MaterialForm):
    body = forms.CharField(widget=TinyMCE(attrs={'rows': 7}), required=False)

    def __init__(self, *args, **kwargs):
        super(ModuleForm, self).__init__(*args, **kwargs)
        if kwargs.get('instance'):
            self.fields['body'].initial = kwargs['instance'].text


class CollectionForm(MaterialForm):
    body = forms.CharField(required=False)



class EditProfileForm(forms.Form):