diff --git a/whirlwind/bin/whirlwind b/whirlwind/bin/whirlwind new file mode 100644 index 0000000..7427edd --- /dev/null +++ b/whirlwind/bin/whirlwind @@ -0,0 +1,55 @@ +#!/bin/bash -e + +. /lib/lsb/init-functions + +if [[ $1 == -c ]]; then + CONFIG_FILE=$2 +else + CONFIG_FILE=/etc/whirlwind.conf +fi + +if [[ -f $CONFIG_FILE ]]; then + . $CONFIG_FILE +fi + +#DAEMON_DIR=/trendrr/WeatherChannelAdmin +DAEMON=$DAEMON_DIR/main.py +NAME=whirlwind +DESC="whirlwind daemon" + +test -f $DAEMON || exit 0 + +case "$1" in + start) + echo -n "Starting $DESC: " + for PORT in ${PORTS[@]} + do + start-stop-daemon --start --pidfile /var/run/"$NAME-$PORT".pid --chdir $DAEMON_DIR --make-pidfile --background --startas $DAEMON + echo "$NAME $PORT." + done + ;; + stop) + echo -n "Stopping $DESC: " + for PORT in ${PORTS[@]} + do + start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/"$NAME-$PORT".pid + rm -f /var/run/"$NAME-$PORT".pid + echo "$NAME $PORT." + done + ;; + restart) + echo -n "Restarting $DESC: " + for PORT in ${PORTS[@]} + do + start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/"$NAME-$PORT".pid + rm -f /var/run/"$NAME-$PORT".pid + start-stop-daemon --start --pidfile /var/run/"$NAME-$PORT".pid --chdir $DAEMON_DIR --make-pidfile --background --startas $DAEMON + echo "$NAME $PORT." + done + ;; + *) + echo "Usage: "$1" {start|stop|restart}" + exit 1 + +esac +exit 0 diff --git a/whirlwind/bin/whirlwind.conf b/whirlwind/bin/whirlwind.conf new file mode 100644 index 0000000..a429fa0 --- /dev/null +++ b/whirlwind/bin/whirlwind.conf @@ -0,0 +1,2 @@ +DAEMON_DIR=/trendrr/WeatherChannelAdmin +PORTS=(8000 8001 8002 8003) \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/controllers/account_controller.py b/whirlwind/conf/app_template/application/controllers/account_controller.py index 6d3acd7..acd4cf4 100644 --- a/whirlwind/conf/app_template/application/controllers/account_controller.py +++ b/whirlwind/conf/app_template/application/controllers/account_controller.py @@ -1,10 +1,7 @@ -#from tornado import web -from mako.template import Template from whirlwind.core.request import BaseRequest from whirlwind.db.mongo import Mongo -import hashlib from application.models.user import User -import datetime +import datetime, hashlib from tornado.web import authenticated from whirlwind.view.decorators import route @@ -22,7 +19,7 @@ def get(self): template_values = {} template_values['next'] = self.get_argument('next','/') - self.render_template('/site/login.html',**template_values) + self.render_template('/account/login.html',**template_values) def post(self): username = self.get_argument("username",None) @@ -74,7 +71,7 @@ def get(self): template_values = {} template_values['next'] = self.get_argument('next','/') - self.render_template('/site/signup.html',**template_values) + self.render_template('/account/signup.html',**template_values) def post(self): username = self.get_argument("username",None) @@ -96,12 +93,6 @@ def post(self): self.flash.info = "Successfully created your account, please log in." self.redirect("/login") - - - - - - class PasswordChanger(BaseRequest): @authenticated def post(self): diff --git a/whirlwind/conf/app_template/application/controllers/site_controller.py b/whirlwind/conf/app_template/application/controllers/site_controller.py index c52ede9..9d8ea0a 100644 --- a/whirlwind/conf/app_template/application/controllers/site_controller.py +++ b/whirlwind/conf/app_template/application/controllers/site_controller.py @@ -1,17 +1,12 @@ -#from tornado import web -from mako.template import Template from whirlwind.core.request import BaseRequest - from whirlwind.db.mongo import Mongo -import hashlib -import os, StringIO, pycurl from tornado.web import authenticated from whirlwind.view.decorators import route @route('/') class IndexHandler(BaseRequest): def get(self): - template_values = { - 'page_id' : 'homepage' - } - self.render_template('/site/welcome.html',**template_values) \ No newline at end of file + #template context variables go in here + template_values = {} + + self.render_template('/site/index.html',**template_values) \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/account/login.html b/whirlwind/conf/app_template/application/views/account/login.html new file mode 100644 index 0000000..4db1f95 --- /dev/null +++ b/whirlwind/conf/app_template/application/views/account/login.html @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +<%inherit file="/layouts/content.html" /> + +<%def name="body()"> +
+
+ Please Log-in +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+ +
+
+
+ \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/account/signup.html b/whirlwind/conf/app_template/application/views/account/signup.html new file mode 100644 index 0000000..fcfa67d --- /dev/null +++ b/whirlwind/conf/app_template/application/views/account/signup.html @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +<%inherit file="/layouts/content.html" /> + +<%def name="body()"> +
+
+ Please Sign-up +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
+
+ \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/layouts/content.html b/whirlwind/conf/app_template/application/views/layouts/content.html new file mode 100644 index 0000000..72d85dc --- /dev/null +++ b/whirlwind/conf/app_template/application/views/layouts/content.html @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +<%inherit file="/layouts/htmlPage.html" /> + +### Template for content pages +<%def name="body()"> + <%include file="/shared/flash_messages.html"/> +
+
+ <%include file="/shared/header.html"/> +
+
+ <%def name="body_content()"> + ${next.body()} + + ${body_content()} +
+
+
+
+ <%include file="/shared/footer.html"/> + \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/templates/htmlPage.html b/whirlwind/conf/app_template/application/views/layouts/htmlPage.html similarity index 63% rename from whirlwind/conf/app_template/application/views/templates/htmlPage.html rename to whirlwind/conf/app_template/application/views/layouts/htmlPage.html index e7a9876..9e246bc 100644 --- a/whirlwind/conf/app_template/application/views/templates/htmlPage.html +++ b/whirlwind/conf/app_template/application/views/layouts/htmlPage.html @@ -5,20 +5,23 @@ - <%def name="page_title()">WELCOME! + <%def name="page_title()">Welcome to Whirlwind ${self.page_title()} - - - - - - + + + + ${self.head_tags()} + <%def name="head_tags()"> ${next.body()} diff --git a/whirlwind/conf/app_template/application/views/shared/_flash_messages.html b/whirlwind/conf/app_template/application/views/shared/_flash_messages.html deleted file mode 100644 index e39e7be..0000000 --- a/whirlwind/conf/app_template/application/views/shared/_flash_messages.html +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding: utf-8 -*- -% if flash: -
- % if 'error' in flash: -
- -
- % endif - % if 'notice' in flash: -
- -
- % endif - % if 'info' in flash: -
- -
- % endif - % if 'success' in flash: -
- -
- % endif -
- -% endif \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/shared/_footer.html b/whirlwind/conf/app_template/application/views/shared/_footer.html deleted file mode 100644 index 3155fd7..0000000 --- a/whirlwind/conf/app_template/application/views/shared/_footer.html +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- - -<% import datetime %> - - \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/shared/_masthead.html b/whirlwind/conf/app_template/application/views/shared/_masthead.html deleted file mode 100644 index 07694b3..0000000 --- a/whirlwind/conf/app_template/application/views/shared/_masthead.html +++ /dev/null @@ -1,9 +0,0 @@ -# -*- coding: utf-8 -*- - \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/shared/flash_messages.html b/whirlwind/conf/app_template/application/views/shared/flash_messages.html new file mode 100644 index 0000000..e819c61 --- /dev/null +++ b/whirlwind/conf/app_template/application/views/shared/flash_messages.html @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +% if flash: +
+
+
+ +% endif \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/shared/footer.html b/whirlwind/conf/app_template/application/views/shared/footer.html new file mode 100644 index 0000000..26c1fbf --- /dev/null +++ b/whirlwind/conf/app_template/application/views/shared/footer.html @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- + + \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/shared/header.html b/whirlwind/conf/app_template/application/views/shared/header.html new file mode 100644 index 0000000..6641276 --- /dev/null +++ b/whirlwind/conf/app_template/application/views/shared/header.html @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/site/index.html b/whirlwind/conf/app_template/application/views/site/index.html new file mode 100644 index 0000000..3d399fd --- /dev/null +++ b/whirlwind/conf/app_template/application/views/site/index.html @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +<%inherit file="/layouts/content.html" /> + +<%def name="body()"> + +
+
+ Check out our docs on github.com to get started +
+
+ + \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/site/login.html b/whirlwind/conf/app_template/application/views/site/login.html deleted file mode 100644 index f21118a..0000000 --- a/whirlwind/conf/app_template/application/views/site/login.html +++ /dev/null @@ -1,38 +0,0 @@ -# -*- coding: utf-8 -*- -<%inherit file="/templates/content.html" /> - -<%def name="head_tags()"> - - -<%def name="body()"> -

-
-
- -
- -
- -
-
- -
- -
- -
-
- -
- - keep me logged in -
- - -
-
- \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/site/signup.html b/whirlwind/conf/app_template/application/views/site/signup.html deleted file mode 100644 index a0f870d..0000000 --- a/whirlwind/conf/app_template/application/views/site/signup.html +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -<%inherit file="/templates/content.html" /> - -<%def name="head_tags()"> - - -<%def name="body()"> -

-
-
- -
- -
- -
-
- -
- -
- -
-
-
- -
- -
-
- -
-
- \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/site/welcome.html b/whirlwind/conf/app_template/application/views/site/welcome.html deleted file mode 100644 index 64aa3fc..0000000 --- a/whirlwind/conf/app_template/application/views/site/welcome.html +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -<%inherit file="/templates/content.html" /> - -<%def name="head_tags()"> - - -<%def name="body()"> -

-
- WELCOME! - % if is_logged_in : -

- ${current_user['_id']} is logged in - % endif -
- \ No newline at end of file diff --git a/whirlwind/conf/app_template/application/views/templates/content.html b/whirlwind/conf/app_template/application/views/templates/content.html deleted file mode 100644 index 8f6fe0b..0000000 --- a/whirlwind/conf/app_template/application/views/templates/content.html +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -<%inherit file="/templates/htmlPage.html" /> - -### Template for content pages -<%def name="body()"> - -
-
- <%include file="/shared/_masthead.html"/> - -
- <%include file="/shared/_flash_messages.html"/> - <%def name="body_content()"> - ${next.body()} - - ${body_content()} -
-
-
- - \ No newline at end of file diff --git a/whirlwind/conf/app_template/static/css/public.css b/whirlwind/conf/app_template/static/css/public.css deleted file mode 100644 index 8c29fc4..0000000 --- a/whirlwind/conf/app_template/static/css/public.css +++ /dev/null @@ -1,23 +0,0 @@ -@charset "UTF-8"; -/* CSS Document */ - - -/*------------------------------------------- - Styles --------------------------------------------*/ - -ui-offscreen { - position: absolute; - left: -10000px; - top: 0px; -} - -html, body, #wrap { - font-family:Helvetica, Arial, sans-serif; -} - -a { - color: #258fcd; - text-decoration:none; - font-weight:bold; -} \ No newline at end of file diff --git a/whirlwind/conf/app_template/static/css/style.css b/whirlwind/conf/app_template/static/css/style.css new file mode 100644 index 0000000..7c58262 --- /dev/null +++ b/whirlwind/conf/app_template/static/css/style.css @@ -0,0 +1,248 @@ +@charset "UTF-8"; + +/* Start Element Overrides */ + +* {margin:0;padding:0;} + +html, body {height: 100%;} + +body{ + background: white; + font-family: "lucida grande",tahoma,verdana,arial,sans-serif; + font-size: 11px; + color: #333; + margin: 0; + padding: 0; + text-align: left; + direction: ltr; + unicode-bidi: embed; + overflow-y: scroll; +} + +body:before { + content:""; + height:100%; + float:left; + width:0; + margin-top:-32767px;/ +} + +a { + color: #258fcd; + text-decoration:none; +} + +a:hover { + text-decoration: underline; +} + +a:active { + outline: 0 none; +} + +img, a img { + border:none; +} + +form{ + display: inline; +} + +/* End Element Overrides */ + +/* Start Layout */ +#wrap {min-height: 100%;} + +#main { + overflow:auto; + padding-bottom: 55px; +} /* must be same height as the footer */ + +#footer { + position: relative; + margin-top: -55px; /* negative value of footer height */ + height: 55px; + clear:both; + background-color: #EBEFF9; +} + +#footer-inner{ + width: 900px; + margin-left: auto; + margin-right: auto; +} + +#header{ + height: 40px; + background-color: #EBEFF9; +} + +#header-inner{ + width: 900px; + margin-left: auto; + margin-right: auto; +} + +#logo{ + float: left; + margin-top: 5px; + width: 200px; +} + +#user-menu{ + float: right; + text-align: center; + width: 200px; + padding: 5px; + font-size: 12px; + background: white; + font-weight: bold; +} + +#content{ + margin-top: 20px; +} + +#content-inner{ + width: 900px; + margin-left: auto; + margin-right: auto; +} + +#copyright{ + padding: 20px; + text-align: center; + font-weight: bold; +} + +#page-header{ + margin-bottom: 10px; + padding: 10px; + background-color: #efefef; +} + +#page-header .title{ + margin-bottom: 5px; + font-size: 20px; + font-weight: bold; +} + +#page-header .subtitle{ + font-size: 13px; + color: #999999; +} + +#page-content{ + margin-top: 20px; + padding: 0 30px 0 30px; +} + +#page-content .title{ + font-size: 15px; + font-weight: bold; +} + +#page-content .subtitle{ + color: #999999; + font-size: 12px; +} + +#page-content .body{ + padding: 20px; + text-align: center; + font-size: 20px; +} + +/* End Layout*/ + + +/* Start Common Classes */ +.column, .left { + float:left; +} + +.right { + float:right; +} + +.clear { + clear:both; + margin: 0; + padding: 0; +} + +.hidden { + display:none; +} + +.form{ + padding: 20px; + background-color: #EBEFF9; +} + +.form .title{ + margin-bottom: 10px; + font-size: 18px; + font-weight: bold; +} + +.field{ + margin-bottom: 5px; +} + +label{ + cursor: pointer; +} + +.input{ + +} + +.field input[type="text"], .field input[type="password"]{ + width: 100%; + font-size: 18px; +} + +.field input[type="checkbox"]{ + vertical-align: middle; +} + +.button{ + padding: 5px; +} + +.buttons{ + margin: 10px 0 10px 0; + text-align: right; +} + +/* End Common Classes*/ + +/* Start Twitter Style Flash Messages */ + +.flash-message{ + display: none; + width: 100%; + position: fixed; + padding-top: 10px; + padding-bottom: 10px; + margin: 0; + font-weight: bold; + font-size: 1.2em; + overflow: visible; + background-color: #efefef; +} + +.flash-message ul, .flash-message ul li{ + list-style: none; + margin:0; + padding:0; +} + +#flash-message-list{ + width: 900px; + margin-left: auto; + margin-right: auto; +} + +/* End Twitter Style Flash Messages */ \ No newline at end of file diff --git a/whirlwind/conf/app_template/static/js/application.js b/whirlwind/conf/app_template/static/js/application.js new file mode 100644 index 0000000..55b8c63 --- /dev/null +++ b/whirlwind/conf/app_template/static/js/application.js @@ -0,0 +1,40 @@ +/* + * Start Twitter Style Flash Messages + * */ + +//Provide a variable to hold the callback function +var notifyCallBack; + +function showNotification(message, type, callback) { + + notifyCallBack = callback; + + var notification = $("#flash-message"); + notification.removeClass("success notice error"); + notification.addClass(type); + + //Make sure it's visible even when top of the page not visible + notification.css("top", $(window).scrollTop()); + notification.css("width", $(document).width()); + + $("#flash-message-list").html(message); + + //show the notification + notification.slideDown("slow", function() { + setTimeout(hideNotification,4000) + }); +} + +function hideNotification() { + $("#flash-message").slideUp("slow", function() { + if (null != notifyCallBack && (typeof notifyCallBack == "function")) { + notifyCallBack(); + } + //reset the callback variable + notifyCallBack = null + }); +} + +/* + * End Twitter Style Flash Messages + * */ \ No newline at end of file diff --git a/whirlwind/conf/app_template/static/js/date.js b/whirlwind/conf/app_template/static/js/date.js new file mode 100644 index 0000000..2d52e9a --- /dev/null +++ b/whirlwind/conf/app_template/static/js/date.js @@ -0,0 +1,104 @@ +/** + * Version: 1.0 Alpha-1 + * Build Date: 13-Nov-2007 + * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved. + * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. + * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/ + */ +Date.CultureInfo={name:"en-US",englishName:"English (United States)",nativeName:"English (United States)",dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbreviatedDayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],shortestDayNames:["Su","Mo","Tu","We","Th","Fr","Sa"],firstLetterDayNames:["S","M","T","W","T","F","S"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],abbreviatedMonthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],amDesignator:"AM",pmDesignator:"PM",firstDayOfWeek:0,twoDigitYearMax:2029,dateElementOrder:"mdy",formatPatterns:{shortDate:"M/d/yyyy",longDate:"dddd, MMMM dd, yyyy",shortTime:"h:mm tt",longTime:"h:mm:ss tt",fullDateTime:"dddd, MMMM dd, yyyy h:mm:ss tt",sortableDateTime:"yyyy-MM-ddTHH:mm:ss",universalSortableDateTime:"yyyy-MM-dd HH:mm:ssZ",rfc1123:"ddd, dd MMM yyyy HH:mm:ss GMT",monthDay:"MMMM dd",yearMonth:"MMMM, yyyy"},regexPatterns:{jan:/^jan(uary)?/i,feb:/^feb(ruary)?/i,mar:/^mar(ch)?/i,apr:/^apr(il)?/i,may:/^may/i,jun:/^jun(e)?/i,jul:/^jul(y)?/i,aug:/^aug(ust)?/i,sep:/^sep(t(ember)?)?/i,oct:/^oct(ober)?/i,nov:/^nov(ember)?/i,dec:/^dec(ember)?/i,sun:/^su(n(day)?)?/i,mon:/^mo(n(day)?)?/i,tue:/^tu(e(s(day)?)?)?/i,wed:/^we(d(nesday)?)?/i,thu:/^th(u(r(s(day)?)?)?)?/i,fri:/^fr(i(day)?)?/i,sat:/^sa(t(urday)?)?/i,future:/^next/i,past:/^last|past|prev(ious)?/i,add:/^(\+|after|from)/i,subtract:/^(\-|before|ago)/i,yesterday:/^yesterday/i,today:/^t(oday)?/i,tomorrow:/^tomorrow/i,now:/^n(ow)?/i,millisecond:/^ms|milli(second)?s?/i,second:/^sec(ond)?s?/i,minute:/^min(ute)?s?/i,hour:/^h(ou)?rs?/i,week:/^w(ee)?k/i,month:/^m(o(nth)?s?)?/i,day:/^d(ays?)?/i,year:/^y((ea)?rs?)?/i,shortMeridian:/^(a|p)/i,longMeridian:/^(a\.?m?\.?|p\.?m?\.?)/i,timezone:/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\s*(\+|\-)\s*\d\d\d\d?)|gmt)/i,ordinalSuffix:/^\s*(st|nd|rd|th)/i,timeContext:/^\s*(\:|a|p)/i},abbreviatedTimeZoneStandard:{GMT:"-000",EST:"-0400",CST:"-0500",MST:"-0600",PST:"-0700"},abbreviatedTimeZoneDST:{GMT:"-000",EDT:"-0500",CDT:"-0600",MDT:"-0700",PDT:"-0800"}}; +Date.getMonthNumberFromName=function(name){var n=Date.CultureInfo.monthNames,m=Date.CultureInfo.abbreviatedMonthNames,s=name.toLowerCase();for(var i=0;idate)?1:(this=start.getTime()&&t<=end.getTime();};Date.prototype.addMilliseconds=function(value){this.setMilliseconds(this.getMilliseconds()+value);return this;};Date.prototype.addSeconds=function(value){return this.addMilliseconds(value*1000);};Date.prototype.addMinutes=function(value){return this.addMilliseconds(value*60000);};Date.prototype.addHours=function(value){return this.addMilliseconds(value*3600000);};Date.prototype.addDays=function(value){return this.addMilliseconds(value*86400000);};Date.prototype.addWeeks=function(value){return this.addMilliseconds(value*604800000);};Date.prototype.addMonths=function(value){var n=this.getDate();this.setDate(1);this.setMonth(this.getMonth()+value);this.setDate(Math.min(n,this.getDaysInMonth()));return this;};Date.prototype.addYears=function(value){return this.addMonths(value*12);};Date.prototype.add=function(config){if(typeof config=="number"){this._orient=config;return this;} +var x=config;if(x.millisecond||x.milliseconds){this.addMilliseconds(x.millisecond||x.milliseconds);} +if(x.second||x.seconds){this.addSeconds(x.second||x.seconds);} +if(x.minute||x.minutes){this.addMinutes(x.minute||x.minutes);} +if(x.hour||x.hours){this.addHours(x.hour||x.hours);} +if(x.month||x.months){this.addMonths(x.month||x.months);} +if(x.year||x.years){this.addYears(x.year||x.years);} +if(x.day||x.days){this.addDays(x.day||x.days);} +return this;};Date._validate=function(value,min,max,name){if(typeof value!="number"){throw new TypeError(value+" is not a Number.");}else if(valuemax){throw new RangeError(value+" is not a valid value for "+name+".");} +return true;};Date.validateMillisecond=function(n){return Date._validate(n,0,999,"milliseconds");};Date.validateSecond=function(n){return Date._validate(n,0,59,"seconds");};Date.validateMinute=function(n){return Date._validate(n,0,59,"minutes");};Date.validateHour=function(n){return Date._validate(n,0,23,"hours");};Date.validateDay=function(n,year,month){return Date._validate(n,1,Date.getDaysInMonth(year,month),"days");};Date.validateMonth=function(n){return Date._validate(n,0,11,"months");};Date.validateYear=function(n){return Date._validate(n,1,9999,"seconds");};Date.prototype.set=function(config){var x=config;if(!x.millisecond&&x.millisecond!==0){x.millisecond=-1;} +if(!x.second&&x.second!==0){x.second=-1;} +if(!x.minute&&x.minute!==0){x.minute=-1;} +if(!x.hour&&x.hour!==0){x.hour=-1;} +if(!x.day&&x.day!==0){x.day=-1;} +if(!x.month&&x.month!==0){x.month=-1;} +if(!x.year&&x.year!==0){x.year=-1;} +if(x.millisecond!=-1&&Date.validateMillisecond(x.millisecond)){this.addMilliseconds(x.millisecond-this.getMilliseconds());} +if(x.second!=-1&&Date.validateSecond(x.second)){this.addSeconds(x.second-this.getSeconds());} +if(x.minute!=-1&&Date.validateMinute(x.minute)){this.addMinutes(x.minute-this.getMinutes());} +if(x.hour!=-1&&Date.validateHour(x.hour)){this.addHours(x.hour-this.getHours());} +if(x.month!==-1&&Date.validateMonth(x.month)){this.addMonths(x.month-this.getMonth());} +if(x.year!=-1&&Date.validateYear(x.year)){this.addYears(x.year-this.getFullYear());} +if(x.day!=-1&&Date.validateDay(x.day,this.getFullYear(),this.getMonth())){this.addDays(x.day-this.getDate());} +if(x.timezone){this.setTimezone(x.timezone);} +if(x.timezoneOffset){this.setTimezoneOffset(x.timezoneOffset);} +return this;};Date.prototype.clearTime=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this;};Date.prototype.isLeapYear=function(){var y=this.getFullYear();return(((y%4===0)&&(y%100!==0))||(y%400===0));};Date.prototype.isWeekday=function(){return!(this.is().sat()||this.is().sun());};Date.prototype.getDaysInMonth=function(){return Date.getDaysInMonth(this.getFullYear(),this.getMonth());};Date.prototype.moveToFirstDayOfMonth=function(){return this.set({day:1});};Date.prototype.moveToLastDayOfMonth=function(){return this.set({day:this.getDaysInMonth()});};Date.prototype.moveToDayOfWeek=function(day,orient){var diff=(day-this.getDay()+7*(orient||+1))%7;return this.addDays((diff===0)?diff+=7*(orient||+1):diff);};Date.prototype.moveToMonth=function(month,orient){var diff=(month-this.getMonth()+12*(orient||+1))%12;return this.addMonths((diff===0)?diff+=12*(orient||+1):diff);};Date.prototype.getDayOfYear=function(){return Math.floor((this-new Date(this.getFullYear(),0,1))/86400000);};Date.prototype.getWeekOfYear=function(firstDayOfWeek){var y=this.getFullYear(),m=this.getMonth(),d=this.getDate();var dow=firstDayOfWeek||Date.CultureInfo.firstDayOfWeek;var offset=7+1-new Date(y,0,1).getDay();if(offset==8){offset=1;} +var daynum=((Date.UTC(y,m,d,0,0,0)-Date.UTC(y,0,1,0,0,0))/86400000)+1;var w=Math.floor((daynum-offset+7)/7);if(w===dow){y--;var prevOffset=7+1-new Date(y,0,1).getDay();if(prevOffset==2||prevOffset==8){w=53;}else{w=52;}} +return w;};Date.prototype.isDST=function(){console.log('isDST');return this.toString().match(/(E|C|M|P)(S|D)T/)[2]=="D";};Date.prototype.getTimezone=function(){return Date.getTimezoneAbbreviation(this.getUTCOffset,this.isDST());};Date.prototype.setTimezoneOffset=function(s){var here=this.getTimezoneOffset(),there=Number(s)*-6/10;this.addMinutes(there-here);return this;};Date.prototype.setTimezone=function(s){return this.setTimezoneOffset(Date.getTimezoneOffset(s));};Date.prototype.getUTCOffset=function(){var n=this.getTimezoneOffset()*-10/6,r;if(n<0){r=(n-10000).toString();return r[0]+r.substr(2);}else{r=(n+10000).toString();return"+"+r.substr(1);}};Date.prototype.getDayName=function(abbrev){return abbrev?Date.CultureInfo.abbreviatedDayNames[this.getDay()]:Date.CultureInfo.dayNames[this.getDay()];};Date.prototype.getMonthName=function(abbrev){return abbrev?Date.CultureInfo.abbreviatedMonthNames[this.getMonth()]:Date.CultureInfo.monthNames[this.getMonth()];};Date.prototype._toString=Date.prototype.toString;Date.prototype.toString=function(format){var self=this;var p=function p(s){return(s.toString().length==1)?"0"+s:s;};return format?format.replace(/dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?/g,function(format){switch(format){case"hh":return p(self.getHours()<13?self.getHours():(self.getHours()-12));case"h":return self.getHours()<13?self.getHours():(self.getHours()-12);case"HH":return p(self.getHours());case"H":return self.getHours();case"mm":return p(self.getMinutes());case"m":return self.getMinutes();case"ss":return p(self.getSeconds());case"s":return self.getSeconds();case"yyyy":return self.getFullYear();case"yy":return self.getFullYear().toString().substring(2,4);case"dddd":return self.getDayName();case"ddd":return self.getDayName(true);case"dd":return p(self.getDate());case"d":return self.getDate().toString();case"MMMM":return self.getMonthName();case"MMM":return self.getMonthName(true);case"MM":return p((self.getMonth()+1));case"M":return self.getMonth()+1;case"t":return self.getHours()<12?Date.CultureInfo.amDesignator.substring(0,1):Date.CultureInfo.pmDesignator.substring(0,1);case"tt":return self.getHours()<12?Date.CultureInfo.amDesignator:Date.CultureInfo.pmDesignator;case"zzz":case"zz":case"z":return"";}}):this._toString();}; +Date.now=function(){return new Date();};Date.today=function(){return Date.now().clearTime();};Date.prototype._orient=+1;Date.prototype.next=function(){this._orient=+1;return this;};Date.prototype.last=Date.prototype.prev=Date.prototype.previous=function(){this._orient=-1;return this;};Date.prototype._is=false;Date.prototype.is=function(){this._is=true;return this;};Number.prototype._dateElement="day";Number.prototype.fromNow=function(){var c={};c[this._dateElement]=this;return Date.now().add(c);};Number.prototype.ago=function(){var c={};c[this._dateElement]=this*-1;return Date.now().add(c);};(function(){var $D=Date.prototype,$N=Number.prototype;var dx=("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),mx=("january february march april may june july august september october november december").split(/\s/),px=("Millisecond Second Minute Hour Day Week Month Year").split(/\s/),de;var df=function(n){return function(){if(this._is){this._is=false;return this.getDay()==n;} +return this.moveToDayOfWeek(n,this._orient);};};for(var i=0;i0&&!last){try{q=d.call(this,r[1]);}catch(ex){last=true;}}else{last=true;} +if(!last&&q[1].length===0){last=true;} +if(!last){var qx=[];for(var j=0;j0){rx[0]=rx[0].concat(p[0]);rx[1]=p[1];}} +if(rx[1].length1){args=Array.prototype.slice.call(arguments);}else if(arguments[0]instanceof Array){args=arguments[0];} +if(args){for(var i=0,px=args.shift();i2)?n:(n+(((n+2000)Date.getDaysInMonth(this.year,this.month)){throw new RangeError(this.day+" is not a valid value for days.");} +var r=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second);if(this.timezone){r.set({timezone:this.timezone});}else if(this.timezoneOffset){r.set({timezoneOffset:this.timezoneOffset});} +return r;},finish:function(x){x=(x instanceof Array)?flattenAndCompact(x):[x];if(x.length===0){return null;} +for(var i=0;i 'string' * Trendrr.trim('trendrr', 'r'); => 'trend' */ -Trendrr.trim = function(str, trim) { +Whirlwind.trim = function(str, trim) { if (!str) { return str; } @@ -217,10 +214,10 @@ Trendrr.trim = function(str, trim) { return jQuery.trim(str); } var tmp = str; - while(Trendrr.stringStartsWith(tmp, trim)) { + while(Whirlwind.stringStartsWith(tmp, trim)) { tmp = tmp.slice(trim.length); } - while(Trendrr.stringEndsWith(tmp, trim)) { + while(Whirlwind.stringEndsWith(tmp, trim)) { tmp = tmp.slice(0, tmp.length-trim.length); } return tmp; @@ -238,8 +235,8 @@ Trendrr.trim = function(str, trim) { * if false will return the updated url * clearParams = (default false) if true will clear all url params before the params are applied */ -Trendrr.href = function(options) { - if (Trendrr.isString(options)) { +Whirlwind.href = function(options) { + if (Whirlwind.isString(options)) { options = {url:options}; } var opts = $.extend({ @@ -281,7 +278,7 @@ Trendrr.href = function(options) { * must be with the current scrollpane., */ -Trendrr.isVisible = function(element) { +Whirlwind.isVisible = function(element) { if (!element) { return false; } @@ -298,11 +295,12 @@ Trendrr.isVisible = function(element) { if (elem.hasClass('ui-offscreen')) { return false; } + if (elem.closest('.ui-offscreen').size() > 0) { return false; } - var measure = Trendrr.measure(elem); + var measure = Whirlwind.measure(elem); if ($(document).scrollTop() > (measure.top + measure.height)) { return false; @@ -323,7 +321,7 @@ Trendrr.isVisible = function(element) { * * */ -Trendrr.formatNumber = function(number) { +Whirlwind.formatNumber = function(number) { var str = ''; var unit = ''; diff --git a/whirlwind/core/request.py b/whirlwind/core/request.py index 1ebefe1..05e1dbe 100644 --- a/whirlwind/core/request.py +++ b/whirlwind/core/request.py @@ -6,6 +6,7 @@ from tornado import web from urllib import unquote from whirlwind.middleware import MiddlewareManager +from whirlwind.core.log import Log from tornado import ioloop @@ -39,6 +40,9 @@ def template_exists(self, template_name): def _get_template_lookup(self) : + from whirlwind.view.filters import Cycler + Cycler.cycle_registry = {} + return TemplateLookup( directories=[options.template_dir], module_directory=options.mako_modules_dir, @@ -185,3 +189,59 @@ def get_error_html(self, status_code, **kwargs): self.redirect('/404') else : # call super. self.redirect('/error') + + #helper function to page lists of objects + def paged_list(table_class,select=None,sort=None): + + page = self.get_argument('page',1) + page = page if page >= 1 else 1 + + count = self.get_argument('count',10) + count = count if count >= 1 else 10 + + if select: + if sort: + results = table_class.find(select).skip((page-1)*count).limit(count).sort(sort) + else: + results = table_class.find(select).skip((page-1)*count).limit(count) + + total = table_class.find(select).count() + else: + if sort: + results = table_class.find().skip((page-1)*count).limit(count).sort(sort) + else: + results = table_class.find().skip((page-1)*count).limit(count) + + total = table_class.find().count() + + return Paginator(results,page,count,total) + + #delete checked list items + def delete_selected(pymongo_collection,feild_name='ids',return_stats=False): + ids = self.get_argument(feild_name,[]) + + if len(ids) == 0: return False + + if not return_stats: + pymongo_collection.remove( + {'_id':{'$in':ids} + }) + return True + else: + stats = { + 'requested':len(ids), + 'success':0, + 'failed':0 + } + + for id in ids: + try: + pymongo_collection.remove({'_id':id},True) + stats['success'] += 1 + except Exception, ex: + stats['failed'] += 1 + Log.error(ex.message) + + return stats + + \ No newline at end of file