From 1fd9d4cd1e165e905ec8b53d55780c61995bde7c Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 7 Jul 2014 11:34:17 -0700 Subject: [PATCH 1/1] xoslib javascript from demo app --- planetstack/core/xoslib/__init__.py | 1 - planetstack/core/xoslib/objects/__init__.py | 12 ------- planetstack/core/xoslib/objects/nodes.py | 19 ----------- planetstack/core/xoslib/objects/sites.py | 20 ----------- planetstack/core/xoslib/objects/slices.py | 21 ------------ planetstack/core/xoslib/objects/slivers.py | 20 ----------- planetstack/core/xoslib/objects/xosbase.py | 21 ------------ .../core/xoslib/static/js/ICanHaz.min.js | 10 ++++++ .../core/xoslib/static/js/backbone-min.js | 33 +++++++++++++++++++ .../core/xoslib/static/js/underscore-min.js | 30 +++++++++++++++++ planetstack/core/xoslib/xoslib.py | 19 ----------- 11 files changed, 73 insertions(+), 133 deletions(-) delete mode 100644 planetstack/core/xoslib/__init__.py delete mode 100644 planetstack/core/xoslib/objects/__init__.py delete mode 100644 planetstack/core/xoslib/objects/nodes.py delete mode 100644 planetstack/core/xoslib/objects/sites.py delete mode 100644 planetstack/core/xoslib/objects/slices.py delete mode 100644 planetstack/core/xoslib/objects/slivers.py delete mode 100644 planetstack/core/xoslib/objects/xosbase.py create mode 100644 planetstack/core/xoslib/static/js/ICanHaz.min.js create mode 100644 planetstack/core/xoslib/static/js/backbone-min.js create mode 100644 planetstack/core/xoslib/static/js/underscore-min.js delete mode 100644 planetstack/core/xoslib/xoslib.py diff --git a/planetstack/core/xoslib/__init__.py b/planetstack/core/xoslib/__init__.py deleted file mode 100644 index f71ac5d..0000000 --- a/planetstack/core/xoslib/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .xoslib import * diff --git a/planetstack/core/xoslib/objects/__init__.py b/planetstack/core/xoslib/objects/__init__.py deleted file mode 100644 index 5387bfe..0000000 --- a/planetstack/core/xoslib/objects/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -from .slivers import XOSSlivers -from .sites import XOSSites -from .nodes import XOSNodes -from .slices import XOSSlices - -XOSLIB_OBJECTS = {} - -XOSLIB_OBJECTS[XOSSlivers.name] = XOSSlivers -XOSLIB_OBJECTS[XOSSites.name] = XOSSites -XOSLIB_OBJECTS[XOSNodes.name] = XOSNodes -XOSLIB_OBJECTS[XOSSlices.name] = XOSSlices - diff --git a/planetstack/core/xoslib/objects/nodes.py b/planetstack/core/xoslib/objects/nodes.py deleted file mode 100644 index fedd0b0..0000000 --- a/planetstack/core/xoslib/objects/nodes.py +++ /dev/null @@ -1,19 +0,0 @@ -from core.models import Node -from xosbase import XOSBase -from django.forms.models import model_to_dict - -class XOSNodes(XOSBase): - name = "nodes" - - def __init__(self): - super(XOSNodes, self).__init__() - - def get(self): - allNodes = list(Node.objects.all()) - - result = [] - for nocd in allNodes: - d=model_to_dict(nocd) - result.append(self.ensure_serializable(d)) - - return result diff --git a/planetstack/core/xoslib/objects/sites.py b/planetstack/core/xoslib/objects/sites.py deleted file mode 100644 index 7146320..0000000 --- a/planetstack/core/xoslib/objects/sites.py +++ /dev/null @@ -1,20 +0,0 @@ -from core.models import Site -from xosbase import XOSBase -from django.forms.models import model_to_dict - -class XOSSites(XOSBase): - name = "sites" - - def __init__(self): - super(XOSSites, self).__init__() - - def get(self): - allSites = list(Site.objects.all()) - - result = [] - for site in allSites: - d=model_to_dict(site) - result.append(self.ensure_serializable(d)) - - return result - diff --git a/planetstack/core/xoslib/objects/slices.py b/planetstack/core/xoslib/objects/slices.py deleted file mode 100644 index 04a04f2..0000000 --- a/planetstack/core/xoslib/objects/slices.py +++ /dev/null @@ -1,21 +0,0 @@ -from core.models import Slice -from xosbase import XOSBase -from django.forms.models import model_to_dict - -class XOSSlices(XOSBase): - name = "slices" - - def __init__(self): - super(XOSSlices, self).__init__() - - def get(self): - allSlices = list(Slice.objects.all()) - - result = [] - for slice in allSlices: - d = model_to_dict(slice) - result.append(self.ensure_serializable(d)) - - return result - - diff --git a/planetstack/core/xoslib/objects/slivers.py b/planetstack/core/xoslib/objects/slivers.py deleted file mode 100644 index 1428908..0000000 --- a/planetstack/core/xoslib/objects/slivers.py +++ /dev/null @@ -1,20 +0,0 @@ -from core.models import Sliver -from xosbase import XOSBase -from django.forms.models import model_to_dict - -class XOSSlivers(XOSBase): - name = "slivers" - - def __init__(self): - super(XOSSlivers, self).__init__() - - def get(self): - allSlivers = list(Sliver.objects.all()) - - result = [] - for sliver in allSlivers: - d=model_to_dict(sliver) - result.append(self.ensure_serializable(d)) - - return result - diff --git a/planetstack/core/xoslib/objects/xosbase.py b/planetstack/core/xoslib/objects/xosbase.py deleted file mode 100644 index 881c7b5..0000000 --- a/planetstack/core/xoslib/objects/xosbase.py +++ /dev/null @@ -1,21 +0,0 @@ -import datetime -import time - -class XOSBase(object): - name = "XOSBase" - - def __init__(self): - pass - - def ensure_serializable(self, d): - d2={} - for (k,v) in d.items(): - # datetime is not json serializable - if isinstance(v, datetime.datetime): - d2[k] = time.mktime(v.timetuple()) - elif v.__class__.__name__ == "Geoposition": - pass - else: - d2[k] = v - return d2 - diff --git a/planetstack/core/xoslib/static/js/ICanHaz.min.js b/planetstack/core/xoslib/static/js/ICanHaz.min.js new file mode 100644 index 0000000..18ef653 --- /dev/null +++ b/planetstack/core/xoslib/static/js/ICanHaz.min.js @@ -0,0 +1,10 @@ +(function(){var m=function(){var f=function(){};f.prototype={otag:"{{",ctag:"}}",pragmas:{},buffer:[],pragmas_implemented:{"IMPLICIT-ITERATOR":true},context:{},render:function(a,b,c,d){if(!d){this.context=b;this.buffer=[]}if(!this.includes("",a))if(d)return a;else{this.send(a);return}a=this.render_pragmas(a);a=this.render_section(a,b,c);if(d)return this.render_tags(a,b,c,d);this.render_tags(a,b,c,d)},send:function(a){a!=""&&this.buffer.push(a)},render_pragmas:function(a){if(!this.includes("%",a))return a; +var b=this;return a.replace(RegExp(this.otag+"%([\\w-]+) ?([\\w]+=[\\w]+)?"+this.ctag),function(c,d,e){if(!b.pragmas_implemented[d])throw{message:"This implementation of mustache doesn't understand the '"+d+"' pragma"};b.pragmas[d]={};if(e){c=e.split("=");b.pragmas[d][c[0]]=c[1]}return""})},render_partial:function(a,b,c){a=this.trim(a);if(!c||c[a]===undefined)throw{message:"unknown_partial '"+a+"'"};if(typeof b[a]!="object")return this.render(c[a],b,c,true);return this.render(c[a],b[a],c,true)},render_section:function(a, +b,c){if(!this.includes("#",a)&&!this.includes("^",a))return a;var d=this;return a.replace(RegExp(this.otag+"(\\^|\\#)\\s*(.+)\\s*"+this.ctag+"\n*([\\s\\S]+?)"+this.otag+"\\/\\s*\\2\\s*"+this.ctag+"\\s*","mg"),function(e,i,j,h){e=d.find(j,b);if(i=="^")return!e||d.is_array(e)&&e.length===0?d.render(h,b,c,true):"";else if(i=="#")return d.is_array(e)?d.map(e,function(g){return d.render(h,d.create_context(g),c,true)}).join(""):d.is_object(e)?d.render(h,d.create_context(e),c,true):typeof e==="function"? +e.call(b,h,function(g){return d.render(g,b,c,true)}):e?d.render(h,b,c,true):""})},render_tags:function(a,b,c,d){var e=this,i=function(){return RegExp(e.otag+"(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?"+e.ctag+"+","g")},j=i(),h=function(n,l,k){switch(l){case "!":return"";case "=":e.set_delimiters(k);j=i();return"";case ">":return e.render_partial(k,b,c);case "{":return e.find(k,b);default:return e.escape(e.find(k,b))}};a=a.split("\n");for(var g=0;g\\]/g,function(b){switch(b){case "&":return"&";case "\\":return"\\\\";case '"':return'"';case "<":return"<";case ">":return">";default:return b}})},create_context:function(a){if(this.is_object(a))return a;else{var b=".";if(this.pragmas["IMPLICIT-ITERATOR"])b=this.pragmas["IMPLICIT-ITERATOR"].iterator;var c={};c[b]=a;return c}}, +is_object:function(a){return a&&typeof a=="object"},is_array:function(a){return Object.prototype.toString.call(a)==="[object Array]"},trim:function(a){return a.replace(/^\s*|\s*$/g,"")},map:function(a,b){if(typeof a.map=="function")return a.map(b);else{for(var c=[],d=a.length,e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")},has:function(a){return this.attributes[a]!=null},set:function(a,b){b||(b={});if(!a)return this;if(a.attributes)a=a.attributes;var c=this.attributes,d=this._escapedAttributes;if(!b.silent&&this.validate&&!this._performValidation(a,b))return!1;if(this.idAttribute in a)this.id=a[this.idAttribute]; +var e=this._changing;this._changing=!0;for(var g in a){var h=a[g];if(!f.isEqual(c[g],h))c[g]=h,delete d[g],this._changed=!0,b.silent||this.trigger("change:"+g,this,h,b)}!e&&!b.silent&&this._changed&&this.change(b);this._changing=!1;return this},unset:function(a,b){if(!(a in this.attributes))return this;b||(b={});var c={};c[a]=void 0;if(!b.silent&&this.validate&&!this._performValidation(c,b))return!1;delete this.attributes[a];delete this._escapedAttributes[a];a==this.idAttribute&&delete this.id;this._changed= +!0;b.silent||(this.trigger("change:"+a,this,void 0,b),this.change(b));return this},clear:function(a){a||(a={});var b,c=this.attributes,d={};for(b in c)d[b]=void 0;if(!a.silent&&this.validate&&!this._performValidation(d,a))return!1;this.attributes={};this._escapedAttributes={};this._changed=!0;if(!a.silent){for(b in c)this.trigger("change:"+b,this,void 0,a);this.change(a)}return this},fetch:function(a){a||(a={});var b=this,c=a.success;a.success=function(d,e,f){if(!b.set(b.parse(d,f),a))return!1;c&& +c(b,d)};a.error=i(a.error,b,a);return(this.sync||e.sync).call(this,"read",this,a)},save:function(a,b){b||(b={});if(a&&!this.set(a,b))return!1;var c=this,d=b.success;b.success=function(a,e,f){if(!c.set(c.parse(a,f),b))return!1;d&&d(c,a,f)};b.error=i(b.error,c,b);var f=this.isNew()?"create":"update";return(this.sync||e.sync).call(this,f,this,b)},destroy:function(a){a||(a={});if(this.isNew())return this.trigger("destroy",this,this.collection,a);var b=this,c=a.success;a.success=function(d){b.trigger("destroy", +b,b.collection,a);c&&c(b,d)};a.error=i(a.error,b,a);return(this.sync||e.sync).call(this,"delete",this,a)},url:function(){var a=k(this.collection)||this.urlRoot||l();if(this.isNew())return a;return a+(a.charAt(a.length-1)=="/"?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this)},isNew:function(){return this.id==null},change:function(a){this.trigger("change",this,a);this._previousAttributes=f.clone(this.attributes);this._changed=!1},hasChanged:function(a){if(a)return this._previousAttributes[a]!= +this.attributes[a];return this._changed},changedAttributes:function(a){a||(a=this.attributes);var b=this._previousAttributes,c=!1,d;for(d in a)f.isEqual(b[d],a[d])||(c=c||{},c[d]=a[d]);return c},previous:function(a){if(!a||!this._previousAttributes)return null;return this._previousAttributes[a]},previousAttributes:function(){return f.clone(this._previousAttributes)},_performValidation:function(a,b){var c=this.validate(a);if(c)return b.error?b.error(this,c,b):this.trigger("error",this,c,b),!1;return!0}}); +e.Collection=function(a,b){b||(b={});if(b.comparator)this.comparator=b.comparator;f.bindAll(this,"_onModelEvent","_removeReference");this._reset();a&&this.reset(a,{silent:!0});this.initialize.apply(this,arguments)};f.extend(e.Collection.prototype,e.Events,{model:e.Model,initialize:function(){},toJSON:function(){return this.map(function(a){return a.toJSON()})},add:function(a,b){if(f.isArray(a))for(var c=0,d=a.length;c').hide().appendTo("body")[0].contentWindow,this.navigate(a); +this._hasPushState?g(window).bind("popstate",this.checkUrl):"onhashchange"in window&&!b?g(window).bind("hashchange",this.checkUrl):setInterval(this.checkUrl,this.interval);this.fragment=a;m=!0;a=window.location;b=a.pathname==this.options.root;if(this._wantsPushState&&!this._hasPushState&&!b)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;else if(this._wantsPushState&&this._hasPushState&&b&&a.hash)this.fragment=a.hash.replace(j,""),window.history.replaceState({}, +document.title,a.protocol+"//"+a.host+this.options.root+this.fragment);if(!this.options.silent)return this.loadUrl()},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a==this.fragment&&this.iframe&&(a=this.getFragment(this.iframe.location.hash));if(a==this.fragment||a==decodeURIComponent(this.fragment))return!1;this.iframe&&this.navigate(a);this.loadUrl()||this.loadUrl(window.location.hash)},loadUrl:function(a){var b=this.fragment=this.getFragment(a); +return f.any(this.handlers,function(a){if(a.route.test(b))return a.callback(b),!0})},navigate:function(a,b){var c=(a||"").replace(j,"");if(!(this.fragment==c||this.fragment==decodeURIComponent(c))){if(this._hasPushState){var d=window.location;c.indexOf(this.options.root)!=0&&(c=this.options.root+c);this.fragment=c;window.history.pushState({},document.title,d.protocol+"//"+d.host+c)}else if(window.location.hash=this.fragment=c,this.iframe&&c!=this.getFragment(this.iframe.location.hash))this.iframe.document.open().close(), +this.iframe.location.hash=c;b&&this.loadUrl(a)}}});e.View=function(a){this.cid=f.uniqueId("view");this._configure(a||{});this._ensureElement();this.delegateEvents();this.initialize.apply(this,arguments)};var u=/^(\S+)\s*(.*)$/,n=["model","collection","el","id","attributes","className","tagName"];f.extend(e.View.prototype,e.Events,{tagName:"div",$:function(a){return g(a,this.el)},initialize:function(){},render:function(){return this},remove:function(){g(this.el).remove();return this},make:function(a, +b,c){a=document.createElement(a);b&&g(a).attr(b);c&&g(a).html(c);return a},delegateEvents:function(a){if(a||(a=this.events))for(var b in f.isFunction(a)&&(a=a.call(this)),g(this.el).unbind(".delegateEvents"+this.cid),a){var c=this[a[b]];if(!c)throw Error('Event "'+a[b]+'" does not exist');var d=b.match(u),e=d[1];d=d[2];c=f.bind(c,this);e+=".delegateEvents"+this.cid;d===""?g(this.el).bind(e,c):g(this.el).delegate(d,e,c)}},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(var b= +0,c=n.length;b=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,c){var b=e(a,c);(d[b]||(d[b]=[])).push(a)});return d};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var e=0,f=a.length;e< +f;){var g=e+f>>1;d(a[g])=0})})};b.difference=function(a,c){return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=H||function(a){if(a!== +Object(a))throw new TypeError("Invalid object");var b=[],d;for(d in a)m.call(a,d)&&(b[b.length]=d);return b};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)b[d]!==void 0&&(a[d]=b[d])});return a};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)? +a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return r(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(m.call(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};b.isArguments=l.call(arguments)=="[object Arguments]"?function(a){return l.call(a)=="[object Arguments]"}: +function(a){return!(!a||!m.call(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"};b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null}; +b.isUndefined=function(a){return a===void 0};b.noConflict=function(){s._=F;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a),function(c){I(c,b[c]=a[c])})};var J=0;b.uniqueId=function(a){var b=J++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g, +interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape,function(a,b){return"',_.escape("+b.replace(/\\'/g,"'")+"),'"}).replace(d.interpolate,function(a,b){return"',"+b.replace(/\\'/g,"'")+",'"}).replace(d.evaluate||null,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g, +"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e(a,b)}};var n=function(a){this._wrapped=a};b.prototype=n.prototype;var u=function(a,c){return c?b(a).chain():a},I=function(a,c){n.prototype[a]=function(){var a=i.call(arguments);G.call(a,this._wrapped);return u(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];n.prototype[a]=function(){b.apply(this._wrapped, +arguments);return u(this._wrapped,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];n.prototype[a]=function(){return u(b.apply(this._wrapped,arguments),this._chain)}});n.prototype.chain=function(){this._chain=true;return this};n.prototype.value=function(){return this._wrapped}}).call(this); diff --git a/planetstack/core/xoslib/xoslib.py b/planetstack/core/xoslib/xoslib.py deleted file mode 100644 index b8866c4..0000000 --- a/planetstack/core/xoslib/xoslib.py +++ /dev/null @@ -1,19 +0,0 @@ -# /opt/planetstack/core/dashboard/views/helloworld.py -import datetime -import os -import sys -import time -import json -from django.http import HttpResponse, HttpResponseServerError, HttpResponseForbidden -from django.views.generic import TemplateView, View -from django.forms.models import model_to_dict -from objects import XOSLIB_OBJECTS - -class XOSLibDataView(View): - def get(self, request, name="hello_world", **kwargs): - if name in XOSLIB_OBJECTS: - result = XOSLIB_OBJECTS[name]().get() - else: - raise ValueError("Unknown object %s" % name) - - return HttpResponse(json.dumps(result), mimetype='application/json') -- 2.43.0