def validate_iid(iid):
pass
def get_action_id(action_name):
pass
def form_error_to_json(view_func):
pass
#http://stackoverflow.com/questions/7075828/make-sqlalchemy-use-date-in-filter-using-postgresql | |
from sqlalchemy import Date, cast | |
from datetime import date | |
my_date = (session.query(MyObject) | |
.filter(cast(MyObject.date_time, Date) == date.today()) | |
.all()) | |
import datetime | |
yestoday = datetime.date.today() - datetime.timedelta(days=1) | |
print yestoday | |
yestoday_datetime = datetime.datetime.combine(yestoday, datetime.time.min) | |
print yestoday_datetime | |
yestoday_datetime = datetime.datetime.combine(yestoday, datetime.time()) | |
print yestoday_datetime |
import time | |
class cached_property(object): | |
'''Decorator for read-only properties evaluated only once within TTL period. | |
src http://wiki.python.org/moin/PythonDecoratorLibrary#Cached_Properties | |
It can be used to created a cached property like this:: | |
import random |
http://stackoverflow.com/questions/13706382/how-to-get-static-files-in-flask-without-url-forstatic-file-name-xxx | |
You can Setup your own route to serve static | |
files. Add this method and update the static path director in the send_from_directory method and your img tag should work. | |
@app.route('/pic/<path:filename>') | |
def send_pic(filename): | |
return send_from_directory('/path/to/static/files', filename) | |
For a production app however, you should setup your server to serve static files directly. |
def validate_iid(iid):
pass
def get_action_id(action_name):
pass
def form_error_to_json(view_func):
pass
#_*_ coding: utf-8 _*_ | |
""" | |
Mutation Tracking | |
http://sqlalchemy.readthedocs.org/en/rel_0_8/orm/extensions/mutable.html | |
JSONColumn | |
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/JSONColumn | |
""" |
Index: home/moo/workspace/django-trunk/docs/request_response.txt | |
=================================================================== | |
--- /home/moo/workspace/django-trunk/docs/request_response.txt (revision 6657) | |
+++ /home/moo/workspace/django-trunk/docs/request_response.txt (working copy) | |
@@ -588,3 +588,29 @@ | |
That takes care of setting ``handler500`` in the current module. As you can see | |
in ``django/conf/urls/defaults.py``, ``handler500`` is set to | |
``'django.views.defaults.server_error'`` by default. | |
+ | |
+Here is example how to log the exception using Python logging API and |
Reflecting All Tables at Once | |
The MetaData object can also get a listing of tables and reflect the full set. This is achieved by using the reflect() method. After calling it, all located tables are present within the MetaData object’s dictionary of tables: | |
meta = MetaData() | |
meta.reflect(bind=someengine) | |
users_table = meta.tables['users'] | |
addresses_table = meta.tables['addresses'] |
if [ -n "$BASH" ] ; then | |
_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | |
_basepath=$(dirname "$_DIR") | |
fi | |
if [ -n "$ZSH_VERSION" ]; then | |
_DIR="$(dirname $(cd -P -- "$(dirname -- "$0")" && pwd -P))" | |
_basepath=$_DIR | |
fi |
def get_count(q): | |
count_q = q.statement.with_only_columns([func.count()]).order_by(None) | |
count = q.session.execute(count_q).scalar() | |
return count | |
q = session.query(TestModel).filter(...).order_by(...) | |
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ... | |
print q.count() |