'''Copyright(C): Leaf Johnson 2011

    This file is part of makeclub.

    makeclub is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    makeclub is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with makeclub.  If not, see <http://www.gnu.org/licenses/>.

 
 
'''
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from errors import errorPage
from models import Club
from access import isAccessible
from url import cluburl
from helper import lastWordOfUrl
from access import hasClubPrivilige
from url import urlconf
import os

class ClubList(webapp.RequestHandler):
	def __init__(self,
			template=os.path.join(os.path.dirname(__file__), '../templates/default/clublist.html'), *args, **kw ):
		webapp.RequestHandler.__init__(self, *args, **kw)
		self.template = template

	def get(self, *args):
		if (isAccessible('', 'listclubs')):
			clubs = Club.all()
			vars = dict (clubs=Club.all(), cluburl=cluburl)
			self.response.out.write (template.render(self.template, vars) )
		else:
			errorPage("Not Accessible", users.create_login_url(self.request.uri), self.response)

from google.appengine.api import users
class ClubView(webapp.RequestHandler):
	def __init__(self, 
			template=os.path.join(os.path.dirname(__file__), '../templates/default/clubview.html'), *args, **kw ):
		webapp.RequestHandler.__init__(self, *args, **kw)
		self.template = template

	def get(self, *args):
		path = self.request.path
		slug = lastWordOfUrl(path)
		if (slug):
			club = Club.getClubBySlug(slug)
		if (club):
			templatevars = dict(club = club )
			user = users.get_current_user()
			if (user and hasClubPrivilige(user, club, 'join')): #Could Join
				templatevars['userName'] = user.nickname()
				templatevars['userEmail'] = user.email()
			else:
				templatevars['loginUrl'] = users.create_login_url(self.request.uri)
			self.response.out.write (template.render(self.template, templatevars) )
		else:
			self.response.set_status(404)
			errorPage("Club Not Found", urlconf.clubListPath(), self.response)
			


@@ -770,109 +770,30 @@
 rom 
-google.appengine.ext.webapp import template%0Afrom google.appengine.ext.webapp.util import run_wsgi_app
+template import render
 %0Afro
@@ -994,18 +994,8 @@
 conf
-%0Aimport os
 %0A%0Acl
@@ -1067,70 +1067,9 @@
 ate=
-os.path.join(os.path.dirname(__file__), '../templates/default/
+'
 club
@@ -1074,25 +1074,24 @@
 ublist.html'
-)
 , *args, **k
@@ -1333,33 +1333,24 @@
 .out.write (
-template.
 render(self.
@@ -1579,70 +1579,9 @@
 ate=
-os.path.join(os.path.dirname(__file__), '../templates/default/
+'
 club
@@ -1590,17 +1590,16 @@
 ew.html'
-)
 , *args,
@@ -2139,16 +2139,16 @@
 st.uri)%0A
+
 %09%09%09self.
@@ -2171,17 +2171,8 @@
 te (
-template.
 rend

use tempalte engine in club.py either