Skip to content

Instantly share code, notes, and snippets.

@brutus
brutus / validators.py
Last active August 29, 2015 14:20
Django DateTime Validator
from django.core.exceptions import ValidationError
from django.utils.deconstruct import deconstructible
@deconstructible
class DateValidator():
"""
Überprüft ob *ein Datum* vor oder nach einem gegebenen anderen Datum liegt.
@brutus
brutus / invoke.yaml
Last active August 29, 2015 14:20
Invoke YAML loading trouble
deployments:
testing:
host: xyz.domain.tld
user: username
destination: /home/username/html/misc/path/
sources:
- index.html
- img
@brutus
brutus / tasks.py
Created October 12, 2014 23:19
A collection of tasks for *Invoke* to set up a Django project with Gunicorn on Uberspace.
# -*- coding: UTF-8 -*-
"""
A collection of tasks for `Invoke`_ to help setting up a `Django`_ project
with `Gunicorn`_ on `Uberspace`_ accounts.
All information for this script has to be set in a JSON file
called ``settings.json`` in the same directory like this::
{
# -*- coding: UTF-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
from django.db import models
from django.db.models.query import QuerySet
from django.core.urlresolvers import reverse
from django.utils.timezone import now
from django.utils.encoding import python_2_unicode_compatible

Here is the query I use to get the data:

q = db.query(Stat, Song, Commit).join(Song).join(Commit)

Well, I actually use something like db.query(Stat.rating, Stat.play_count, Song.path, ....

Now I can filter the results like this:

if user:
  q = q.filter(Commit.user == user)
songcommits_table = Table(
'songcommits', Base.metadata,
Column('commit_id', Integer, ForeignKey('commits.commit_id')),
Column('song_id', Integer, ForeignKey('songs.song_id'))
)
class Commit(Base):
__tablename__ = 'commits'
CREATE TABLE songs (
song_id INTEGER NOT NULL,
path VARCHAR(250) NOT NULL CHECK (TRIM(path) <> ''),
PRIMARY KEY (song_id)
);
CREATE TABLE commits (
commit_id INTEGER NOT NULL,
user VARCHAR(24) NOT NULL CHECK (TRIM(user) <> ''),
device VARCHAR(48) NOT NULL CHECK (TRIM(device) <> ''),
[pep8]
ignore = E111,E121,E127,E128,E501
max-line-length = 78
DPI scale: 1
startup, version: 3047 linux x64 channel: stable
executable: /opt/sublime_text/sublime_text
working dir: /home/brutus
packages path: /home/brutus/Dokumente/.config/sublime-text-3/Packages
state path: /home/brutus/Dokumente/.config/sublime-text-3/Local
hardware concurrency: 4
zip path: /opt/sublime_text/Packages
zip path: /home/brutus/Dokumente/.config/sublime-text-3/Installed Packages
found 7 files for base name Default.sublime-keymap
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
lvm2
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 584 kB of archives.
After this operation, 1182 kB of additional disk space will be used.
Get:1 http://archive.raspbian.org/raspbian/ wheezy/main lvm2 armhf 2.02.95-7+rpi1 [584 kB]
Fetched 584 kB in 1s (577 kB/s)
Selecting previously unselected package lvm2.