Paul's Programming Notes     Archive     Feed     Github

NULL values excluded from NOT IN - SQLAlchemy+SQLite

Solution: AND column IS NOT NULL

Example: query.filter(or_(~self.column.in_(value), self.column == None))

This thread explains "SQL Server in treating NULL as a value": http://stackoverflow.com/questions/11491831/null-values-are-excluded-why

Guide To Syncing Fork With Original Project

https://help.github.com/articles/syncing-a-fork/

From my fork, I ran these commands:

  1. git remote add upstream https://github.com/mrjoes/flask-admin.git
  2. git fetch upstream
  3. git merge upstream/master
  4. git push
Create new branch and sync with upstream (change the bolded text):
  1. git remote add upstream https://github.com/mrjoes/flask-admin.git
  2. git fetch upstream
  3. git checkout -b issue_xxxx upstream/master
https://docs.djangoproject.com/en/1.6/internals/contributing/writing-code/working-with-git/#working-on-a-ticket

Configuring Notepad++ For Python

On the Settings->"Preferences", "Tab Settings" tab, I set "[Default]" at Tab size: 8, uncheck Replace by space; and set "Python" to uncheck Use default value, Tab size: 4, check Replace by space. This causes inserts into a python source to use 4 spaces for indents, and indent with spaces instead of tabs. 
If I end up with any tabs in the source, I use Edit->Blank Operations->TAB to Space to convert them. I also clean up trailing blanks with Edit->Blank Operations->Trim Trailing Space. 
I install and use the pep8 package to verify standard formatting.
http://www.reddit.com/r/Python/comments/2mfrn6/python_in_notepad/cm3tdj5

Redirecting From Within Helper Functions - Flask

from flask import Flask, redirect
from werkzeug.routing import RoutingException, HTTPException
app = Flask(__name__)
@app.route('/')
def hello_world():
def helper_function():
# Attempt #1
# this obviously won't work: return redirect('www.google.com')
# the program would just return 'Hello World!'
# Attempt #2
# THIS IS PERMANENT!: raise RequestRedirect('example2')
# your browser will cache the status 301 and ALWAYS redirect
# explanation: http://stackoverflow.com/a/16371787/1364191
# Attempt #3
class RequestRedirect(HTTPException, RoutingException):
"""Raise if the map requests a redirect. This is for example the case if
`strict_slashes` are activated and an url that requires a trailing slash.
The attribute `new_url` contains the absolute destination url.
The attribute `code` is returned status code.
"""
def __init__(self, new_url, code=301):
RoutingException.__init__(self, new_url)
self.new_url = new_url
self.code = code
def get_response(self, environ):
return redirect(self.new_url, self.code)
raise RequestRedirect('example3', code=302)
helper_function()
return 'Hello World!'
@app.route('/example2')
def example2():
return 'Example 2'
@app.route('/example3')
def example3():
return 'Example 3'
if __name__ == '__main__':
app.run(host="0.0.0.0", port=9999, debug=True)
view raw redirect.py hosted with ❤ by GitHub