Skip to content

Instantly share code, notes, and snippets.

View ianjosephwilson's full-sized avatar

Ian Wilson ianjosephwilson

View GitHub Profile
class TrytonServerWrapper(object):
def __init__(self, user_id, session_id, context, target):
self.user_id = user_id
self.session_id = session_id
self.context = context
self.target = target
def __call__(self, *args):
new_args = [self.user_id, self.session_id]
@ndb.transactional(xg=True)
def remove(self, new_rep_id=None):
# Un-assign this rep from all their stores.
stores = Store.query_stores(rep_id = self.key, active=None)
for store in stores:
store.rep_id = new_rep_id
store.put()
self.active = False
self.put()
from pyramid.config import Configurator
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '{url:.*}')
config.scan()
@ianjosephwilson
ianjosephwilson / app.js
Created September 27, 2013 19:57
loading notification
app.config(function($routeProvider, $locationProvider, $httpProvider) {
// ...
$httpProvider.responseInterceptors.push(function ($q, $rootScope) {
return function (promise) {
$rootScope.$broadcast('startLoading');
return promise.then(function (response) {
$rootScope.$broadcast('stopLoading');
return response;
}, function (response) {
$rootScope.$broadcast('stopLoading');
@ianjosephwilson
ianjosephwilson / app.js
Last active December 24, 2015 02:49
loading manager
$httpProvider.responseInterceptors.push(function ($q, LoadingManager) {
return function (promise) {
LoadingManager.startLoading();
return promise.then(function (response) {
LoadingManager.stopLoading();
return response;
}, function (response) {
LoadingManager.stopLoading();
return $q.reject(response);
});
define([], function() {
'use strict';
return function ($scope, $http, $routeParams, $q, $location) {
var warehouseId = $routeParams.warehouseId,
warehouseDeferred = $q.defer(),
locationsDeferred = $q.defer();
// @TODO: Resolve these.
$scope.crumbs = [];
$scope.warehouse = warehouseDeferred.promise;
$scope.locations = locationsDeferred.promise;
@ianjosephwilson
ianjosephwilson / app.js
Created September 9, 2013 22:08
do not route a url with angular while using html5mode, ie. this route should leave angularjs and do a full page load
// ...
// ...
app.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
// ...
$routeProvider.otherwise({
redirectTo: function (params, path, search) {
search = jquery.param(search);
if (search) {
window.location = path + '?' + search;
@ianjosephwilson
ianjosephwilson / __init__.py
Created September 2, 2013 18:24
pyramid save off url in forbidden view
def redirect_if_not_logged_in(request):
if request.user is None:
request.session['original_url'] = request.url
return HTTPFound(location=request.route_url(
request.registry.settings['auth.login_route_name']))
return Forbidden()
def main(global_config, **settings):
#...
from sqlalchemy.ext.declarative import declarative_base
import sqlalchemy as db
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from datetime import datetime
Base = declarative_base()
def set_request_url_info(request, settings):
# Need this to get port included when not 80,443.
request.host = None
request.scheme = settings['scripts.server_scheme']
request.server_name = settings['scripts.server_name']
request.server_port = settings['scripts.server_port']