+++ /dev/null
-from __future__ import absolute_import
-import os, sys
-from celery import Celery
-from django.conf import settings
-
-sys.path.append(os.path.dirname('sandbox'))
-
-# set the default Django settings module for the 'celery' program.
-os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
-
-app = Celery('sandbox')
-
-# Using a string here means the worker will not have to
-# pickle the object when using Windows.
-app.config_from_object('django.conf:settings')
-app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
-# app.conf.update(
-# CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
-# )
-
-@app.task(bind=True)
-def debug_task(self):
- print('Request: {0!r}'.format(self.request))
--- /dev/null
+#!/bin/sh
+
+# paths
+app='/srv/app'
+manage=$app'/manage.py'
+wsgi=$app'/wsgi.py'
+static='/srv/static/'
+media='/srv/media/'
+src='/srv/src/'
+
+# uwsgi params
+port=8000
+processes=8
+threads=8
+autoreload=3
+uid='www-data'
+gid='www-data'
+
+# stating apps
+pip install -U django==1.6.11 django-environ redis django-angular
+pip install -e git+https://github.com/django-haystack/saved_searches.git#egg=saved_searches-2.0.0-alpha
+
+# waiting for other services
+sh $app/deploy/wait.sh
+
+# waiting for available database
+python $app/wait.py
+
+# django init
+python $manage syncdb --noinput
+python $manage migrate --noinput
+python $manage bower_install -- --allow-root
+python $manage collectstatic --noinput
+python $manage telemeta-create-admin-user
+python $manage telemeta-create-boilerplate
+
+if [ $DEBUG = "False" ]
+then
+ python $manage update_index --workers $processes &
+fi
+
+if [ $1 = "--runserver" ]
+then
+ python $manage runserver 0.0.0.0:8000
+else
+ # static files auto update
+ watchmedo shell-command --patterns="*.js;*.css" --recursive \
+ --command='python '$manage' collectstatic --noinput' $src &
+
+ # app start
+ uwsgi --socket :$port --wsgi-file $wsgi --chdir $app --master \
+ --processes $processes --threads $threads \
+ --uid $uid --gid $gid \
+ --py-autoreload $autoreload
+fi
+++ /dev/null
-deb http://ftp.debian.org/debian/ wheezy-backports main contrib non-free
-deb-src http://ftp.debian.org/debian/ wheezy-backports main contrib non-free
-
-deb http://security.debian.org/ wheezy/updates main
-deb-src http://security.debian.org/ wheezy/updates main
-
-deb http://www.deb-multimedia.org wheezy main non-free
-deb http://www.deb-multimedia.org wheezy-backports main
-
-deb http://debian.parisson.com/debian/ wheezy main
-deb-src http://debian.parisson.com/debian wheezy main
-
--- /dev/null
+deb http://ftp.debian.org/debian/ wheezy-backports main contrib non-free
+deb-src http://ftp.debian.org/debian/ wheezy-backports main contrib non-free
+
+deb http://security.debian.org/ wheezy/updates main
+deb-src http://security.debian.org/ wheezy/updates main
+
+deb http://www.deb-multimedia.org wheezy main non-free
+deb http://www.deb-multimedia.org wheezy-backports main
+
+deb http://debian.parisson.com/debian/ wheezy main
+deb-src http://debian.parisson.com/debian wheezy main
+
+++ /dev/null
-#!/bin/sh
-
-# paths
-app='/srv/app'
-manage=$app'/manage.py'
-wsgi=$app'/wsgi.py'
-
-# stating apps
-pip install django-environ redis
-
-# waiting for other services
-sh $app/deploy/wait.sh
-
-# Starting celery worker with the --autoreload option will enable the worker to watch for file system changes
-# This is an experimental feature intended for use in development only
-# see http://celery.readthedocs.org/en/latest/userguide/workers.html#autoreloading
-python $manage celery worker --autoreload -A celery_app
+++ /dev/null
-#!/usr/bin/python
-
-import os, sys
-import argparse
-
-sysvinit_script = """
-#!/bin/sh
-
-### BEGIN INIT INFO
-# Provides: %s
-# Required-Start: docker
-# Required-Stop: docker
-# Default-Start: 2 3 4 5
-# Default-Stop: 0 1 6
-# Short-Description: Docker Services
-### END INIT INFO
-
-set -e
-
-PROJECT_NAME=%s
-YAMLFILE=%s
-OPTS="-f $YAMLFILE -p $PROJECT_NAME"
-UPOPTS="-d --no-recreate --no-build --no-deps"
-
-. /lib/lsb/init-functions
-
-case "$1" in
- start)
- log_daemon_msg "Starting $PROJECT_NAME composition" "$PROJECT_NAME" || true
- if su -c "docker-compose $OPTS up $UPOPTS > /dev/null 2>&1" root ; then
- log_end_msg 0 || true
- else
- log_end_msg 1 || true
- fi
- ;;
-
- stop)
- log_daemon_msg "Stopping $PROJECT_NAME composition" "$PROJECT_NAME" || true
- if su -c "docker-compose $OPTS stop > /dev/null 2>&1" root; then
- log_end_msg 0 || true
- else
- log_end_msg 1 || true
- fi
- ;;
-
- reload|force-reload)
- log_daemon_msg "Reloading $PROJECT_NAME composition" "$PROJECT_NAME" || true
- if docker-compose $OPTS up $UPOPTS > /dev/null 2>&1 ; then
- log_end_msg 0 || true
- else
- log_end_msg 1 || true
- fi
- ;;
-
- restart|try-restart)
- log_daemon_msg "Restarting $PROJECT_NAME composition" "$PROJECT_NAME" || true
- if docker-compose $OPTS stop > /dev/null 2>&1; docker-compose $OPTS up $UPOPTS > /dev/null 2>&1 ; then
- log_end_msg 0 || true
- else
- log_end_msg 1 || true
- fi
- ;;
-
- status)
- docker-compose $OPTS ps && exit 0 || exit $?
- ;;
-
- *)
- log_action_msg "Usage: /etc/init.d/$PROJECT_NAME {start|stop|reload|force-reload|restart|try-restart|status}" || true
- exit 1
- ;;
-esac
-
-exit 0
-"""
-
-systemd_service = """
-[Unit]
-Description=%s composition
-Requires=docker.service
-After=docker.service
-
-[Service]
-ExecStart=%s -f %s up -d
-ExecStop=%s -f %s stop
-
-[Install]
-WantedBy=local.target
-"""
-
-
-class DockerComposeDaemonInstall(object):
-
- vcs_types = ['git', 'svn', 'hg']
- docker = '/etc/init.d/docker'
- docker_compose = '/usr/local/bin/docker-compose'
-
- def __init__(self, path=None, init_type='sysvinit'):
- self.init_type = init_type
-
- self.local_path = os.path.dirname(os.path.realpath(__file__))
- if not path or not os.path.isdir(path):
- self.root = self.get_root(self.local_path)
- else:
- self.root = os.path.abspath(path)
-
- if self.root[-1] == os.sep:
- self.name = self.root.split(os.sep)[-2].lower()
- else:
- self.name = self.root.split(os.sep)[-1].lower()
-
- self.conf = self.root + os.sep + 'docker-compose.yml'
-
- def is_root(self, path):
- content = os.listdir(path)
- for vcs_type in self.vcs_types:
- if '.' + vcs_type in content:
- return True
- return False
-
- def get_root(self, path):
- while not self.is_root(path):
- path = os.sep.join(path.split(os.sep)[:-1])
- if not path:
- raise ValueError('This is not a versioned repository, please give the root directory of the app as the first argument.')
- return path
-
- def install_docker(self):
- if not os.path.exists(self.docker):
- print 'Installing docker first...'
- os.system('wget -qO- https://get.docker.com/ | sh')
- if not os.path.exists(self.docker_compose):
- print 'Installing docker-compose...'
- os.system('pip install docker-compose')
-
- def install_daemon_sysvinit(self):
- service = '/etc/init.d/' + self.name
- print 'Writing sysvinit script in ' + service
- script = sysvinit_script % (self.name, self.name, self.conf)
- f = open(service, 'w')
- f.write(script)
- f.close()
- os.system('chmod 755 ' + service)
- os.system('update-rc.d ' + self.name + ' defaults')
-
- def install_daemon_systemd(self):
- service = '/lib/systemd/system/' + self.name + '.service'
- print 'Writing systemd service in ' + service
- conf = systemd_service % (self.name, self.docker_compose, self.conf, self.docker_compose, self.conf)
- f = open(service, 'w')
- f.write(rules)
- f.close()
- os.system('systemctl enable ' + service)
- os.system('systemctl daemon-reload')
-
- def run(self):
- print 'Installing ' + self.name + ' composition as a daemon...'
- self.install_docker()
- if self.init_type == 'sysvinit':
- self.install_daemon_sysvinit()
- elif self.init_type == 'systemd':
- self.install_daemon_systemd()
- print 'Done'
-
-
-if __name__ == '__main__':
- path = sys.argv[-1]
- install = DockerComposeDaemonInstall(path)
- install.run()
+++ /dev/null
-# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-#
-# The MySQL Community Server configuration file.
-#
-# For explanations see
-# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
-
-[client]
-port = 3306
-socket = /var/run/mysqld/mysqld.sock
-
-[mysqld_safe]
-pid-file = /var/run/mysqld/mysqld.pid
-socket = /var/run/mysqld/mysqld.sock
-nice = 0
-
-[mysqld]
-skip-host-cache
-skip-name-resolve
-user = mysql
-pid-file = /var/run/mysqld/mysqld.pid
-socket = /var/run/mysqld/mysqld.sock
-port = 3306
-basedir = /usr
-datadir = /var/lib/mysql
-tmpdir = /tmp
-lc-messages-dir = /usr/share/mysql
-explicit_defaults_for_timestamp
-
-# Instead of skip-networking the default is now to listen only on
-# localhost which is more compatible and is not less secure.
-#bind-address = 127.0.0.1
-
-#log-error = /var/log/mysql/error.log
-
-# Disabling symbolic-links is recommended to prevent assorted security risks
-symbolic-links=0
-
-# * IMPORTANT: Additional settings that can override those from this file!
-# The files must end with '.cnf', otherwise they'll be ignored.
-#
-!includedir /etc/mysql/conf.d/
+++ /dev/null
-server_tokens off;
-
-server {
- listen 80;
- server_name nginx;
- charset utf-8;
-
- access_log /var/log/nginx/app-access.log;
- error_log /var/log/nginx/app-error.log;
-
- # max upload size
- client_max_body_size 4096M; # adjust to taste
-
- # Django media
- location /media/ {
- alias /srv/media/; # your Django project's media files - amend as required
- }
- # Django static
- location /static {
- alias /srv/static/; # your Django project's static files - amend as required
- }
-
- # phpmyadmin
- location /phpmyadmin/ {
- proxy_pass http://phpmyadmin/;
- #proxy_set_header Host $http_host;
- #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- #proxy_set_header X-Forwarded-Server $http_host;
- #proxy_redirect / /phpmyadmin/;
- #proxy_cookie_path / /phpmyadmin/;
- }
-
- location / {
- uwsgi_pass app:8000;
- include /etc/nginx/uwsgi_params;
- }
-}
--- /dev/null
+server_tokens off;
+
+server {
+ listen 80;
+ server_name nginx;
+ charset utf-8;
+
+ access_log /var/log/nginx/app-access.log;
+ error_log /var/log/nginx/app-error.log;
+
+ # max upload size
+ client_max_body_size 4096M; # adjust to taste
+
+ # phpmyadmin
+ location /phpmyadmin/ {
+ proxy_pass http://phpmyadmin/;
+ #proxy_set_header Host $http_host;
+ #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ #proxy_set_header X-Forwarded-Server $http_host;
+ #proxy_redirect / /phpmyadmin/;
+ #proxy_cookie_path / /phpmyadmin/;
+ }
+
+ location / {
+ uwsgi_pass app:8000;
+ include /etc/nginx/uwsgi_params;
+ }
+}
--- /dev/null
+server_tokens off;
+
+server {
+ listen 80;
+ server_name nginx;
+ charset utf-8;
+
+ access_log /var/log/nginx/app-access.log;
+ error_log /var/log/nginx/app-error.log;
+
+ # max upload size
+ client_max_body_size 4096M; # adjust to taste
+
+ # Django media
+ location /media/ {
+ alias /srv/media/; # your Django project's media files - amend as required
+ }
+ # Django static
+ location /static {
+ alias /srv/static/; # your Django project's static files - amend as required
+ }
+
+ # phpmyadmin
+ location /phpmyadmin/ {
+ proxy_pass http://phpmyadmin/;
+ #proxy_set_header Host $http_host;
+ #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ #proxy_set_header X-Forwarded-Server $http_host;
+ #proxy_redirect / /phpmyadmin/;
+ #proxy_cookie_path / /phpmyadmin/;
+ }
+
+ location / {
+ uwsgi_pass app:8000;
+ include /etc/nginx/uwsgi_params;
+ }
+}
+++ /dev/null
-#!/bin/sh
-
-# paths
-app='/srv/app'
-manage=$app'/manage.py'
-wsgi=$app'/wsgi.py'
-static='/srv/static/'
-media='/srv/media/'
-src='/srv/src/'
-
-# uwsgi params
-port=8000
-processes=8
-threads=8
-autoreload=3
-uid='www-data'
-gid='www-data'
-
-# stating apps
-pip install django-environ redis
-
-# waiting for other services
-sh $app/deploy/wait.sh
-
-# waiting for available database
-python $app/wait.py
-
-# django init
-python $manage syncdb --noinput
-python $manage migrate --noinput
-python $manage bower_install -- --allow-root
-python $manage collectstatic --noinput
-python $manage telemeta-create-admin-user
-python $manage telemeta-create-boilerplate
-
-if [ ! -f $app/.init ]; then
- chown www-data:www-data $media
- python $manage update_index --workers $processes &
- touch $app/.init
-fi
-
-# static files auto update
-watchmedo shell-command --patterns="*.js;*.css" --recursive \
- --command='python '$manage' collectstatic --noinput' $src &
-
-# app start
-uwsgi --socket :$port --wsgi-file $wsgi --chdir $app --master \
- --processes $processes --threads $threads \
- --uid $uid --gid $gid \
- --py-autoreload $autoreload
--- /dev/null
+#!/bin/sh
+
+# paths
+app='/srv/app'
+manage=$app'/manage.py'
+wsgi=$app'/wsgi.py'
+
+# stating apps
+pip install django-environ redis
+
+# waiting for other services
+sh $app/deploy/wait.sh
+
+# Starting celery worker with the --autoreload option will enable the worker to watch for file system changes
+# This is an experimental feature intended for use in development only
+# see http://celery.readthedocs.org/en/latest/userguide/workers.html#autoreloading
+python $manage celery worker --autoreload -A worker
'haystack',
'djangobower',
'djng',
+ 'saved_searches',
)
TEMPLATE_CONTEXT_PROCESSORS = (
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['application/json']
-from celery_app import app
+from worker import app
HAYSTACK_CONNECTIONS = {
'default': {
+++ /dev/null
-# -- MYSQL DATABASE
-
-ENGINE=django.db.backends.mysql
-MYSQL_ROOT_PASSWORD=mysecretpassword
-MYSQL_DATABASE=telemeta
-MYSQL_USER=telemeta
-MYSQL_PASSWORD=mysecretpassword
-
-# -- DJANGO
-
-DEBUG=True
-
-SECRET_KEY=ghv8us2587n97dq&w$c((o5rj_$-9#d-8j#57y_a9og8wux1h7
-
-# replace broker by localhost if you start your app outside docker-compose
-BROKER_URL=redis://broker:6379/0
-
-# If this is True, all tasks will be executed locally by blocking until the task returns.
-CELERY_ALWAYS_EAGER=False
--- /dev/null
+from __future__ import absolute_import
+import os, sys
+from celery import Celery
+from django.conf import settings
+
+sys.path.append(os.path.dirname('sandbox'))
+
+# set the default Django settings module for the 'celery' program.
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
+
+app = Celery('sandbox')
+
+# Using a string here means the worker will not have to
+# pickle the object when using Windows.
+app.config_from_object('django.conf:settings')
+app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
+# app.conf.update(
+# CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
+# )
+
+@app.task(bind=True)
+def debug_task(self):
+ print('Request: {0!r}'.format(self.request))
# This file is part of Telemeta.
-# TimeSide is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
-# Telemeta is distributed in the hope that it will be useful,
+# TimeSide is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# GNU Affero General Public License for more details.
-# You should have received a copy of the GNU General Public License
+# You should have received a copy of the GNU Affero General Public License
# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
# Authors:
volumes_from:
- data
env_file:
- - app/sandbox/tm-docker-compose.env
+ - env/prod.env
broker:
image: redis
build: .
volumes:
- ./app/:/srv/app
- - ./telemeta/:/srv/src/telemeta/telemeta
volumes_from:
- data
env_file:
- - app/sandbox/tm-docker-compose.env
- command: /bin/sh deploy/start_app.sh
- ports:
- - "9001:9000"
+ - env/prod.env
+ command: /bin/sh deploy/app.sh
links:
- broker
- db
volumes_from:
- app
env_file:
- - app/sandbox/tm-docker-compose.env
- command: /bin/sh deploy/celery_app.sh
+ - env/prod.env
+ command: /bin/sh deploy/worker.sh
links:
- broker
- db
ports:
- "8000:80"
volumes:
- - ./app/deploy/nginx-app.conf:/etc/nginx/conf.d/default.conf
- - ./var/log/nginx/:/var/log/nginx
+ - ./app/deploy/nginx.conf:/etc/nginx/conf.d/default.conf
volumes_from:
- data
links:
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2015-2016 Parisson SARL
+
+# This file is part of Telemeta.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
+
+# Authors:
+# Guillaume Pellerin <yomguy@parisson.com>
+# Thomas Fillon <thomas@parisson.com>
+
+app:
+ build: .
+
+worker:
+ build: .
--- /dev/null
+# -- MYSQL DATABASE
+
+ENGINE=django.db.backends.mysql
+MYSQL_ROOT_PASSWORD=mysecretpassword
+MYSQL_DATABASE=telemeta
+MYSQL_USER=telemeta
+MYSQL_PASSWORD=mysecretpassword
+
+# -- DJANGO
+
+DEBUG=True
+
+SECRET_KEY=ghv8us2587n97dq&w$c((o5rj_$-9#d-8j#57y_a9og8wux1h7
+
+# replace broker by localhost if you start your app outside docker-compose
+BROKER_URL=redis://broker:6379/0
+
+# If this is True, all tasks will be executed locally by blocking until the task returns.
+CELERY_ALWAYS_EAGER=False
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2015-2016 Parisson SARL
+
+# This file is part of Telemeta.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
+
+# Authors:
+# Guillaume Pellerin <yomguy@parisson.com>
+# Thomas Fillon <thomas@parisson.com>
+
+
+app:
+ volumes:
+ - ./app/:/srv/app
+ - ./telemeta/:/srv/src/telemeta/telemeta
+ env_file:
+ - env/debug.env
+
+worker:
+ env_file:
+ - env/debug.env
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2015-2016 Parisson SARL
+
+# This file is part of Telemeta.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
+
+# Authors:
+# Guillaume Pellerin <yomguy@parisson.com>
+# Thomas Fillon <thomas@parisson.com>
+
+
+app:
+ volumes:
+ - ./app/:/srv/app
+ - ./telemeta/:/srv/src/telemeta/telemeta
+ env_file:
+ - env/debug.env
+ command: /bin/sh deploy/app.sh --runserver
+ ports:
+ - 9000:8000
+
+worker:
+ env_file:
+ - env/debug.env
--- /dev/null
+# -- MYSQL DATABASE
+
+ENGINE=django.db.backends.mysql
+MYSQL_ROOT_PASSWORD=mysecretpassword
+MYSQL_DATABASE=telemeta
+MYSQL_USER=telemeta
+MYSQL_PASSWORD=mysecretpassword
+
+# -- DJANGO
+
+DEBUG=False
+
+SECRET_KEY=ghv8us2587n97dq&w$c((o5rj_$-9#d-8j#57y_a9og8wux1h7
+
+# replace broker by localhost if you start your app outside docker-compose
+BROKER_URL=redis://broker:6379/0
+
+# If this is True, all tasks will be executed locally by blocking until the task returns.
+CELERY_ALWAYS_EAGER=False
-e git+https://github.com/mariocesar/sorl-thumbnail.git@v12.2#egg=sorl-thumbnail-12.2
-e git+https://github.com/Parisson/ebooklib.git#egg=ebooklib-0.16
+-e git+https://github.com/django-haystack/saved_searches.git#egg=saved_searches-2.0.0-alpha
@classmethod
def touch(cls, element, user):
"Create or update a revision"
- revision = cls(element_type=element.element_type, element_id=element.pk,
- user=user, change_type='create')
+ revision = cls(element_type=element.element_type, element_id=element.pk, user=user, change_type='create')
if element.pk:
try:
element.__class__.objects.get(pk=element.pk)
username = ForeignKey(User, related_name="searches", db_column="username")
date = DateTimeField(_('date'), auto_now_add=True)
description = CharField(_('Description'))
- criteria = models.ManyToManyField(Criteria, related_name="search",
- verbose_name=_('criteria'), blank=True, null=True)
+ criteria = models.ManyToManyField(Criteria, related_name="search", verbose_name=_('criteria'), blank=True, null=True)
class Meta(MetaCore):
db_table = 'searches'
ordering = ['-date']
def __unicode__(self):
- return ' - '.join([self.username.username, unicode(self.date),
- ' - '.join([c.key for c in self.criteria.all()])])
-
+ return ' - '.join([self.username.username, unicode(self.date), ' - '.join([c.key for c in self.criteria.all()])])
self.type = type
self.form_class = HaySearchForm
self.selected_facet = self.selected_facet_list(request.GET.getlist('selected_facets', ['a']))
+ print(self.selected_facet)
if request.GET.get('results_page'):
self.results_per_page = int(request.GET.get('results_page'))
else:
self.results_per_page = 20
+ self.request = request
+ self.save_search()
return super(HaystackSearch, self).__call__(request)
def get_query(self):
extra['Radio_count'] = self.get_results().narrow('recording_context:Radio').count()
extra['Video_count'] = self.get_results().narrow('media_type:Video').count()
extra['Audio_count'] = self.get_results().narrow('media_type:Audio').count()
+
if self.type == 'item':
extra['type'] = 'item'
elif self.type == 'fonds':
extra['results_page'] = self.results_per_page
return extra
- def save_search(self, request):
- user = request.user
+ def save_search(self):
+ user = self.request.user
if user:
if user.is_authenticated():
search = Search(username=user)
search.save()
- if criteria:
- for key in criteria.keys():
- value = criteria[key]
- if key == 'ethnic_group':
- try:
- group = EthnicGroup.objects.get(value=value)
- value = group.id
- except:
- value = ''
- criter = Criteria(key=key, value=value)
- criter.save()
- search.criteria.add(criter)
- search.save()
-
+ q = self.get_query()
+ print(q)
+ criteria = Criteria(key=key, value=value)
+ criteria.save()
+ search.criteria.add(criter)
+ search.save()
#def auto_complete(request):
#content = SearchQuerySet().autocomplete(content_auto=request.POST.get('seatch_text', ''))