Permalink
Browse files

- Splitted main.py into several files

- Done pages for unit 3
  • Loading branch information...
1 parent 00d07a5 commit b66c63c1d52e799284802966a409f3d01ceaef04 @daniloz committed May 1, 2012
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>webapp</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.python.pydev.PyDevBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.python.pydev.pythonNature</nature>
+ </natures>
+</projectDescription>
View
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?eclipse-pydev version="1.0"?>
+
+<pydev_project>
+<pydev_variables_property name="org.python.pydev.PROJECT_VARIABLE_SUBSTITUTION">
+<key>GOOGLE_APP_ENGINE</key>
+<value>C:\Program Files (x86)\Google\google_appengine</value>
+</pydev_variables_property>
+<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
+<path>/webapp</path>
+</pydev_pathproperty>
+<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
+<path>${GOOGLE_APP_ENGINE}</path>
+<path>${GOOGLE_APP_ENGINE}/lib/antlr3</path>
+<path>${GOOGLE_APP_ENGINE}/lib/django_1_3</path>
+<path>${GOOGLE_APP_ENGINE}/lib/enum</path>
+<path>${GOOGLE_APP_ENGINE}/lib/fancy_urllib</path>
+<path>${GOOGLE_APP_ENGINE}/lib/google-api-python-client</path>
+<path>${GOOGLE_APP_ENGINE}/lib/graphy</path>
+<path>${GOOGLE_APP_ENGINE}/lib/grizzled</path>
+<path>${GOOGLE_APP_ENGINE}/lib/httplib2</path>
+<path>${GOOGLE_APP_ENGINE}/lib/ipaddr</path>
+<path>${GOOGLE_APP_ENGINE}/lib/jinja2</path>
+<path>${GOOGLE_APP_ENGINE}/lib/markupsafe</path>
+<path>${GOOGLE_APP_ENGINE}/lib/oauth2</path>
+<path>${GOOGLE_APP_ENGINE}/lib/prettytable</path>
+<path>${GOOGLE_APP_ENGINE}/lib/protorpc</path>
+<path>${GOOGLE_APP_ENGINE}/lib/python-gflags/tests</path>
+<path>${GOOGLE_APP_ENGINE}/lib/simplejson</path>
+<path>${GOOGLE_APP_ENGINE}/lib/sqlcmd</path>
+<path>${GOOGLE_APP_ENGINE}/lib/webapp2</path>
+<path>${GOOGLE_APP_ENGINE}/lib/webob_1_1_1</path>
+<path>${GOOGLE_APP_ENGINE}/lib/yaml/lib</path>
+</pydev_pathproperty>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
+</pydev_project>
View
@@ -9,8 +9,12 @@ handlers:
static_files: favicon.ico
upload: favicon\.ico
+- url: /static
+ static_dir: static
+
- url: .*
script: main.app
+
libraries:
- name: webapp2
View
@@ -0,0 +1,23 @@
+import os
+import webapp2
+import jinja2
+
+template_dir = os.path.join(os.path.dirname(__file__), 'templates')
+jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = True)
+
+
+class BaseHandler(webapp2.RequestHandler):
+ def __init__(self, request, response):
+ self.initialize(request, response)
+
+ def write(self, *a, **kw):
+ self.response.out.write(*a, **kw)
+
+ def render_str(self, template, **params):
+ t = jinja_env.get_template(template)
+ return t.render(params)
+
+ def render(self, template, **kw):
+ self.write(self.render_str(template, **kw))
+
+
View
@@ -0,0 +1,7 @@
+from base_handler import BaseHandler
+
+links = dict(homeworks = [])
+
+class RootPage(BaseHandler):
+ def get(self):
+ self.render('index.html', **links)
View
@@ -0,0 +1,74 @@
+import re
+from base_handler import BaseHandler
+import handlers_root
+
+handlers_root.links['homeworks'].append(dict(href = "/unit2/rot13", caption = "Unit2: ROT13"))
+handlers_root.links['homeworks'].append(dict(href = "/unit2/signup", caption = "Unit2: SignUp"))
+
+class Rot13Page(BaseHandler):
+ def get(self):
+ self.render('u2-rot13-form.html')
+
+ def post(self):
+ user_text = self.request.get('text')
+ text_rot13ed = user_text.encode('rot13')
+ params = dict(usertext = text_rot13ed);
+ self.render('u2-rot13-form.html', **params)
+
+
+USER_RE = re.compile(r"^[a-zA-Z0-9_-]{3,20}$")
+def validate_username(username):
+ return username and USER_RE.match(username)
+
+PASS_RE = re.compile(r"^.{3,20}$")
+def validate_password(password):
+ return password and PASS_RE.match(password)
+
+EMAIL_RE = re.compile(r"^[\S]+@[\S]+\.[\S]+$")
+def validate_email(email):
+ return not email or EMAIL_RE.match(email)
+
+
+class SignUpPage(BaseHandler):
+ def get(self):
+ self.render('u2-signup-form.html')
+
+ def post(self):
+ username = self.request.get('username')
+ password = self.request.get('password')
+ verify = self.request.get('verify')
+ email = self.request.get('email')
+
+ params = dict(username = username,
+ email = email)
+
+ has_error = False
+
+ if not validate_username(username):
+ params['username_error'] = "That's not a valid username."
+ has_error = True
+
+ if not validate_password(password):
+ params['password_error'] = "That wasn't a valid password."
+ has_error = True
+ elif password != verify:
+ params['verify_error'] = "Your passwords didn't match."
+ has_error = True
+
+ if not validate_email(email):
+ params['email_error'] = "That's not a valid email."
+ has_error = True
+
+ if has_error:
+ self.render('u2-signup-form.html', **params)
+ else:
+ self.redirect('/unit2/signup/welcome?username=' + username)
+
+class SignUpWelcomePage(BaseHandler):
+ def get(self):
+ username = self.request.get('username')
+ if validate_username(username):
+ self.render('u2-signup-welcome.html', username = username)
+ else:
+ self.redirect('/unit2/signup')
+
View
@@ -0,0 +1,14 @@
+from base_handler import BaseHandler
+import handlers_root
+
+handlers_root.links['homeworks'].append(dict(href = "/unit3/blog", caption = "Unit3: Blog"))
+handlers_root.links['homeworks'].append(dict(href = "/unit3/blog/newpost", caption = "Unit3: Blog NewPost"))
+
+class BlogPage(BaseHandler):
+ def get(self):
+ self.render('u3-blog-blog.html')
+
+
+class NewPost(BaseHandler):
+ def get(self):
+ self.render('u3-blog-newpost.html')
View
@@ -14,113 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-import os
-import re
import webapp2
-import logging
-import jinja2
-
from google.appengine.ext import db
-template_dir = os.path.join(os.path.dirname(__file__), 'templates')
-jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = True)
-
-
-class BaseHandler(webapp2.RequestHandler):
- def __init__(self, request, response):
- self.initialize(request, response)
-
- def write(self, *a, **kw):
- self.response.out.write(*a, **kw)
-
- def render_str(self, template, **params):
- t = jinja_env.get_template(template)
- return t.render(params)
-
- def render(self, template, **kw):
- self.write(self.render_str(template, **kw))
-
-
-
-class Rot13Page(BaseHandler):
- def get(self):
- self.render('u2-rot13-form.html')
-
- def post(self):
- user_text = self.request.get('text')
- text_rot13ed = user_text.encode('rot13')
- params = dict(usertext = text_rot13ed);
- self.render('u2-rot13-form.html', **params)
-
-
-USER_RE = re.compile(r"^[a-zA-Z0-9_-]{3,20}$")
-def validate_username(username):
- return username and USER_RE.match(username)
-
-PASS_RE = re.compile(r"^.{3,20}$")
-def validate_password(password):
- return password and PASS_RE.match(password)
-
-EMAIL_RE = re.compile(r"^[\S]+@[\S]+\.[\S]+$")
-def validate_email(email):
- return not email or EMAIL_RE.match(email)
-
-
-class SignUpPage(BaseHandler):
- def get(self):
- self.render('u2-signup-form.html')
-
- def post(self):
- username = self.request.get('username')
- password = self.request.get('password')
- verify = self.request.get('verify')
- email = self.request.get('email')
-
- params = dict(username = username,
- email = email)
-
- has_error = False
-
- if not validate_username(username):
- params['username_error'] = "That's not a valid username."
- has_error = True
-
- if not validate_password(password):
- params['password_error'] = "That wasn't a valid password."
- has_error = True
- elif password != verify:
- params['verify_error'] = "Your passwords didn't match."
- has_error = True
-
- if not validate_email(email):
- params['email_error'] = "That's not a valid email."
- has_error = True
-
- if has_error:
- self.render('u2-signup-form.html', **params)
- else:
- self.redirect('/unit2/signup/welcome?username=' + username)
-
-class SignUpWelcomePage(BaseHandler):
- def get(self):
- username = self.request.get('username')
- if validate_username(username):
- self.render('u2-signup-welcome.html', username = username)
- else:
- self.redirect('/unit2/signup')
-
-class RootPage(BaseHandler):
- def get(self):
- self.render('index.html', **links)
+import urls
-links = dict(homeworks = [])
-links['homeworks'].append(dict(href="/unit2/rot13",caption="Unit2: ROT13"))
-links['homeworks'].append(dict(href="/unit2/signup",caption="Unit2: SignUp"))
-
-app = webapp2.WSGIApplication([('/',RootPage),
- ('/unit2/rot13',Rot13Page),
- ('/unit2/signup',SignUpPage),
- #('/unit2/rot13',Rot13Page(None,None, dict(href="/unit2/rot13",caption="Unit2: ROT13"))),
- #('/unit2/signup',SignUpPage(None,None, dict(href="/unit2/signup",caption="Unit2: SignUp"))),
- ('/unit2/signup/welcome',SignUpWelcomePage)],
- debug=True)
+app = webapp2.WSGIApplication(urls.SITE_URLS, debug = True)
View
@@ -0,0 +1,83 @@
+body {
+ position: relative;
+ font-family: Helvetica, Arial, sans-serif;
+ font-size: 14px;
+
+ width: 800px;
+ margin: 0 auto;
+ padding: 10px;
+ color: #333;
+}
+
+h2 {
+ font-size: 24px;
+ font-weight: bold;
+ margin-bottom: 20px;
+}
+
+.error {
+ color: red;
+}
+
+label {
+ display: block;
+ font-size: 20px;
+}
+
+label + label {
+ margin-top: 20px;
+}
+
+input[type=text] {
+ width: 500px;
+ font-size: 20px;
+ padding: 2px;
+ font-family: monospace;
+}
+
+textarea {
+ width: 500px;
+ height: 400px;
+ font-size: 17px;
+ font-family: monospace;
+}
+
+input[type=submit] {
+ font-size: 24px;
+}
+
+.main-title {
+ display: block;
+ color: #222;
+ font-size: 40px;
+ font-weight: bold;
+ text-align: center;
+ margin-bottom: 30px;
+ text-decoration: none;
+}
+
+.post + .post {
+ margin-top: 15px;
+}
+
+.post-heading {
+ position: relative;
+ border-bottom: 3px solid #666;
+}
+
+.post-title {
+ font-size: 24px;
+ font-weight: bold;
+}
+
+.post-date {
+ position: absolute;
+ right: 0px;
+ bottom: 0px;
+ color: #999;
+
+}
+
+.post-content {
+ margin-top: 5px;
+}
Oops, something went wrong.

0 comments on commit b66c63c

Please sign in to comment.