Skip to content

Instantly share code, notes, and snippets.

View ods's full-sized avatar
🇺🇦
Stand with Ukraine

Denis Otkidach ods

🇺🇦
Stand with Ukraine
View GitHub Profile
@ods
ods / sa_dict_collection.py
Created August 28, 2013 15:59
Custom collection replication prove of concept
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy.orm.collections import attribute_mapped_collection
Base = declarative_base()
class Parent(Base):
__tablename__ = 'parents'
id = Column(Integer, primary_key=True)
@ods
ods / replicate_auto_relations.py
Created August 21, 2013 16:44
Automatically discover relationships to replicate
#!/usr/bin/python2.7
import path_config
from app import db_maker
db = db_maker()
from models import admin
from models.admin.base import AdminFrontModel
from sqlalchemy.orm.attributes import manager_of_class
@ods
ods / path_config.py
Created June 20, 2013 13:46
A possible implementation of path_config.py to quickly get path configuration in all subsites of our typical iktomi-based project. This module is placed in code root and symlinked to all subsite roots. A script in subsite root requires just the following single line: import path_config
import os, sys, warnings
def _get_root():
# Only .py file is symbolic link, while compiled module can be placed
# locally
name, ext = os.path.splitext(__file__)
fn = os.path.abspath(name +'.py')
if os.path.islink(fn):
# Symlinks are relative to target, not working dir
fn = os.path.join(os.path.dirname(fn), os.readlink(fn))
@ods
ods / gist:5481419
Created April 29, 2013 12:54
Test case for implicit merge in SQLAlchemy when PK is set in transient object
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, ForeignKey, create_engine
from sqlalchemy.orm import sessionmaker, relationship
Base = declarative_base()
class Parent(Base):
__tablename__ = 'parents'
id = Column(Integer, primary_key=True)
#children = relationship('Child', cascade='all') # doesn't merge
@ods
ods / PublicQuery.py
Last active December 12, 2015 09:49
from sqlalchemy.orm.query import Query
from sqlalchemy.sql import ClauseElement
from sqlalchemy import cast, Boolean
class PublicQuery(Query):
'''
Filters all queries by publicity condition for each participating mapped
class. Attribute "public" of mapped class (if present) should be either
>>> import pdb
>>> pdb.set_trace()
--Return--
> <stdin>(1)<module>()->None
(Pdb) from __future__ import division
(Pdb) 1/2
0
(Pdb) from __future__ import division; 1/2
0.5
@ods
ods / gist:4248725
Created December 10, 2012 06:00
Forbid localization redirects by blogger
<script type='text/javascript'>
(function(){
var oh=window.location.host, nh=oh.replace(/\.\w+$/, '.com');
if (nh!=oh) {
window.location.replace(window.location.href.replace(oh, nh+'/ncr'));
}
})()
</script>
@ods
ods / webob-ctype.diff
Created October 25, 2012 12:26
Webob patch: Fixed condition for adding charset parameter to Content-Type header
diff -r df324794a581 -r c59f41d443d3 third-party/webob/response.py
--- a/third-party/webob/response.py Wed Oct 24 19:28:50 2012 +0400
+++ b/third-party/webob/response.py Thu Oct 25 16:29:29 2012 +0400
@@ -115,16 +115,11 @@
charset = None
if 'charset' in kw:
charset = kw.pop('charset')
- elif self.default_charset:
- if (content_type
+ elif (self.default_charset
@ods
ods / gist:3821453
Created October 2, 2012 17:31
eplant prototype implementation
#!/usr/bin/python
from lxml.builder import ElementMaker
from lxml import etree
class QName(unicode):
def __new__(cls, maker, name):
self = unicode.__new__(cls, maker._namespace+name)