# Path: poweredsites/forms/base.py
# class BaseForm(formencode.Schema):
#     allow_extra_fields = True
#     filter_extra_fields = True
# 
#     _xsrf = validators.PlainText(not_empty=True, max=32)
# 
#     def __init__(self, handler):
# 
#         self._parmas = {}
#         self._values = {}
#         self._form_errors = {}
#         arguments = {}
# 
#         # re-parse qs, keep_blank_values for formencode to validate
#         # so formencode not_empty setting work.
#         request = handler.request
#         content_type = request.headers.get("Content-Type", "")
# 
#         if request.method == "POST":
#             if content_type.startswith("application/x-www-form-urlencoded"):
#                 arguments = urlparse.parse_qs(request.body, keep_blank_values=1)
# 
#         for k, v in arguments.iteritems():
#             if len(v) == 1:
#                 self._parmas[k] = v[0]
#             else:
#                 # keep a list of values as list (or set)
#                 self._parmas[k] = v
# 
#         self._handler = handler
#         self._result = True
# 
#     def validate(self):
#         try:
#             self._values = self.to_python(self._parmas)
#             self._result = True
#             self.__after__()
#         except formencode.Invalid, error:
#             self._values = error.value
#             self._form_errors = error.error_dict or {}
#             self._result = False
# 
#         return self._result
# 
#     # add custom error msg
#     def add_error(self, attr, msg):
#         self._result = False
#         self._form_errors[attr] = msg
# 
#     def render(self, template_name, **kwargs):
#         html = self._handler.render_string(template_name, **kwargs)
#         if not self._result:
#             html = htmlfill.render(
#                                    html,
#                                    defaults=self._values,
#                                    errors=self._form_errors,
#                                    encoding="utf8",
#             )
#         self._handler.finish(html)
# 
#     # post process hook
#     def __after__(self):
#         pass
# 
# class URL(validators.URL):
#     url_re = re.compile(r'''
#         ^(http|https)://
#         (?:[%:\w]*@)?                           # authenticator
#         (?P<domain>[a-z0-9][a-z0-9\-]{0,62}\.)* # (sub)domain - alpha followed by 62max chars (63 total)
#         (?P<tld>[a-z]{2,})                      # TLD
#         (?::[0-9]+)?                            # port
# 
#         # files/delims/etc
#         (?P<path>/[a-z0-9\-\._~:/\?#\[\]@!%\$&\'\(\)\*\+,;=]*)?
#         $
#     ''', re.I | re.VERBOSE)
# 
# Path: poweredsites/libs/const.py
# class Status(object):
# class Role(object):
# class OpenID(object):
# class Category(object):
#     LOCK = -2
#     SPAM = -1
#     INIT = 0
#     PENDING = 1
#     UNVERIFIED = 2
#     ACTIVE = 9
#     NORMAL = 0
#     STAFF = 5
#     ADMIN = 9
#     GOOGLE = 1
#     FACEBOOK = 2
#     TWITTER = 3
#     FRIENDFEED = 4
#     NAME = {GOOGLE:"Google", FACEBOOK:"Facebook",
#             TWITTER:"Twitter", FRIENDFEED:"Friendfeed"}
#     TOOLKIT = 1
#     HOSTING = 2
#     SERVER = 3
#     DATABASE = 4
#     FRAMEWORK = 5
#     FRONTEND = 6
#     LANGUAGE = 7


import re
import unicodedata
import uuid
import logging
import markdown
from formencode import validators
from tornado import escape
from poweredsites.forms.base import BaseForm, URL
from poweredsites.libs import const

# Copyright(c) 2010 poweredsites.org
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.



_domain_prefix_re = re.compile("(http://www\.|http://)")

class ProjectPreForm(BaseForm):
    website = URL(not_empty=True, max=600, add_http=True)


class ProjectForm(BaseForm):
    subdomain = validators.PlainText(not_empty=True, strip=True)
    name = validators.String(not_empty=True, min=3, max=30, strip=True)
    category = validators.Int(not_empty=True)

    keywords = validators.String(not_empty=False, max=100)
    desc = validators.String(not_empty=False, max=600)
    website = URL(not_empty=False, max=600, add_http=True)

# Path: poweredsites/forms/base.py
# class BaseForm(formencode.Schema):
#     allow_extra_fields = True
#     filter_extra_fields = True
# 
#     _xsrf = validators.PlainText(not_empty=True, max=32)
# 
#     def __init__(self, handler):
# 
#         self._parmas = {}
#         self._values = {}
#         self._form_errors = {}
#         arguments = {}
# 
#         # re-parse qs, keep_blank_values for formencode to validate
#         # so formencode not_empty setting work.
#         request = handler.request
#         content_type = request.headers.get("Content-Type", "")
# 
#         if request.method == "POST":
#             if content_type.startswith("application/x-www-form-urlencoded"):
#                 arguments = urlparse.parse_qs(request.body, keep_blank_values=1)
# 
#         for k, v in arguments.iteritems():
#             if len(v) == 1:
#                 self._parmas[k] = v[0]
#             else:
#                 # keep a list of values as list (or set)
#                 self._parmas[k] = v
# 
#         self._handler = handler
#         self._result = True
# 
#     def validate(self):
#         try:
#             self._values = self.to_python(self._parmas)
#             self._result = True
#             self.__after__()
#         except formencode.Invalid, error:
#             self._values = error.value
#             self._form_errors = error.error_dict or {}
#             self._result = False
# 
#         return self._result
# 
#     # add custom error msg
#     def add_error(self, attr, msg):
#         self._result = False
#         self._form_errors[attr] = msg
# 
#     def render(self, template_name, **kwargs):
#         html = self._handler.render_string(template_name, **kwargs)
#         if not self._result:
#             html = htmlfill.render(
#                                    html,
#                                    defaults=self._values,
#                                    errors=self._form_errors,
#                                    encoding="utf8",
#             )
#         self._handler.finish(html)
# 
#     # post process hook
#     def __after__(self):
#         pass
# 
# class URL(validators.URL):
#     url_re = re.compile(r'''
#         ^(http|https)://
#         (?:[%:\w]*@)?                           # authenticator
#         (?P<domain>[a-z0-9][a-z0-9\-]{0,62}\.)* # (sub)domain - alpha followed by 62max chars (63 total)
#         (?P<tld>[a-z]{2,})                      # TLD
#         (?::[0-9]+)?                            # port
# 
#         # files/delims/etc
#         (?P<path>/[a-z0-9\-\._~:/\?#\[\]@!%\$&\'\(\)\*\+,;=]*)?
#         $
#     ''', re.I | re.VERBOSE)
# 
# Path: poweredsites/libs/const.py
# class Status(object):
# class Role(object):
# class OpenID(object):
# class Category(object):
#     LOCK = -2
#     SPAM = -1
#     INIT = 0
#     PENDING = 1
#     UNVERIFIED = 2
#     ACTIVE = 9
#     NORMAL = 0
#     STAFF = 5
#     ADMIN = 9
#     GOOGLE = 1
#     FACEBOOK = 2
#     TWITTER = 3
#     FRIENDFEED = 4
#     NAME = {GOOGLE:"Google", FACEBOOK:"Facebook",
#             TWITTER:"Twitter", FRIENDFEED:"Friendfeed"}
#     TOOLKIT = 1
#     HOSTING = 2
#     SERVER = 3
#     DATABASE = 4
#     FRAMEWORK = 5
#     FRONTEND = 6
#     LANGUAGE = 7


# Path: poweredsites/forms/submit.py
import re
import unicodedata
import uuid
import logging
import markdown
from formencode import validators
from tornado import escape
from poweredsites.forms.base import BaseForm, URL
from poweredsites.libs import const

# Copyright(c) 2010 poweredsites.org
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.



_domain_prefix_re = re.compile("(http://www\.|http://)")

class ProjectPreForm(BaseForm):
    website = URL(not_empty=True, max=600, add_http=True)


class ProjectForm(BaseForm):
    subdomain = validators.PlainText(not_empty=True, strip=True)
    name = validators.String(not_empty=True, min=3, max=30, strip=True)
    category = validators.Int(not_empty=True)

    keywords = validators.String(not_empty=False, max=100)
    desc = validators.String(not_empty=False, max=600)
    website = URL(not_empty=False, max=600, add_http=True)

    logo = URL(not_empty=False, max=600, add_http=True)
