# 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/utils.py
# def image_exists(site, path):
#     if site == '':
#         site = settings.SITE_URL
# 
#     url = site + path
#     try:
#         res = urllib.urlopen(url)
#         http_message = res.info()
#         mimetype = str(http_message.type)
#         maintype = http_message.maintype
# 
#         if res.getcode() == 200 and maintype == 'image' and mimetype.startswith('image'):
#             image_found = True
#         else:
#             image_found = False
#     except:
#         image_found = False
# 
#     return image_found
# 
# Path: vpw/vpr_api.py
# def vpr_materials_by_author(aid, page=1, sort_on=''):
#     result = vpr_request("GET", "materials?author=%s&page=%s&sort_on=%s" % (aid, str(page), sort_on))
#     return result
# 
# def vpr_get_favorite(pid, page=1):
#     result = vpr_request("GET", "persons/%s/favorites/?page=%s" % (pid, str(page)))
#     return result
# 
# def vpr_get_person(pid, is_count=False):
#     if not pid:
#         return None
#     if is_count:
#         result = vpr_request("GET", "persons/%s?count=1" % pid)
#     else:
#         result = vpr_request("GET", "persons/%s" % pid)
#     return result


from django import template
from django.core.urlresolvers import reverse
from django.db.models.query_utils import Q
from django.template.defaultfilters import stringfilter
from vpw.models import Material
from vpw.utils import image_exists
from vpw.vpr_api import vpr_materials_by_author, vpr_get_favorite, vpr_get_person
    from vpw.utils import normalize_string

register = template.Library()


@register.filter(is_safe=True)
@stringfilter

# 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/utils.py
# def image_exists(site, path):
#     if site == '':
#         site = settings.SITE_URL
# 
#     url = site + path
#     try:
#         res = urllib.urlopen(url)
#         http_message = res.info()
#         mimetype = str(http_message.type)
#         maintype = http_message.maintype
# 
#         if res.getcode() == 200 and maintype == 'image' and mimetype.startswith('image'):
#             image_found = True
#         else:
#             image_found = False
#     except:
#         image_found = False
# 
#     return image_found
# 
# Path: vpw/vpr_api.py
# def vpr_materials_by_author(aid, page=1, sort_on=''):
#     result = vpr_request("GET", "materials?author=%s&page=%s&sort_on=%s" % (aid, str(page), sort_on))
#     return result
# 
# def vpr_get_favorite(pid, page=1):
#     result = vpr_request("GET", "persons/%s/favorites/?page=%s" % (pid, str(page)))
#     return result
# 
# def vpr_get_person(pid, is_count=False):
#     if not pid:
#         return None
#     if is_count:
#         result = vpr_request("GET", "persons/%s?count=1" % pid)
#     else:
#         result = vpr_request("GET", "persons/%s" % pid)
#     return result


# Path: vpw/templatetags/vpw_filters.py
from django import template
from django.core.urlresolvers import reverse
from django.db.models.query_utils import Q
from django.template.defaultfilters import stringfilter
from vpw.models import Material
from vpw.utils import image_exists
from vpw.vpr_api import vpr_materials_by_author, vpr_get_favorite, vpr_get_person
    from vpw.utils import normalize_string


register = template.Library()


@register.filter(is_safe=True)
@stringfilter

def normalize_string(value):