Created active clubs page.
authorSalem Amin Talha <satalha@caffeine.csclub.uwaterloo.ca>
Thu, 15 Mar 2012 22:53:25 +0000 (18:53 -0400)
committerSalem Amin Talha <satalha@caffeine.csclub.uwaterloo.ca>
Thu, 15 Mar 2012 22:53:25 +0000 (18:53 -0400)
.htaccess
bin/clubs.py [new file with mode: 0755]
src/config.d

index 7b23492..33d5b27 100644 (file)
--- 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 (executable)
index 0000000..18a4ca8
--- /dev/null
@@ -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 "<h1>Clubs This Term</h1>"
+print "<center>"
+print "<table>"
+print "    <tr><th>Name</th></tr>"
+
+
+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 "    <tr>"
+                        print "        <td><a href=\"http://csclub.uwaterloo.ca/~" + club['uid'][0] + "\">" + club['cn'][0] + "</a></td>"
+                        print "    </tr>"
+                        return
+
+for (_, club) in clubs:
+  doshit(club)
+
+print "</table>"
+print "</center>"
index 94aa9df..cfb2174 100644 (file)
@@ -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) {