From 0c0073e84d84902872b39ea8e61f753116613027 Mon Sep 17 00:00:00 2001 From: Salem Amin Talha Date: Thu, 15 Mar 2012 18:53:25 -0400 Subject: [PATCH] Created active clubs page. --- .htaccess | 2 +- bin/clubs.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/config.d | 3 ++- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100755 bin/clubs.py diff --git a/.htaccess b/.htaccess index 7b23492..33d5b27 100644 --- a/.htaccess +++ b/.htaccess @@ -1,4 +1,4 @@ RewriteEngine on -RewriteBase /~j3parker/ +RewriteBase /~satalha/www/ RewriteRule ^pub/(.*) - [L] RewriteRule ^(.*) bin/web [L] diff --git a/bin/clubs.py b/bin/clubs.py new file mode 100755 index 0000000..18a4ca8 --- /dev/null +++ b/bin/clubs.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +import ldap, time, operator + +# +# globals +# +cscUri = "http://csclub.uwaterloo.ca/xsltproc" +cscTerms = ["Winter", "Spring", "Fall"] +cscShortTerms = ['w', 's', 'f'] +cscLdapUri = "ldap://ldap1.csclub.uwaterloo.ca ldap://ldap2.csclub.uwaterloo.ca" +cscLdap = None + +cscClubBase = 'ou=People, dc=csclub, dc=uwaterloo, dc=ca' +cscGroupBase = 'ou=Group, dc=csclub, dc=uwaterloo, dc=ca' +cscPeopleBase = 'ou=People,dc=csclub,dc=uwaterloo,dc=ca' + + +def cscLdapConnect(): + global cscLdap + cscLdap = ldap.initialize(cscLdapUri) + cscLdap.simple_bind_s("", "") + +cscLdapConnect() + +curDate = time.strftime('%d-%m-%Y') +year = time.localtime().tm_year +term = cscShortTerms[int(time.localtime().tm_mon - 1) / 4] +term2 = cscTerms[int(time.localtime().tm_mon - 1) / 4] + + +clubs = cscLdap.search_s(cscClubBase, ldap.SCOPE_SUBTREE, '(&(objectClass=club))') +groups = cscLdap.search_s(cscGroupBase, ldap.SCOPE_SUBTREE, '(&(objectClass=group))') +members = cscLdap.search_s(cscPeopleBase, ldap.SCOPE_SUBTREE,'(&(objectClass=member)(|(term=%s%d)(nonMemberTerm=%s%d)))' % (term, year, term, year)) + + +clubs.sort(key=lambda (_, y): y['cn'][0]) +print "

Clubs This Term

" +print "
" +print "" +print " " + + +def doshit(club): + for (_, group) in groups: + if group['cn'][0] == club['uid'][0] and group.has_key('uniqueMember'): + for clubrep in group['uniqueMember']: + clubrepname = clubrep.split(",")[0][4:] + for (_, member) in members: + if member['uid'][0] == clubrepname: + print " " + print " " + print " " + return + +for (_, club) in clubs: + doshit(club) + +print "
Name
" + club['cn'][0] + "
" +print "
" diff --git a/src/config.d b/src/config.d index 94aa9df..cfb2174 100644 --- a/src/config.d +++ b/src/config.d @@ -1,6 +1,6 @@ import std.regex; -const string url_root = "/~j3parker/"; +const string url_root = "/~satalha/www/"; const string site_title = "CSC"; const string site_subtitle = "UWaterloo Computer Science Club"; @@ -14,6 +14,7 @@ void init_handlers() { handler!("^About/Members/$").add("members.py"); handler!("^About/Members/(.+)$").add("member_info.py"); handler!("^About/Executive$").add("exec_positions.py"); + handler!("^About/Clubs/$").add("clubs.py"); } template handler(string pattern) {