- Zips of the haikus, report
- Source on GitHub
+
### Models
- User
Which resolves problems with the env's `site-packages` dir not getting picked up recursively.
+To do this automatically in ipython, I do a little work on startup. In my `ipython_config.py` file,
+in `c.TerminalIPythonApp.exec_lines` I have (among many other things) an import for
+a module `dsc_ipython` where I keep all my ipython specific code, including:
+
+````python
+import os, sys
+from os.path import isfile, join, relpath, abspath
+
+def activate_virtual_env(base=None, dirnames=None, override=False):
+ """ Introspects whether there's an inactive virtual environment here,
+ and if so, activates it.
+
+ - `base` -- Path at which to search.
+ Default: `os.getcwd()`
+ - `dirnames` -- Iterable of directory names to search for env activation file.
+ Default: `('.env', '.virtualenv', 'env', 'virtualenv',)`
+ - `override` -- Whether to clobber an existing environment if detected.
+ Default: False
+ """
+ if base is None: base = os.getcwd()
+ if dirnames is None: dirnames = ('.', '.env', '.virtualenv', 'env', 'virtualenv',)
+
+ # Don't auto-activate if we've already got a virtual env
+ if 'VIRTUAL_ENV' in os.environ:
+ sys.stderr.write('Existing Virtual Environment detected (%s) ... ' % os.environ['VIRTUAL_ENV'])
+ if not override:
+ sys.stderr.write('Aborting!\n')
+ return False
+ sys.stderr.write('Overriding!\n')
+
+ for env in dirnames:
+ activate_file = abspath(join(base, env, 'bin/activate_this.py'))
+ if not isfile(activate_file):
+ continue
+
+ sys.stderr.write('Found Virtual Environment (%s) ... ' % relpath(join(base, env)))
+ execfile(activate_file, dict(__file__=activate_file))
+ sys.stderr.write('Activated!\n')
+ return True
+
+
+# automatically check on startup, using defaults
+activate_virtual_env()
+
+````
+
+
+
## Notes
# likes = db.Table('likes',
# Column('user_id', Integer, ForeignKey('user.id')),
# Column('target_id', Integer, ForeignKey('target.id')),
-# Column('ctime', DateTime, default=func.now()),
# )
# tags2haikus = db.Table('tags',
"A polymorphic pointer to a Comment, Haiku, or Section."
id = Column(Integer, primary_key=True)
+
class Section(db.Model):
"A chunk of the Report. May represent a chapter/section node, or a paragraph of text."
id = Column(Integer, primary_key=True)
text = Column(Text())
parent = relationship('Section', backref=backref('children', lazy='dynamic'))
+
class Haiku(db.Model):
id = Column(Integer, primary_key=True)
text = Column(Text())
context = relationship('Section', backref=backref('haikus' lazy='dynamic'))
start = Column(Integer) # character index into the section where this haiku begins
+
class Like(db.Model):
id = Column(Integer, primary_key=True)
user = relationship('User', backref=backref('likes', lazy='dynamic'))
target = relationship('Target')
ctime = Column(DateTime, default=func.now())
+
class Comment(TimestampMixin, db.Model):
id = Column(Integer, primary_key=True)
target = relationship('Target')
approved = Column(Boolean) # spam filter approval
deleted = Column(Boolean)
+
class Tag(db.Model):
id = Column(Integer, primary_key=True)
name = Column(String(120), unique=True)
# Column('haiku_id', Integer, ForeignKey('haiku.id')),
# )
+
class User(TimestampMixin, db.Model):
id = Column(Integer, primary_key=True)
username = Column(String(30), unique=True)
# verification_token = Column(String(60))
# comments
- # likes
+ # likes = relationship('Target', secondary=likes, backref=backref('tags', lazy='dynamic'))
+
# tags = relationship('UserTag')
--- a/crisishaiku/views.py
-SQLALCHEMY_DATABASE_URI = 'sqlite:///var/haikus.db'
-TWITTER_CONSUMER_KEY = 'tQww8eCQbbtF12hHPTJA',
-TWITTER_CONSUMER_SECRET = 'OE9AIRTkxWTBJU88PJjqGI4soC6k0pUOtrRur0Q8d4w',
+SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/haiku.db'
+TWITTER_CONSUMER_KEY = 'tQww8eCQbbtF12hHPTJA'
+TWITTER_CONSUMER_SECRET = 'OE9AIRTkxWTBJU88PJjqGI4soC6k0pUOtrRur0Q8d4w'