Skip to content
Browse files

Merge branch 'dev' (v0.5.3)

  • Loading branch information...
2 parents 716be19 + b3d0119 commit 70ec2a49b81db988c5e5ee3c0fdbfb8356a3782d dot2code Technologies committed
Showing with 824 additions and 600 deletions.
  1. +6 −0 CHANGES.txt
  2. +6 −0 DEVELOPERS.rst
  3. +3 −2 Makefile
  4. +16 −12 Vagrantfile
  5. +27 −19 extras/init.d/varnish-bans-manager-celerybeat
  6. +33 −30 extras/init.d/varnish-bans-manager-celeryd
  7. +26 −13 extras/init.d/varnish-bans-manager-http
  8. +1 −0 extras/vagrant/files/apt/varnish.list
  9. 0 {vagrant/files → extras/vagrant/files/postfix}/mailname
  10. 0 vagrant/files/postfix-main.cf → extras/vagrant/files/postfix/main.cf
  11. +2 −2 { → extras}/vagrant/files/profile
  12. +204 −0 extras/vagrant/manifests/default.pp
  13. +73 −0 extras/varnish-bans-manager.dev.conf
  14. +12 −0 requirements.txt
  15. +18 −17 setup.py
  16. +0 −140 vagrant/manifests/default.pp
  17. +2 −2 varnish_bans_manager/__init__.py
  18. +2 −2 varnish_bans_manager/core/__init__.py
  19. +5 −4 varnish_bans_manager/core/context_processors.py
  20. +2 −2 varnish_bans_manager/core/forms/__init__.py
  21. +8 −6 varnish_bans_manager/core/forms/bans.py
  22. +8 −8 varnish_bans_manager/core/forms/base.py
  23. +2 −2 varnish_bans_manager/core/forms/caches/__init__.py
  24. +2 −2 varnish_bans_manager/core/forms/caches/groups.py
  25. +2 −2 varnish_bans_manager/core/forms/caches/nodes.py
  26. +2 −2 varnish_bans_manager/core/forms/settings.py
  27. +13 −12 varnish_bans_manager/core/forms/user.py
  28. +2 −2 varnish_bans_manager/core/forms/users.py
  29. +2 −2 varnish_bans_manager/core/helpers/__init__.py
  30. +17 −12 varnish_bans_manager/core/helpers/cli.py
  31. +2 −2 varnish_bans_manager/core/helpers/commands.py
  32. +4 −4 varnish_bans_manager/core/helpers/csv.py
  33. +2 −2 varnish_bans_manager/core/helpers/http.py
  34. +5 −4 varnish_bans_manager/core/helpers/paginator.py
  35. +2 −2 varnish_bans_manager/core/helpers/views.py
  36. +2 −2 varnish_bans_manager/core/management/__init__.py
  37. +2 −2 varnish_bans_manager/core/management/commands/__init__.py
  38. +2 −2 varnish_bans_manager/core/management/commands/groups.py
  39. +2 −2 varnish_bans_manager/core/management/commands/nodes.py
  40. +3 −3 varnish_bans_manager/core/management/commands/start.py
  41. +3 −3 varnish_bans_manager/core/management/commands/upgrade.py
  42. +2 −2 varnish_bans_manager/core/management/commands/users.py
  43. +13 −10 varnish_bans_manager/core/middleware.py
  44. +2 −2 varnish_bans_manager/core/models/__init__.py
  45. +2 −2 varnish_bans_manager/core/models/ban_submission.py
  46. +28 −21 varnish_bans_manager/core/models/base.py
  47. +2 −2 varnish_bans_manager/core/models/cache.py
  48. +2 −2 varnish_bans_manager/core/models/setting.py
  49. +2 −2 varnish_bans_manager/core/models/user.py
  50. +2 −2 varnish_bans_manager/core/models/user_profile.py
  51. +2 −2 varnish_bans_manager/core/patches/__init__.py
  52. +2 −2 varnish_bans_manager/core/patches/base_management_command.py
  53. +2 −2 varnish_bans_manager/core/signals.py
  54. +2 −2 varnish_bans_manager/core/tasks/__init__.py
  55. +9 −8 varnish_bans_manager/core/tasks/bans.py
  56. +9 −7 varnish_bans_manager/core/tasks/base.py
  57. +2 −2 varnish_bans_manager/core/tasks/kombu.py
  58. +2 −2 varnish_bans_manager/core/tasks/sessions.py
  59. +2 −2 varnish_bans_manager/core/tasks/users.py
  60. +2 −2 varnish_bans_manager/core/templatetags/__init__.py
  61. +13 −10 varnish_bans_manager/core/templatetags/vbm_base_helpers.py
  62. +2 −2 varnish_bans_manager/core/templatetags/vbm_form_helpers.py
  63. +19 −18 varnish_bans_manager/core/templatetags/vbm_widget_helpers.py
  64. +2 −2 varnish_bans_manager/core/views/__init__.py
  65. +2 −2 varnish_bans_manager/core/views/bans.py
  66. +2 −2 varnish_bans_manager/core/views/caches/__init__.py
  67. +2 −2 varnish_bans_manager/core/views/caches/base.py
  68. +2 −2 varnish_bans_manager/core/views/caches/groups.py
  69. +2 −2 varnish_bans_manager/core/views/caches/nodes.py
  70. +2 −2 varnish_bans_manager/core/views/settings.py
  71. +3 −3 varnish_bans_manager/core/views/task.py
  72. +4 −4 varnish_bans_manager/core/views/user.py
  73. +3 −3 varnish_bans_manager/core/views/users.py
  74. +3 −2 varnish_bans_manager/filesystem/__init__.py
  75. +8 −6 varnish_bans_manager/filesystem/forms.py
  76. +9 −7 varnish_bans_manager/filesystem/models.py
  77. +2 −2 varnish_bans_manager/filesystem/sendfile_backends/__init__.py
  78. +2 −2 varnish_bans_manager/filesystem/sendfile_backends/nginx.py
  79. +2 −2 varnish_bans_manager/filesystem/sendfile_backends/stream.py
  80. +2 −2 varnish_bans_manager/filesystem/sendfile_backends/xsendfile.py
  81. +2 −2 varnish_bans_manager/filesystem/signals.py
  82. +2 −2 varnish_bans_manager/filesystem/tasks.py
  83. +2 −2 varnish_bans_manager/filesystem/views.py
  84. +6 −6 varnish_bans_manager/runner.py
  85. +20 −23 varnish_bans_manager/settings.py
  86. +2 −2 varnish_bans_manager/templates/varnish-bans-manager/core/bans/expert.html
  87. +87 −84 varnish_bans_manager/urls.py
  88. +3 −3 varnish_bans_manager/wsgi.py
View
6 CHANGES.txt
@@ -1,3 +1,9 @@
+v0.5.3, 27/11/2013
+------------------
+
+ - Improved/updated infrastructure (setup.py, Puppet manifest, etc.).
+ - Blocked django-celery package version (3.0.23).
+
v0.5.2, 25/11/2013
------------------
View
6 DEVELOPERS.rst
@@ -21,6 +21,12 @@ development environment.
$ python varnish_bans_manager/runner.py runserver 0.0.0.0:9000 --nothreading
+ - Initialize database schema::
+
+ $ python varnish_bans_manager/runner.py syncdb
+ $ python varnish_bans_manager/runner.py migrate
+ $ python varnish_bans_manager/runner.py createcachetable cache
+
- Install `Sass <http://sass-lang.com>`_ and `Compass <http://compass-style.org>`_
in your development box (required by ``django-mediagenerator`` asset manager)::
View
5 Makefile
@@ -1,4 +1,4 @@
-VBM_ROOT=.
+VBM_ROOT = $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
sdist: build
@echo
@@ -37,7 +37,8 @@ clone: clean
--exclude="Makefile" --exclude="DEVELOPERS.rst" \
--exclude="vbm.sublime-project" --exclude="vbm.sublime-workspace" \
--exclude="sftp-config.json" \
- "$(VBM_ROOT)" "$(VBM_ROOT)/build/"
+ "$(VBM_ROOT)/" "$(VBM_ROOT)/build/"
clean:
rm -rf "$(VBM_ROOT)/build/"
+ find "$(VBM_ROOT)" -name "*.pyc" -o -name "*.mo" | xargs rm -f
View
28 Vagrantfile
@@ -1,24 +1,28 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
-Vagrant::Config.run do |config|
+Vagrant.configure('2') do |config|
config.vm.box = 'precise64'
- config.vm.host_name = 'dev'
+ config.vm.hostname = 'dev'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
- config.vm.provision :puppet do |puppet|
- puppet.manifests_path = 'vagrant/manifests'
+ config.vm.provider :virtualbox do |vb|
+ vb.customize [
+ 'modifyvm', :id,
+ '--memory', '512',
+ '--name', 'Varnish Bans Manager',
+ ]
end
- config.vm.customize [
- 'modifyvm', :id,
- '--memory', '512',
- '--name', 'Varnish Bans Manager',
- ]
+ config.vm.provision :puppet do |puppet|
+ puppet.manifests_path = 'extras/vagrant/manifests'
+ end
# /etc/hosts
# 192.168.100.102 vbm.d2c.dev
- config.vm.forward_port 9000, 9000
- config.vm.network :hostonly, '192.168.100.102'
- config.vm.network :bridged
+ config.vm.network :forwarded_port, guest: 9000, host: 9000
+ config.vm.network :private_network, ip: '192.168.100.102'
+ config.vm.network :public_network
+
+ config.vm.synced_folder '.', '/vagrant', :nfs => true
end
View
46 extras/init.d/varnish-bans-manager-celerybeat
@@ -12,7 +12,7 @@
##
## Configuration.
##
-VIRTUALENV="/var/www/varnish-bans-manager"
+CELERYBEAT_VIRTUALENV="/var/www/varnish-bans-manager"
CELERYBEAT="python -mvarnish_bans_manager.runner celerybeat"
CELERYBEAT_USER="www-data"
CELERYBEAT_GROUP="www-data"
@@ -22,7 +22,6 @@ CELERYBEAT_LOG_DIR="/var/log/varnish-bans-manager"
CELERYBEAT_LOG_FILE="$CELERYBEAT_LOG_DIR/celerybeat.log"
CELERYBEAT_LOG_LEVEL="WARNING"
CELERYBEAT_SCHEDULE="/var/www/varnish-bans-manager/celerybeat-schedule"
-CELERYBEAT_CHDIR="/tmp"
CELERYBEAT_DAEMON_OPTS="\
--pidfile="$CELERYBEAT_PID_FILE" \
--logfile="$CELERYBEAT_LOG_FILE" \
@@ -30,7 +29,6 @@ CELERYBEAT_DAEMON_OPTS="\
--schedule="$CELERYBEAT_SCHEDULE" \
--uid="$CELERYBEAT_USER" \
--gid="$CELERYBEAT_GROUP" \
- --workdir="$CELERYBEAT_CHDIR" \
--detach"
##
@@ -62,7 +60,7 @@ wait_pid () {
##
##
##
-start_beat () {
+start_celerybeat () {
echo "Starting celerybeat..."
$CELERYBEAT $CELERYBEAT_DAEMON_OPTS
}
@@ -70,10 +68,11 @@ start_beat () {
##
##
##
-stop_beat () {
+stop_celerybeat () {
echo -n "Stopping celerybeat... "
if [ -f "$CELERYBEAT_PID_FILE" ]; then
wait_pid $(cat "$CELERYBEAT_PID_FILE")
+ rm -f "$CELERYBEAT_PID_FILE"
else
echo "NOT RUNNING" 1>&2
fi
@@ -82,31 +81,40 @@ stop_beat () {
##
##
##
-source "$VIRTUALENV/bin/activate"
-mkdir -p "$CELERYBEAT_PID_DIR"
-chown $CELERYBEAT_USER:$CELERYBEAT_GROUP "$CELERYBEAT_PID_DIR"
-mkdir -p "$CELERYBEAT_LOG_DIR"
-chown $CELERYBEAT_USER:$CELERYBEAT_GROUP "$CELERYBEAT_LOG_DIR"
-cd "$CELERYBEAT_CHDIR"
+restart_celerybeat () {
+ echo "Restarting celerybeat..."
+ stop_celerybeat
+ start_celerybeat
+}
+
+##
+##
+##
+source "$CELERYBEAT_VIRTUALENV/bin/activate"
+mkdir -p "$CELERYBEAT_PID_DIR" "$CELERYBEAT_LOG_DIR"
+chown $CELERYBEAT_USER:$CELERYBEAT_GROUP "$CELERYBEAT_PID_DIR" "$CELERYBEAT_LOG_DIR"
##
##
##
case "$1" in
start)
- start_beat
+ start_celerybeat
;;
+
stop)
- stop_beat
- ;;
- reload|force-reload)
- echo "Use start+stop"
+ stop_celerybeat
;;
+
restart)
- echo "Restarting celery periodic task scheduler"
- stop_beat
- start_beat
+ restart_celerybeat
+ ;;
+
+ reload|force-reload)
+ echo "Use restart" 1>&2
+ exit 1
;;
+
*)
echo "Usage: $0 {start|stop|restart}" 1>&2
exit 64 # EX_USAGE
View
63 extras/init.d/varnish-bans-manager-celeryd
@@ -12,7 +12,7 @@
##
## Configuration.
##
-VIRTUALENV="/var/www/varnish-bans-manager"
+CELERYD_VIRTUALENV="/var/www/varnish-bans-manager"
CELERYD_MULTI="python -mvarnish_bans_manager.runner celeryd_multi"
CELERYD_CTL="python -mvarnish_bans_manager.runner celeryctl"
CELERYD_USER="www-data"
@@ -22,78 +22,81 @@ CELERYD_PID_FILE="$CELERYD_PID_DIR/celeryd.pid"
CELERYD_LOG_DIR="/var/log/varnish-bans-manager"
CELERYD_LOG_FILE="$CELERYD_LOG_DIR/celeryd.log"
CELERYD_LOG_LEVEL="WARNING"
-CELERYD_CMD="-m celery.bin.celeryd_detach"
CELERYD_NODES="w1"
-CELERYD_CHDIR="/tmp"
CELERYD_DAEMON_OPTS="\
--pidfile="$CELERYD_PID_FILE" \
- --logfile="$CELERYD_LOG_FILE" \
- --loglevel="$CELERYD_LOG_LEVEL" \
--uid="$CELERYD_USER" \
--gid="$CELERYD_GROUP" \
- --no-execv \
+ --logfile="$CELERYD_LOG_FILE" \
+ --loglevel="$CELERYD_LOG_LEVEL" \
+ --cmd=-mcelery.bin.celeryd_detach \
--time-limit=300 \
- --workdir="$CELERYD_CHDIR" \
--concurrency=2"
##
##
##
-start_workers () {
- $CELERYD_MULTI start $CELERYD_NODES $CELERYD_DAEMON_OPTS --cmd="$CELERYD_CMD"
+start_celeryd () {
+ echo "Starting celeryd..."
+ $CELERYD start $CELERYD_NODES --app=apw $CELERYD_DAEMON_OPTS
+}
+
+##
+##
+##
+stop_celeryd () {
+ echo "Stopping celeryd..."
+ $CELERYD_MULTI stop $CELERYD_NODES --app=apw --pidfile="$CELERYD_PID_FILE"
+ rm -f "$CELERYD_PID_FILE"
}
##
##
##
-restart_workers () {
- $CELERYD_MULTI restart $CELERYD_NODES $CELERYD_DAEMON_OPTS --cmd="$CELERYD_CMD"
+restart_celeryd () {
+ echo "Restarting celeryd..."
+ $CELERYD_MULTI restart $CELERYD_NODES --app=apw $CELERYD_DAEMON_OPTS
}
##
##
##
-stop_workers () {
- $CELERYD_MULTI stop $CELERYD_NODES --pidfile="$CELERYD_PID_FILE"
+status_celeryd () {
+ $CELERYD_CTL status $CELERYD_CTL_OPTS
}
##
##
##
-source "$VIRTUALENV/bin/activate"
-mkdir -p "$CELERYD_PID_DIR"
-chown $CELERYD_USER:$CELERYD_GROUP "$CELERYD_PID_DIR"
-mkdir -p "$CELERYD_LOG_DIR"
-chown $CELERYD_USER:$CELERYD_GROUP "$CELERYD_LOG_DIR"
-cd "$CELERYD_CHDIR"
+source "$CELERYD_VIRTUALENV/bin/activate"
+mkdir -p "$CELERYD_PID_DIR" "$CELERYD_LOG_DIR"
+chown $CELERYD_USER:$CELERYD_GROUP "$CELERYD_PID_DIR" "$CELERYD_LOG_DIR"
##
##
##
case "$1" in
start)
- start_workers
+ start_celeryd
;;
stop)
- stop_workers
+ stop_celeryd
;;
- reload|force-reload)
- echo "Use restart"
+ restart)
+ restart_celeryd
;;
- status)
- $CELERYD_CTL status $CELERYD_CTL_OPTS
+ reload|force-reload)
+ echo "Use restart" 1>&2
+ exit 1
;;
- restart)
- restart_workers
+ status)
+ status_celeryd
;;
- try-restart)
- restart_workers
- ;;
*)
echo "Usage: $0 {start|stop|restart|status}" 1>&2
exit 64 # EX_USAGE
View
39 extras/init.d/varnish-bans-manager-http
@@ -12,16 +12,17 @@
##
## Configuration.
##
-VIRTUALENV="/var/www/varnish-bans-manager"
+HTTP_VIRTUALENV="/var/www/varnish-bans-manager"
HTTP="varnish-bans-manager start"
HTTP_USER="www-data"
HTTP_GROUP="www-data"
HTTP_PID_DIR="/var/run/varnish-bans-manager"
HTTP_PID_FILE="$HTTP_PID_DIR/http.pid"
+HTTP_LOG_DIR="/var/log/varnish-bans-manager"
HTTP_DAEMON_OPTS="\
- --pid "$HTTP_PID_FILE" \
- --user "$HTTP_USER" \
- --group "$HTTP_GROUP" \
+ --pid="$HTTP_PID_FILE" \
+ --user="$HTTP_USER" \
+ --group="$HTTP_GROUP" \
--daemon"
##
@@ -65,6 +66,7 @@ stop_http () {
echo -n "Stopping HTTP... "
if [ -f "$HTTP_PID_FILE" ]; then
wait_pid $(cat "$HTTP_PID_FILE")
+ rm -f "$HTTP_PID_FILE"
else
echo "NOT RUNNING" 1>&2
fi
@@ -73,10 +75,18 @@ stop_http () {
##
##
##
-source "$VIRTUALENV/bin/activate"
-mkdir -p "/var/run/varnish-bans-manager"
-chown $HTTP_USER:$HTTP_GROUP "$HTTP_PID_DIR"
+restart_http () {
+ echo "Restarting HTTP..."
+ stop_http
+ start_http
+}
+##
+##
+##
+source "$HTTP_VIRTUALENV/bin/activate"
+mkdir -p "$HTTP_PID_DIR" "$HTTP_LOG_DIR"
+chown $HTTP_USER:$HTTP_GROUP "$HTTP_PID_DIR" "$HTTP_LOG_DIR"
##
##
@@ -85,17 +95,20 @@ case "$1" in
start)
start_http
;;
+
stop)
stop_http
;;
- reload|force-reload)
- echo "Use start+stop"
- ;;
+
restart)
- echo "Restarting HTTP frontend daemon"
- stop_http
- start_http
+ restart_http
;;
+
+ reload|force-reload)
+ echo "Use restart" 1>&2
+ exit 1
+ ;;
+
*)
echo "Usage: $0 {start|stop|restart}" 1>&2
exit 64 # EX_USAGE
View
1 extras/vagrant/files/apt/varnish.list
@@ -0,0 +1 @@
+deb http://repo.varnish-cache.org/ubuntu/ precise varnish-3.0
View
0 vagrant/files/mailname → extras/vagrant/files/postfix/mailname
File renamed without changes.
View
0 vagrant/files/postfix-main.cf → extras/vagrant/files/postfix/main.cf
File renamed without changes.
View
4 vagrant/files/profile → extras/vagrant/files/profile
@@ -4,7 +4,7 @@ if [ -n "$BASH_VERSION" ]; then
fi
fi
-export VARNISH_BANS_MANAGER_CONF="/vagrant/varnish-bans-manager.conf"
+export VARNISH_BANS_MANAGER_CONF="/vagrant/extras/varnish-bans-manager.dev.conf"
export YUICOMPRESSOR_PATH="/usr/share/yui-compressor/yui-compressor.jar"
-source $HOME/.virtualenvs/varnish-bans-manager/bin/activate
+source $HOME/virtualenv/bin/activate
View
204 extras/vagrant/manifests/default.pp
@@ -0,0 +1,204 @@
+Exec {
+ path => ['/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/', '/usr/local/bin']
+}
+
+class configuration {
+ $mysql_db_name = 'varnish_bans_manager'
+ $mysql_user = 'bob'
+ $mysql_password = 's3cr3t'
+}
+
+class system-update {
+ Class['configuration'] -> Class['system-update']
+
+ exec {'apt-get-update':
+ user => 'root',
+ command => 'apt-get update',
+ }
+
+ package {['python', 'python-pip', 'curl', 'mysql-server', 'mysql-client', 'rubygems', 'python-dev', 'libmysqlclient-dev', 'libjpeg8', 'libjpeg62-dev', 'libfreetype6', 'libfreetype6-dev', 'zlib1g-dev', 'yui-compressor', 'gettext', 'postfix', 'mailutils']:
+ ensure => present,
+ require => Exec['apt-get-update'],
+ }
+
+ file {'/usr/lib/libjpeg.so':
+ ensure => link,
+ mode => 0644,
+ owner => 'root',
+ group => 'root',
+ target => $architecture ? {
+ 'i386' => '/usr/lib/i386-linux-gnu/libjpeg.so',
+ default => '/usr/lib/x86_64-linux-gnu/libjpeg.so',
+ },
+ }
+
+ file {'/usr/lib/libfreetype.so':
+ ensure => link,
+ mode => 0644,
+ owner => 'root',
+ group => 'root',
+ target => $architecture ? {
+ 'i386' => '/usr/lib/i386-linux-gnu/libfreetype.so',
+ default => '/usr/lib/x86_64-linux-gnu/libfreetype.so',
+ },
+ }
+
+ file {'/usr/lib/libz.so':
+ ensure => link,
+ mode => 0644,
+ owner => 'root',
+ group => 'root',
+ target => $architecture ? {
+ 'i386' => '/usr/lib/i386-linux-gnu/libz.so',
+ default => '/usr/lib/x86_64-linux-gnu/libz.so',
+ },
+ }
+}
+
+class virtualenv {
+ Class['system-update'] -> Class['virtualenv']
+
+ package {['virtualenv']:
+ ensure => 'installed',
+ provider => 'pip',
+ }
+
+ exec {'create-virtualenv':
+ creates => '/home/vagrant/virtualenv/',
+ user => 'vagrant',
+ command => 'virtualenv /home/vagrant/virtualenv',
+ require => Package['virtualenv'],
+ }
+
+ exec {'install-virtualenv-dependencies':
+ creates => '/home/vagrant/.vagrant.install-virtualenv-dependencies',
+ user => 'vagrant',
+ provider => 'shell',
+ command => '. /home/vagrant/virtualenv/bin/activate && pip install MySQL-python -r /vagrant/requirements.txt && touch /home/vagrant/.vagrant.install-virtualenv-dependencies',
+ require => Exec['create-virtualenv'],
+ timeout => 0,
+ }
+}
+
+class mysql {
+ Class['system-update'] -> Class['mysql']
+
+ service {['mysql']:
+ enable => true,
+ ensure => running,
+ }
+
+ exec {'set-mysql-root-password':
+ user => 'vagrant',
+ unless => "mysqladmin -uroot -p${configuration::mysql_password} status",
+ command => "mysqladmin -uroot password ${configuration::mysql_password}",
+ require => Service['mysql'],
+ }
+
+ exec {'create-mysql-db':
+ user => 'vagrant',
+ unless => "mysql -u${configuration::mysql_user} -p${configuration::mysql_password} ${configuration::mysql_db_name}",
+ command => "mysql -uroot -p${configuration::mysql_password} -e \"CREATE DATABASE ${configuration::mysql_db_name}; CREATE USER '${configuration::mysql_user}'@'localhost' IDENTIFIED BY '${configuration::mysql_password}'; GRANT ALL PRIVILEGES ON ${configuration::mysql_db_name}.* TO '${configuration::mysql_user}'@'localhost';\"",
+ require => Exec['set-mysql-root-password'],
+ }
+}
+
+class varnish {
+ Class['system-update'] -> Class['varnish']
+
+ exec {'add-varnish-apt-key':
+ user => 'root',
+ creates => '/home/vagrant/.vagrant.add-varnish-apt-key',
+ command => 'curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add - && touch /home/vagrant/.vagrant.add-varnish-apt-key',
+ }
+
+ file {'/etc/apt/sources.list.d/varnish.list':
+ ensure => present,
+ mode => 0644,
+ owner => 'root',
+ group => 'root',
+ source => '/vagrant/extras/vagrant/files/apt/varnish.list',
+ require => Exec['add-varnish-apt-key'],
+ }
+
+ exec {'apt-get-update-varnish':
+ user => 'root',
+ creates => '/usr/sbin/varnishd',
+ command => 'apt-get update',
+ require => File['/etc/apt/sources.list.d/varnish.list'],
+ }
+
+ package {'varnish':
+ ensure => present,
+ require => Exec['apt-get-update-varnish'],
+ }
+
+ service {'varnish':
+ enable => true,
+ ensure => running,
+ require => Package['varnish'],
+ }
+}
+
+class postfix {
+ Class['system-update'] -> Class['postfix']
+
+ service {['postfix']:
+ enable => true,
+ ensure => running,
+ }
+
+ file {'/etc/mailname':
+ ensure => present,
+ mode => 0644,
+ owner => 'root',
+ group => 'root',
+ source => '/vagrant/extras/vagrant/files/postfix/mailname',
+ notify => Service['postfix'],
+ }
+
+ file {'/etc/postfix/main.cf':
+ ensure => present,
+ mode => 0644,
+ owner => 'root',
+ group => 'root',
+ source => '/vagrant/extras/vagrant/files/postfix/main.cf',
+ notify => Service['postfix'],
+ }
+}
+
+class user {
+ Class['system-update'] -> Class['user']
+
+ package {['sass', 'compass']:
+ ensure => 'installed',
+ provider => 'gem',
+ }
+
+ file {'/home/vagrant/.profile':
+ ensure => present,
+ mode => 0644,
+ owner => 'vagrant',
+ group => 'vagrant',
+ source => '/vagrant/extras/vagrant/files/profile',
+ }
+
+ file {'/home/vagrant/source':
+ ensure => link,
+ mode => 0644,
+ target => '/vagrant',
+ }
+
+ file {['/vagrant/files']:
+ ensure => directory,
+ mode => 0644,
+ }
+}
+
+include configuration
+include system-update
+include virtualenv
+include mysql
+include varnish
+include postfix
+include user
View
73 extras/varnish-bans-manager.dev.conf
@@ -0,0 +1,73 @@
+# Gunicorn HTTP server settings. Check out Gunicorn documentation
+# (http://docs.gunicorn.org/en/latest/configure.html) for further
+# details and for a full list of options. Note that 'debug' and
+# 'secure_scheme_headers' Gunicorn settings will always be overriden
+# by VBM internal settings.
+[http]
+bind: 0.0.0.0:9000
+worker_class: eventlet
+forwarded_allow_ips: 127.0.0.1
+x_forwarded_for_header: X-FORWARDED-FOR
+
+# SSL settings. Enable SSL only for proxied VBM deployments.
+[ssl]
+enabled: false
+secure_proxy_ssl_header_name: HTTP_X_FORWARDED_PROTO
+secure_proxy_ssl_header_value: https
+
+# Relational database settings. Check out Django documentation for
+# more information about alternative database engines (PostgreSQL,
+# Oracle, etc.).
+[database]
+engine: django.db.backends.mysql
+name: varnish_bans_manager
+user: bob
+password: s3cr3t
+host: 127.0.0.1
+port: 3306
+
+# Filesytem settings. VBM internally generated files and user
+# uploaded files will be stored in some folder inside the
+# 'root' path.
+#
+# Publicly accessible files will be stored under 'root'/public/,
+# so, when using a reverse proxy, remember to setup it to serve
+# those files directly.
+#
+# Files under 'root'/private/ and 'root'/temporary/ require some
+# app-level access control checks. Never serve those files
+# directly from the reverse proxy.
+#
+# Depending on what reverse proxy you are using, you can boost
+# performance using the adequate sendfile backend:
+#
+# nginx: varnish_bans_manager.filesystem.sendfile_backends.nginx
+# Apache: varnish_bans_manager.filesystem.sendfile_backends.xsendfile
+[filesystem]
+root: /vagrant/files/
+sendfile: varnish_bans_manager.filesystem.sendfile_backends.stream
+
+# Mailing settings.
+[email]
+host: 127.0.0.1
+port: 25
+from: noreply@varnish-bans-manager.domain.com
+subject_prefix: [VBM]
+notifications: cabalde@dot2code.com
+
+# i18n settings. English (en) and Spanish (es) are the available
+# languages at the moment.
+[i18n]
+default: en
+
+# Misc settings.
+[misc]
+# Service timezone.
+timezone: Europe/Madrid
+
+# Internal secret key.
+secret_key: Fgebt?qVUNr41mQ9OEmi8)z6yzy&?(>.7kZ+7$9p}Pl|0E=:2qM1aW|VRdMz{_gQ
+
+# For development purposes only. Always keep this value to false, or,
+# even better, remove it from the configuration file.
+development: true
View
12 requirements.txt
@@ -0,0 +1,12 @@
+django >= 1.5,<1.6
+django-celery == 3.0.23
+django-mediagenerator >= 1.11
+django-templated-email >= 0.4.7
+gunicorn >= 0.14.6
+eventlet >= 0.9.17
+simplejson >= 2.1.6
+path.py >= 2.4.1
+ordereddict >= 1.1
+south >= 0.7.6
+pytz
+pil
View
35 setup.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-"""
+'''
Varnish Bans Manager
====================
@@ -11,14 +11,27 @@
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
+import sys
+import os
from setuptools import setup, find_packages
+if sys.version_info < (2, 7):
+ raise Exception('VBM requires Python 2.7 or higher.')
+
+with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')) as file:
+ install_requires = file.read().splitlines()
+
+extra = {}
+
+if sys.version_info[0] == 3:
+ extra['use_2to3'] = True
+
setup(
name='varnish-bans-manager',
- version='0.5.2',
+ version='0.5.3',
author='dot2code Technologies',
author_email='info@dot2code.com',
packages=find_packages(),
@@ -38,18 +51,6 @@
'Intended Audience :: System Administrators',
'Operating System :: OS Independent',
],
- install_requires=[
- "django >= 1.5,<1.6",
- "django-celery >= 3.0.11",
- "django-mediagenerator >= 1.11",
- "django-templated-email >= 0.4.7",
- "gunicorn >= 0.14.6",
- "eventlet >= 0.9.17",
- "simplejson >= 2.1.6",
- "path.py >= 2.4.1",
- "ordereddict >= 1.1",
- "pytz",
- "pil",
- "south >= 0.7.6",
- ],
+ install_requires=install_requires,
+ **extra
)
View
140 vagrant/manifests/default.pp
@@ -1,140 +0,0 @@
-class phase1 {
- exec {'apt-get-update':
- command => '/usr/bin/apt-get update'
- }
-
- package {['python', 'python-pip', 'mysql-server', 'mysql-client', 'rubygems', 'python-dev', 'libmysqlclient-dev', 'libjpeg8', 'libjpeg62-dev', 'libfreetype6', 'libfreetype6-dev', 'zlib1g-dev', 'yui-compressor', 'gettext', 'varnish', 'postfix', 'mailutils']:
- ensure => present,
- require => Exec['apt-get-update'],
- }
-
- file {'/usr/lib/libjpeg.so':
- ensure => link,
- mode => 0644,
- owner => 'root',
- group => 'root',
- target => $architecture ? {
- 'i386' => '/usr/lib/i386-linux-gnu/libjpeg.so',
- default => '/usr/lib/x86_64-linux-gnu/libjpeg.so',
- }
- }
-
- file {'/usr/lib/libfreetype.so':
- ensure => link,
- mode => 0644,
- owner => 'root',
- group => 'root',
- target => $architecture ? {
- 'i386' => '/usr/lib/i386-linux-gnu/libfreetype.so',
- default => '/usr/lib/x86_64-linux-gnu/libfreetype.so',
- },
- }
-
- file {'/usr/lib/libz.so':
- ensure => link,
- mode => 0644,
- owner => 'root',
- group => 'root',
- target => $architecture ? {
- 'i386' => '/usr/lib/i386-linux-gnu/libz.so',
- default => '/usr/lib/x86_64-linux-gnu/libz.so',
- },
- }
-}
-
-class phase2 {
- Class['phase1'] -> Class['phase2']
-
- package {['sass', 'compass']:
- ensure => 'installed',
- provider => 'gem',
- }
-
- package {['virtualenv']:
- ensure => 'installed',
- provider => 'pip',
- }
-
- service {['mysql', 'varnish', 'postfix']:
- enable => true,
- ensure => running,
- }
-
- file {'/etc/mailname':
- ensure => present,
- mode => 0644,
- owner => 'root',
- group => 'root',
- source => '/vagrant/vagrant/files/mailname',
- notify => Service['postfix'],
- }
-
- file {'/etc/postfix/main.cf':
- ensure => present,
- mode => 0644,
- owner => 'root',
- group => 'root',
- source => '/vagrant/vagrant/files/postfix-main.cf',
- notify => Service['postfix'],
- }
-
- $mysql_user = "bob"
- $mysql_password = "s3cr3t"
- $mysql_db = "varnish_bans_manager"
-
- exec {'set-mysql-root-password':
- unless => "mysqladmin -uroot -p$mysql_password status",
- path => ['/bin', '/usr/bin'],
- command => "mysqladmin -uroot password $mysql_password",
- require => Service['mysql'],
- }
-
- exec {'create-mysql-db':
- unless => "/usr/bin/mysql -u${mysql_user} -p${mysql_password} ${mysql_db}",
- path => ['/bin', '/usr/bin'],
- command => "mysql -uroot -p$mysql_password -e \"CREATE DATABASE ${mysql_db}; CREATE USER '${mysql_user}'@'localhost' IDENTIFIED BY '${mysql_password}'; GRANT ALL PRIVILEGES ON ${mysql_db}.* TO '${mysql_user}'@'localhost';\"",
- require => Exec['set-mysql-root-password'],
- }
-
- exec {'create-virtualenv':
- creates => '/home/vagrant/.virtualenvs/varnish-bans-manager/',
- user => 'vagrant',
- path => ['/bin', '/usr/bin', '/usr/local/bin'],
- command => 'mkdir -p /home/vagrant/.virtualenvs; virtualenv /home/vagrant/.virtualenvs/varnish-bans-manager',
- require => Package['virtualenv'],
- }
-
- exec {'install-virtualenv-dependencies':
- path => ['/bin', '/usr/bin'],
- user => 'vagrant',
- provider => 'shell',
- command => '. /home/vagrant/.virtualenvs/varnish-bans-manager/bin/activate; pip install "MySQL-python" "django >= 1.4.5" "django-celery >= 3.0.11" "django-mediagenerator >= 1.11" "django-templated-email >= 0.4.7" "gunicorn >= 0.14.6" "eventlet >= 0.9.17" "simplejson >= 2.1.6" "path.py >= 2.4.1" "ordereddict >= 1.1" "pytz" "pil" "south >= 0.7.6"',
- require => Exec['create-virtualenv'],
- }
-
- file {'/home/vagrant/.profile':
- ensure => present,
- mode => 0644,
- owner => 'vagrant',
- group => 'vagrant',
- source => '/vagrant/vagrant/files/profile',
- }
-
- file {'/home/vagrant/source':
- ensure => link,
- mode => 0644,
- owner => 'vagrant',
- group => 'vagrant',
- target => '/vagrant',
- }
-
- file {['/vagrant/files']:
- ensure => directory,
- mode => 0644,
- owner => 'vagrant',
- group => 'vagrant',
- }
-}
-
-include phase1
-include phase2
View
4 varnish_bans_manager/__init__.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
View
4 varnish_bans_manager/core/__init__.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
View
9 varnish_bans_manager/core/context_processors.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
import simplejson as json
@@ -12,9 +12,10 @@
def messages(request):
- """
+ '''
Returns a lazy 'messages' context variable (JSON string).
- """
+
+ '''
return {'messages': json.dumps(get_messages(request))}
View
4 varnish_bans_manager/core/forms/__init__.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
View
14 varnish_bans_manager/core/forms/bans.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
import re
@@ -25,9 +25,10 @@ class TargetField(BetterChoiceField):
}
def load_choices(self, initial=None, expert=False):
- """
+ '''
Build choices from current available groups and nodes.
- """
+
+ '''
groups = Group.objects.all().order_by('weight', 'created_at')
nodes = Node.objects.all().order_by('weight', 'created_at')
# Add nodes not linked to any group.
@@ -45,9 +46,10 @@ def load_choices(self, initial=None, expert=False):
self.initial = self._build_choice_value(initial)
def clean(self, value):
- """
+ '''
Returns a Cache instance.
- """
+
+ '''
value = super(TargetField, self).clean(value)
if value:
cache = self._parse_choice_value(value)
View
16 varnish_bans_manager/core/forms/base.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.core.exceptions import ValidationError
@@ -19,11 +19,11 @@ def __init__(self, default=None, choices=None, *args, **kwargs):
# Fallback fields are never required. Trying to require them should be
# an error.
kwargs.setdefault('required', False)
- assert not kwargs['required'], "No fallback field can be set as "\
- "required."
+ assert not kwargs['required'], 'No fallback field can be set as '\
+ 'required.'
# Set default value and choices.
- assert default is not None or choices, "All fallback fields should "\
- "provide a default value or/and a non-empty choices list."
+ assert default is not None or choices, 'All fallback fields should '\
+ 'provide a default value or/and a non-empty choices list.'
self.default = choices[0] if default is None else default
self.choices = choices
# Done!
@@ -51,8 +51,8 @@ class FallbackBooleanField(FallbackMixinField, BooleanField):
class SortDirectionField(FallbackCharField):
def __init__(self, *args, **kwargs):
- assert 'choices' not in kwargs, "No custom choices can be set for a"\
- "SortDirectionField"
+ assert 'choices' not in kwargs, 'No custom choices can be set for a'\
+ 'SortDirectionField'
kwargs['choices'] = ['asc', 'desc']
super(SortDirectionField, self).__init__(*args, **kwargs)
View
4 varnish_bans_manager/core/forms/caches/__init__.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
View
4 varnish_bans_manager/core/forms/caches/groups.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django import forms
View
4 varnish_bans_manager/core/forms/caches/nodes.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django import forms
View
4 varnish_bans_manager/core/forms/settings.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.conf import settings
View
25 varnish_bans_manager/core/forms/user.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django import forms
@@ -31,10 +31,10 @@ class LoginForm(forms.Form):
error_messages = {
'invalid_login': _(
- "Please enter a correct e-mail and password. "
- "Note that both fields are case-sensitive."),
+ 'Please enter a correct e-mail and password. '
+ 'Note that both fields are case-sensitive.'),
'inactive': _(
- "This account is inactive."),
+ 'This account is inactive.'),
}
def __init__(self, *args, **kwargs):
@@ -65,8 +65,8 @@ class PasswordResetForm(forms.Form):
"That e-mail address doesn't have an associated "
"user account. Are you sure you've registered?"),
'unusable': _(
- "The user account associated with this e-mail "
- "address cannot reset the password."),
+ 'The user account associated with this e-mail '
+ 'address cannot reset the password.'),
}
def __init__(self, *args, **kwargs):
@@ -74,9 +74,10 @@ def __init__(self, *args, **kwargs):
self.user = None
def clean_email(self):
- """
+ '''
Validates that an active user exists with the given email address.
- """
+
+ '''
email = self.cleaned_data.get('email')
try:
self.user = User.objects.filter(email__iexact=email, is_active=True).order_by('date_joined')[:1].get()
@@ -88,10 +89,10 @@ def clean_email(self):
raise forms.ValidationError(self.error_messages['unknown'])
def save(self, request):
- """
+ '''
Generates a one-use only link for resetting password and sends to the
user.
- """
+ '''
host = request.get_host()
send_templated_mail(
template_name='varnish-bans-manager/core/user/password_reset',
@@ -100,7 +101,7 @@ def save(self, request):
bcc=settings.DEFAULT_BCC_EMAILS,
context={
'name': self.user.first_name or self.user.email,
- 'base_url': "http://%s" % host,
+ 'base_url': 'http://%s' % host,
'reset_url':
(settings.HTTPS_ENABLED and 'https' or 'http') + '://' +
host +
View
4 varnish_bans_manager/core/forms/users.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from urllib import urlencode
View
4 varnish_bans_manager/core/helpers/__init__.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.utils.translation import ugettext_lazy as _
View
29 varnish_bans_manager/core/helpers/cli.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
import re
@@ -14,7 +14,7 @@
class Varnish(Telnet):
- """
+ '''
Simple CLI to access a Varnish cache node management port. See:
- https://www.varnish-cache.org/trac/wiki/CLI
@@ -23,7 +23,8 @@ class Varnish(Telnet):
- https://www.varnish-cache.org/docs/3.0/reference/varnish-cli.html
- https://github.com/justquick/python-varnish
- http://code.google.com/p/pyvarnishmport/
- """
+
+ '''
error_messages = {
'missing_secret': _(
'Cache has requested authentication but a secret key was not provided.'),
@@ -53,22 +54,24 @@ def __init__(self, host, port, name, secret=None, version=30, timeout=5):
})
def ban(self, expression):
- """
+ '''
(ban|purge) field operator argument [&& field operator argument [...]]
Invalidates all documents matching the ban expression.
- """
+
+ '''
self._fetch('%s %s' % (
'purge' if self.version < 30 else 'ban',
expression,
))
def ban_list(self):
- """
+ '''
(ban|purge).list
Fetches the list of bans.
- """
+
+ '''
# Fetch list of bans.
content = self._fetch('%s.list' % (
'purge' if self.version < 30 else 'ban',
@@ -87,11 +90,12 @@ def ban_list(self):
return result
def quit(self):
- """
+ '''
quit
Closes the connection to the Varnish CLI.
- """
+
+ '''
self.close()
def _read(self):
@@ -106,10 +110,11 @@ def _auth(self, secret, content):
self._fetch('auth %s' % response.hexdigest())
def _fetch(self, command):
- """
+ '''
Runs a command on a Varnish cache node and return the result.
Return value is a tuple of ((status, length), content).
- """
+
+ '''
self.write(('%s\n' % command).encode("utf8"))
while 1:
buffer = self.read_until('\n').strip()
View
4 varnish_bans_manager/core/helpers/commands.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.conf import settings
View
8 varnish_bans_manager/core/helpers/csv.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
import csv
@@ -12,11 +12,11 @@
class UnicodeWriter:
- """
+ '''
A CSV writer which will write rows to CSV file "f",
which is encoded in the given encoding.
- """
+ '''
def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwargs):
# Redirect output to a queue
self.queue = cStringIO.StringIO()
View
4 varnish_bans_manager/core/helpers/http.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
import simplejson as json
View
9 varnish_bans_manager/core/helpers/paginator.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.core.paginator import Paginator as BasePaginator
@@ -27,11 +27,12 @@ def page_range_slice(self):
return range(left, right + 1)
def page(self, number):
- """
+ '''
TODO: this method is a copy & paste of supperclass method due to
the poor Django 1.5 implementation. On 1.6, a '_get_page' factory
method is provided to overcome this.
- """
+
+ '''
number = self.validate_number(number)
bottom = (number - 1) * self.per_page
top = bottom + self.per_page
View
4 varnish_bans_manager/core/helpers/views.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.shortcuts import render_to_response
View
4 varnish_bans_manager/core/management/__init__.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
View
4 varnish_bans_manager/core/management/commands/__init__.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
View
4 varnish_bans_manager/core/management/commands/groups.py
@@ -15,12 +15,12 @@ class Command(BaseCommand):
make_option('--id', dest='id', type='int'),
make_option('--name', dest='name'),
)
- help = """Usage,
+ help = '''Usage,
groups --list
groups --add --name <value>
groups --delete --id <value>
- """
+ '''
def handle(self, *args, **options):
# --list
View
4 varnish_bans_manager/core/management/commands/nodes.py
@@ -20,12 +20,12 @@ class Command(BaseCommand):
make_option('--name', dest='name'),
make_option('--group', dest='group', type='int'),
)
- help = """Usage,
+ help = '''Usage,
nodes --list
nodes --add --host <host> --port <port> [--secret-file <value>] [--legacy] [--name <value>] [--group <group>]
nodes --delete --id <value>
- """
+ '''
def handle(self, *args, **options):
# --list
View
6 varnish_bans_manager/core/management/commands/start.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
import multiprocessing
@@ -25,7 +25,7 @@ class Command(BaseCommand):
def handle(self, *args, **options):
# Do any necessary upgrades in the DB.
- print "Doing any required upgrades before service startup..."
+ print 'Doing any required upgrades before service startup...'
call_command('upgrade')
# Run!
View
6 varnish_bans_manager/core/management/commands/upgrade.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.conf import settings
@@ -36,5 +36,5 @@ def _createcachetable(self):
connection = connections[DEFAULT_DB_ALIAS]
# Make sure cache table exists.
if tablename not in connection.introspection.table_names():
- print "Creating %s table ..." % tablename
+ print 'Creating %s table ...' % tablename
call_command('createcachetable', tablename)
View
4 varnish_bans_manager/core/management/commands/users.py
@@ -15,10 +15,10 @@ class Command(BaseCommand):
make_option('--firstname', dest='firstname'),
make_option('--lastname', dest='lastname'),
)
- help = """Usage,
+ help = '''Usage,
users --add [--administrator] --email <value> --password <value> --firstname <value> --lastname <value>
- """
+ '''
def handle(self, *args, **options):
# Check arguments.
View
23 varnish_bans_manager/core/middleware.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
import time
@@ -27,11 +27,12 @@
def _replace_insensitive(string, target, replacement):
- """
+ '''
Similar to string.replace() but case insensitive.
Code borrowed from:
http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html
- """
+
+ '''
no_case = string.lower()
index = no_case.rfind(target.lower())
if index >= 0:
@@ -97,11 +98,12 @@ def process_view(self, request, view_func, view_args, view_kwargs):
class SecurityMiddleware:
- """
+ '''
Extra check to force authentication for all views by default. Therefore, 'login_required'
decorator is not required, but it's recommended (documentation, extra check if this
middleware is disabled, etc.).
- """
+
+ '''
def process_view(self, request, view_func, view_args, view_kwargs):
is_login_required = view_kwargs.pop('login_required', True)
if is_login_required and not request.user.is_authenticated():
@@ -120,8 +122,8 @@ def _redirect(self, request, secure):
url = "%s://%s%s" % (protocol, request.get_host(), request.get_full_path())
if settings.DEBUG and request.method == 'POST':
raise RuntimeError(
- """Django can't perform a redirect while maintaining POST data.
- Please structure your views so that redirects only occur during GETs.""")
+ '''Django can't perform a redirect while maintaining POST data.
+ Please structure your views so that redirects only occur during GETs.''')
if request.is_ajax():
return HttpResponseAjax([commands.redirect(url)])
else:
@@ -283,9 +285,10 @@ def process_response(self, request, response):
class AjaxRedirectMiddleware:
- """
+ '''
Intercepts standard HTTP redirections replacing them by AJAX commands when required.
- """
+
+ '''
def process_response(self, request, response):
if request.is_ajax():
if isinstance(response, HttpResponseRedirect) or \
View
4 varnish_bans_manager/core/models/__init__.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from varnish_bans_manager.core.models.setting import Setting
View
4 varnish_bans_manager/core/models/ban_submission.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.contrib.contenttypes import generic
View
49 varnish_bans_manager/core/models/base.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
import simplejson as json
@@ -18,9 +18,10 @@
class RevisionedQuerySet(models.query.QuerySet):
- """
+ '''
Makes sure revision has not been changed since data was last read from DB.
- """
+
+ '''
class RecordModifiedError(DatabaseError):
pass
@@ -53,12 +54,12 @@ def _update(self, values):
class QuerySet(RevisionedQuerySet, models.query.QuerySet):
- """
+ '''
Custom QuerySet class for our models. Main added functionalities are:
- RevisionField automatic checks during updates.
- """
+ '''
pass
##
@@ -79,9 +80,10 @@ class QuerySet(RevisionedQuerySet, models.query.QuerySet):
class Manager(models.Manager):
- """
+ '''
Custom Manager class for our models.
- """
+
+ '''
use_for_related_fields = True
def get_query_set(self):
@@ -92,9 +94,10 @@ def get_query_set(self):
class Options(object):
- """
+ '''
Custom meta options class for our models.
- """
+
+ '''
_valid_options = ('trackable_field_names',)
def __init__(self, cls, meta):
@@ -114,7 +117,7 @@ def __init__(self, cls, meta):
class ModelBase(models.base.ModelBase):
- """
+ '''
Custom metaclass.
This metaclass parses custom options in VBMMeta and makes
@@ -122,7 +125,8 @@ class ModelBase(models.base.ModelBase):
a similar behaviour than that of the Meta class offered
by Django model classes (inheritance, etc.) but encapsulates
our own custom options for all our models.
- """
+
+ '''
def __init__(cls, name, bases, attrs):
super(ModelBase, cls).__init__(name, bases, attrs)
vbm_meta = attrs.pop('VBMMeta', getattr(cls, 'VBMMeta'))
@@ -150,7 +154,7 @@ def remove_files(cls, sender, instance, **kwargs):
class Model(models.Model):
- """
+ '''
Custom base model class.
Added functionality:
@@ -162,7 +166,8 @@ class Model(models.Model):
updates to work, FileField fields will always be
automatically added to VBMMeta.trackable_field_names.
See Options.__init__
- """
+
+ '''
__metaclass__ = ModelBase
objects = Manager()
@@ -224,9 +229,9 @@ class Meta:
abstract = True
class VBMMeta:
- """
+ '''
Default values for all custom meta options.
- """
+ '''
trackable_field_names = ()
@@ -234,9 +239,10 @@ class VBMMeta:
class RevisionField(models.IntegerField):
- """
+ '''
Revision Field that returns a "unique" revision number for the record.
- """
+
+ '''
default_error_messages = {
'modified': _(
'This item has been updated by other user while you were editing '
@@ -280,11 +286,12 @@ def clean_with_revision(self, *args, **kwargs):
class JSONField(models.Field):
- """
+ '''
Simple JSON field. See:
- https://github.com/bradjasper/django-jsonfield
- """
+
+ '''
__metaclass__ = models.SubfieldBase
def to_python(self, value):
@@ -306,4 +313,4 @@ def get_internal_type(self):
return 'TextField'
-add_introspection_rules([], ["^varnish_bans_manager\.core\.models\.base\.JSONField"])
+add_introspection_rules([], ['^varnish_bans_manager\.core\.models\.base\.JSONField'])
View
4 varnish_bans_manager/core/models/cache.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.contrib.contenttypes import generic
View
4 varnish_bans_manager/core/models/setting.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.db import models
View
4 varnish_bans_manager/core/models/user.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from ordereddict import OrderedDict
View
4 varnish_bans_manager/core/models/user_profile.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
from django.db import models
View
4 varnish_bans_manager/core/patches/__init__.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
-"""
+'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
-"""
+'''
from __future__ import absolute_import
View