Skip to content

Commit

Permalink
WIP: Community page and 'Proud Cherokee Users' list.
Browse files Browse the repository at this point in the history
git-svn-id: svn://cherokee-project.com/web/branches/beta-ctk@6577 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed May 4, 2011
1 parent ec4406f commit 417199c
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHEROKEE_WEB-server.py
Expand Up @@ -30,5 +30,6 @@
import PageSVN
import PageDistro
import PageDoc
import PageCommunity

CTK.run (port=8090)
50 changes: 50 additions & 0 deletions PageCommunity.py
@@ -0,0 +1,50 @@
# -*- Mode: python; coding: utf-8 -*-

#
# Cherokee Web Site
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2001-2011 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program 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 General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#

import os
import re
import CTK
import Page
import config
import ProudList

URL_BASE = "/community"


class PageCommunity:
def __call__ (self):
title = "Community"

page = Page.Page_Menu_Side (title=title)
page += CTK.RawHTML ("<h1>%s</h1>"%(title))

# Proud Cherokee Users List
page.sidebar += ProudList.DomainList()

return CTK.HTTP_Cacheable (60, body=page.Render())



CTK.publish (URL_BASE, PageCommunity)
87 changes: 87 additions & 0 deletions ProudList.py
@@ -0,0 +1,87 @@
# -*- Mode: python; coding: utf-8 -*-

#
# Cherokee Web Site
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2001-2011 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program 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 General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#

import os
import re
import CTK
import time
import Page
import config
import cPickle

CACHE_EXPIRATION = 15 * 60 # 10mins


DOMAIN_CLICK_JS = """
$(".domain").click (function (event) {
var domain = $(this).text();
event.preventDefault();
event.stopPropagation();
window.open ("http://" + domain + "/", '_blank');
});
"""

def domain_cmp (x, y):
if y['page_rank'] == x['page_rank']:
return cmp (x['domain'], y['domain'])

return cmp (y['page_rank'], x['page_rank'])


class DomainList_Widget (CTK.Box):
def __init__ (self):
CTK.Box.__init__ (self, {'class': 'domain_list'})

# Load, filter and sort the domain list
domains = cPickle.load (open (config.PROUD_PICKLE, 'r'))
domains_clean = filter (lambda d: d['publish'], domains)
domains_clean.sort (domain_cmp)

# Render the domain list
l = CTK.List()
for domain in domains_clean:
l += CTK.Box ({'class': 'domain domain-PR%s'%(domain['page_rank'])}, CTK.RawHTML(domain['domain']))

self += CTK.RawHTML ("<h3>Proud Cherokee Users</h3>")
self += l
self += CTK.RawHTML (js = DOMAIN_CLICK_JS)


#
# Factory and cache
#
latest_widget = None
latest_widget_expiration = None

def DomainList():
global latest_widget
global latest_widget_expiration

if not latest_widget or time.time() > latest_widget_expiration:
latest_widget = DomainList_Widget()
latest_widget_expiration = time.time() + CACHE_EXPIRATION

return latest_widget
3 changes: 2 additions & 1 deletion config.py
Expand Up @@ -3,4 +3,5 @@
DOWNLOADS_LOCAL = '/var/www/www.cherokee-project.com/download'
DOWNLOADS_WEB = 'http://www.cherokee-project.com/download'

DOC_LOCAL = '/var/www/www.cherokee-project.com/doc'
DOC_LOCAL = '/var/www/www.cherokee-project.com/doc'
PROUD_PICKLE = '/var/lib/ows/proud/domains.pickle'

0 comments on commit 417199c

Please sign in to comment.