posted on January 27th, 2009 by Greg in CDWS Projects
The idea for this site came when some co-workers and I were collecting our W2’s and found letters attached with some HR information. One of them had a ridiculously long URL at the bottom of it (…Enroll%20in%20UCF%20Retirement%20Plans…). Before seeing that URL I hadn’t thought of the convenience of services like
TinyURL outside of the internet. We realized it would be simple enough to write one that is specific to UCF.
We decided on a few simple features and jumped into
pair programming the site with
django. Since
Jason was new to Django, he obvserved while I drove. It took less than the rest of the day to finish the site.
Features
Only allows domains that we specify
We created a custom Form Field to accomplish this and made it able to accept a tuple of allowed domains. If anyone needs this on their site they can use the following code.
from django import forms
class URLDomainField(forms.URLField):
domain = ''
def __init__(self, *args, **kwargs):
# set domain to passed value or default
self.domain = kwargs.get('domain', ('gregallard.com', 'isthemarketdown.com', 'codespatter.com'))
# remove from list if exists
try:
del kwargs['domain']
except:
pass
# call parent init
super(URLDomainField, self).__init__(*args, **kwargs)
def clean(self, value):
# call parent clean
value = super(URLDomainField, self).clean(value)
from urlparse import urlparse
o = urlparse(value)
# endswith accepts tuples and will try them all and will return false if none match
if not o.hostname.endswith(self.domain):
raise forms.ValidationError('%s is not a valid url! %s domains only.' % (value, self.domain))
return value
The code to use this would look like this:
class LinkForm(forms.Form):
url = URLDomainField(domain=('ivylees.com', 'ucf.edu'))
Automatically creates 5 character alphanumeric string
This method in the model creates a string and makes sure it isn’t in use yet:
def make_short(self):
from random import Random
import string
cool = False
while not cool:
self.short = ''.join( Random().sample(string.letters+string.digits, 5) )
try:
r = Link.objects.get(short=self.short)
except Link.DoesNotExist:
if self.short != "admin" and self.short != "thank":
cool = True
Allows for custom strings
By default it will create a 5 character alphanumeric string to go at the end of the URL, however we added a form field to allow users to specify their own string so that the URL might have more meaning. To strip non alphanumeric characters, we created a simple clean method in the model:
def clean_short(self):
import re
# ^ as first character inside [] negates the set
# find everything that isn't alphanumeric or a -
self.short = re.sub('[^\w|\-]', '_', self.short)
Won’t create more short links
If a URL has been submitted before, the site will not create an extra URL for it, instead it will return the existing one to the user. To do this, we added some functionality to the save method:
def save(self, **kwargs):
link = Link.objects.filter(url=self.url)[:1]
# if one exists, return it, otherwise save it
if link:
# there should be a better way to do this
# but self = link doesn't work
self.url = link[0].url
self.short = link[0].short
self.created = link[0].created
self.id = link[0].id
else:
if self.short == '':
self.make_short()
else:
self.clean_short()
super(Link, self).save(**kwargs)
Just a Prototype
We just wanted to create something simple as a prototype so that hopefully some of the higher-ups will like the idea and we can put it into production.
Pair Programming
This was the first time I had any experience with pair programming and I definitely think it’s a great idea. Jason learned a lot about django, caught my mistakes, and pointed out other things. I solidified my knowledge by showing him what I knew and we both learned some valuable things. For example: using print foo will be displayed in the command window when you are using the django development server. I foresee more pair programming in my future.
Update 2009-01-28
Tim recommended that I remove the chance of profanity to be automatically generated for the url and suggested removing all vowels so that no words will be there. This is the line I added to achieve that.
letters = re.sub('a|e|i|o|u|A|E|I|O|U', '', string.letters)
posted on October 3rd, 2008 by Greg in CDWS Projects
At a large institution like UCF, it is good to have a plan for emergencies. I set up a simple form that will update the main page at
http://ucf.edu in an emergency so that important information can be realeased as fast as possible.
The main page is an html file that is copied every few minutes from our database driven application. This speeds up the website and cuts down on processor utilization considerably. A simple update to our cron job was added that checks if the site is in emergency mode and pulls from our other emergency page. This emergency page is created with a simple form and simple template file.
I created this page updater to be reliable and simple so that there is little turn arround time from emergency situation to information available. The form edits files in the filesystem instead of using a database that would require more complexity. There is a place to update the important information. That info is then put into the pre-built template when the user hits preview. Once the user is satisfied with the way it looks, there is a button to enable/disable the page. It updates the status that the cron job looks for and the main page will change in under a minute.
posted on June 23rd, 2008 by Greg in CDWS Projects
I say middle end (even though it’s not an end) since I didn’t work on the front-end skin or on the content-management back end.
The new site was launched a few days ago (6/21/8) and uses an installment of
InQuira
Information Manager as the content management system. With the CMS comes a JSP tag library. I used the tag library to extract data from the CMS and format it in the front-end layout. I was also responsible for designing the structure of the channels, categories, and schema in InfoManager.
Read the rest of this entry »
posted on April 1st, 2008 by Greg in CDWS Projects
Workflow Management
To Be Done is a Web-based workflow tool that manages the collection, tracking, and processing of work requests. It is written in PHP and uses a MySQL database. It facilitates the collaboration between teams by enabling team members to create requests for other teams’ members to complete. Time-to-completion data is stored when a user completes a request and can be used to display totals, percentages, and averages of requests and hours in a report that can be generated automatically. The report that is generated can also display specific information per user and per course.
Read the rest of this entry »
posted on March 24th, 2008 by Greg in CDWS Projects
Valhalla, which is implemented with PHP and a MySQL database, powers the Techranger Web site. It provides the Techranger team with the ability to manage all aspects of the site including: image galleries, user biographies, job applications, XHTML templates, multiple cascading style sheets and other site features.
For this project I created the data access classes as well as designing the database itself. I also wrote the job application, image gallery, project showcase, and user biography features.
posted on March 20th, 2008 by Greg in CDWS Projects
To Be Done is a Web-based workflow tool that manages the collection, tracking, and processing of work requests. It is written in PHP and uses a MySQL database. It facilitates the collaboration between teams by enabling team members to create requests for other teams’ members to complete. Time-to-completion data is stored when a user completes a request and can be used to display totals, percentages, and averages of requests and hours in a report that can be generated automatically. The report that is generated can also display specific information per user and per course.
Similar to the request functionality, there is a tech support tracker which uses the same process with the addition of client information being stored.
I joined the project to develop the 2.0 version, which was a complete re-write since the original developer didn’t give us any comments or documentation before leaving.
My initial role in the project was to design the database and create the data access classes. After the interface developer left, I started fixing bugs as well as developing new features, such as the report generator. I also began broadening the scope of the project to allow for any team to assign tech support incidents or requests to any team.
posted on March 20th, 2008 by Greg in CDWS Projects
I created an OpenID provider for CDWS. It connected to our LDAP server to authenticate users and provided them with an OpenID in the form of http://username.cdws.us
I used the Jan Rain PEAR library for the OpenID connections and followed the code they provided in an example. I modified the example code heavily to fit it into the CyTE framework for easier future development and maintenance.