diff --git a/colab/accounts/__init__.py b/colab/accounts/__init__.py index e69de29..1ae765e 100644 --- a/colab/accounts/__init__.py +++ b/colab/accounts/__init__.py @@ -0,0 +1,2 @@ + +default_app_config = 'colab.accounts.apps.AccountsConfig' diff --git a/colab/accounts/apps.py b/colab/accounts/apps.py new file mode 100644 index 0000000..f70f7c3 --- /dev/null +++ b/colab/accounts/apps.py @@ -0,0 +1,6 @@ + +from django.apps import AppConfig + + +class AccountsConfig(AppConfig): + name = 'colab.accounts' diff --git a/colab/accounts/forms.py b/colab/accounts/forms.py index f55d13a..c1f4514 100644 --- a/colab/accounts/forms.py +++ b/colab/accounts/forms.py @@ -6,9 +6,9 @@ from django.utils.translation import ugettext_lazy as _ from conversejs.models import XMPPAccount -from accounts.utils import mailman -from super_archives.models import MailingList +from ..super_archives.models import MailingList from .utils.validators import validate_social_account +from .utils import mailman User = get_user_model() diff --git a/colab/accounts/search_indexes.py b/colab/accounts/search_indexes.py index ec13877..6b638f2 100644 --- a/colab/accounts/search_indexes.py +++ b/colab/accounts/search_indexes.py @@ -3,7 +3,7 @@ from haystack import indexes from django.db.models import Count -from badger.utils import get_users_counters +from colab.badger.utils import get_users_counters from .models import User diff --git a/colab/accounts/templatetags/gravatar.py b/colab/accounts/templatetags/gravatar.py index ceff4a8..ff2a0f5 100644 --- a/colab/accounts/templatetags/gravatar.py +++ b/colab/accounts/templatetags/gravatar.py @@ -1,7 +1,7 @@ from django import template -from super_archives.models import EmailAddress +from colab.super_archives.models import EmailAddress register = template.Library() diff --git a/colab/accounts/urls.py b/colab/accounts/urls.py index c9ca9f9..bb026e3 100644 --- a/colab/accounts/urls.py +++ b/colab/accounts/urls.py @@ -4,15 +4,15 @@ from django.conf.urls import patterns, include, url from .views import (UserProfileDetailView, UserProfileUpdateView, ManageUserSubscriptionsView, ChangeXMPPPasswordView) -from accounts import views +from . import views urlpatterns = patterns('', - url(r'^register/$', 'accounts.views.signup', name='signup'), + url(r'^register/$', 'colab.accounts.views.signup', name='signup'), url(r'^change-password/$', ChangeXMPPPasswordView.as_view(), name='change_password'), - url(r'^logout/?$', 'accounts.views.logoutColab', name='logout'), + url(r'^logout/?$', 'colab.accounts.views.logoutColab', name='logout'), url(r'^(?P[\w@+.-]+)/?$', UserProfileDetailView.as_view(), name='user_profile'), diff --git a/colab/accounts/views.py b/colab/accounts/views.py index e1ec516..af3d1b5 100644 --- a/colab/accounts/views.py +++ b/colab/accounts/views.py @@ -22,8 +22,8 @@ from conversejs import xmpp from conversejs.models import XMPPAccount from haystack.query import SearchQuerySet -from super_archives.models import EmailAddress, Message -from search.utils import trans +from colab.super_archives.models import EmailAddress, Message +from colab.search.utils import trans #from proxy.trac.models import WikiCollabCount, TicketCollabCount from .forms import (UserCreationForm, ListsForm, UserUpdateForm, ChangeXMPPPasswordForm) diff --git a/colab/api/resources.py b/colab/api/resources.py index 6a891ce..37f82fa 100644 --- a/colab/api/resources.py +++ b/colab/api/resources.py @@ -6,7 +6,7 @@ from tastypie import fields from tastypie.constants import ALL_WITH_RELATIONS, ALL from tastypie.resources import ModelResource -from super_archives.models import Message, EmailAddress +from colab.super_archives.models import Message, EmailAddress #from proxy.trac.models import Revision, Ticket, Wiki User = get_user_model() diff --git a/colab/api/views.py b/colab/api/views.py index d92b4f8..dc50bc7 100644 --- a/colab/api/views.py +++ b/colab/api/views.py @@ -5,7 +5,7 @@ from django.views.generic import View from django.core.exceptions import ObjectDoesNotExist -from super_archives.models import Message +from colab.super_archives.models import Message class VoteView(View): diff --git a/colab/badger/management/commands/rebuild_badges.py b/colab/badger/management/commands/rebuild_badges.py index 5cbb813..11d6af7 100644 --- a/colab/badger/management/commands/rebuild_badges.py +++ b/colab/badger/management/commands/rebuild_badges.py @@ -3,8 +3,8 @@ from django.core.management.base import BaseCommand, CommandError from haystack.query import SearchQuerySet -from accounts.models import User -from badger.models import Badge +from colab.accounts.models import User +from colab.badger.models import Badge class Command(BaseCommand): diff --git a/colab/badger/management/commands/update_badges.py b/colab/badger/management/commands/update_badges.py index 7c59a44..e75bb8b 100644 --- a/colab/badger/management/commands/update_badges.py +++ b/colab/badger/management/commands/update_badges.py @@ -3,8 +3,8 @@ from django.core.management.base import BaseCommand, CommandError from haystack.query import SearchQuerySet -from accounts.models import User -from badger.models import Badge +from colab.accounts.models import User +from colab.badger.models import Badge import logging diff --git a/colab/badger/utils.py b/colab/badger/utils.py index cee5db9..728b48e 100644 --- a/colab/badger/utils.py +++ b/colab/badger/utils.py @@ -4,7 +4,7 @@ from django.db.models import Count #from proxy.trac.models import (Revision, Ticket, Wiki, # WikiCollabCount, TicketCollabCount) -from accounts.models import User +from colab.accounts.models import User def get_wiki_counters(): diff --git a/colab/colab.template.yaml b/colab/colab.template.yaml new file mode 100644 index 0000000..13dbaaa --- /dev/null +++ b/colab/colab.template.yaml @@ -0,0 +1,53 @@ + +DEBUG: false +TEMPLATE_DEBUG: false + +ADMINS: &admin + - + - John Foo + - john@example.com + - + - Mary Bar + - mary@example.com + +MANAGERS: *admin + +COLAB_FROM_ADDRESS: '"Colab" ' +SERVER_EMAIL: '"Colab" ' + +EMAIL_HOST: localhost +EMAIL_PORT: 25 +EMAIL_SUBJECT_PREFIX: '[colab]' + +SECRET_KEY: '{{ secret_key }}' + +SITE_URL: 'http://www.example.com/' + +ALLOWED_HOSTS: + - example.com + - example.org + - example.net + +CONVERSEJS_ENABLED: false + +CONVERSEJS_AUTO_REGISTER: 'xmpp.example.com' + +DATABASES: + default: + ENGINE: django.db.backends.postgresql_psycopg2 + HOST: localhost + NAME: colab + USER: colab + PASSWORD: colab + +ROBOTS_NOINDEX: false + +# Set to false to disable +RAVEN_DSN: 'http://public:secret@example.com/1' + +PROXIED_APPS: + gitlab: + upstream: 'http://localhost:8090/gitlab/' + trac: + upstream: 'http://localhost:5000/trac/' + diff --git a/colab/colab/__init__.py b/colab/colab/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/colab/colab/__init__.py +++ /dev/null diff --git a/colab/colab/colab.template.yaml b/colab/colab/colab.template.yaml deleted file mode 100644 index 13dbaaa..0000000 --- a/colab/colab/colab.template.yaml +++ /dev/null @@ -1,53 +0,0 @@ - -DEBUG: false -TEMPLATE_DEBUG: false - -ADMINS: &admin - - - - John Foo - - john@example.com - - - - Mary Bar - - mary@example.com - -MANAGERS: *admin - -COLAB_FROM_ADDRESS: '"Colab" ' -SERVER_EMAIL: '"Colab" ' - -EMAIL_HOST: localhost -EMAIL_PORT: 25 -EMAIL_SUBJECT_PREFIX: '[colab]' - -SECRET_KEY: '{{ secret_key }}' - -SITE_URL: 'http://www.example.com/' - -ALLOWED_HOSTS: - - example.com - - example.org - - example.net - -CONVERSEJS_ENABLED: false - -CONVERSEJS_AUTO_REGISTER: 'xmpp.example.com' - -DATABASES: - default: - ENGINE: django.db.backends.postgresql_psycopg2 - HOST: localhost - NAME: colab - USER: colab - PASSWORD: colab - -ROBOTS_NOINDEX: false - -# Set to false to disable -RAVEN_DSN: 'http://public:secret@example.com/1' - -PROXIED_APPS: - gitlab: - upstream: 'http://localhost:8090/gitlab/' - trac: - upstream: 'http://localhost:5000/trac/' - diff --git a/colab/colab/settings.py b/colab/colab/settings.py deleted file mode 100644 index ff14541..0000000 --- a/colab/colab/settings.py +++ /dev/null @@ -1,315 +0,0 @@ -""" -Django settings for colab project. - -For more information on this file, see -https://docs.djangoproject.com/en/1.7/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.7/ref/settings/ -""" - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -import os -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) - -# Used for settings translation -from django.utils.translation import ugettext_lazy as _ - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "{{ secret_key }}" - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -TEMPLATE_DEBUG = True - -ALLOWED_HOSTS = [] - -DATABASE_ROUTERS = [] - -# Application definition - -INSTALLED_APPS = ( - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - - # First app to provide AUTH_USER_MODEL to others - 'accounts', - - # Not standard apps - 'raven.contrib.django.raven_compat', - 'cliauth', - 'django_mobile', - 'django_browserid', - 'conversejs', - 'haystack', - 'hitcounter', - 'i18n_model', - 'mptt', - 'dpaste', - - # Own apps - 'super_archives', - 'api', - 'rss', - 'planet', - 'search', - 'badger', - 'tz', - - # Feedzilla and deps - 'feedzilla', - 'taggit', - 'common', -) - -MIDDLEWARE_CLASSES = ( - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -) - -ROOT_URLCONF = 'colab.urls' - -WSGI_APPLICATION = 'colab.wsgi.application' - -# Internationalization -# https://docs.djangoproject.com/en/1.7/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.7/howto/static-files/ - -STATIC_ROOT = '/usr/share/nginx/colab/static/' -MEDIA_ROOT = '/usr/share/nginx/colab/media/' - -STATIC_URL = '/static/' -MEDIA_URL = '/media/' - - -# Normally you should not import ANYTHING from Django directly -# into your settings, but ImproperlyConfigured is an exception. -from django.core.exceptions import ImproperlyConfigured - - -def get_env_setting(setting): - """ Get the environment setting or return exception """ - try: - return os.environ[setting] - except KeyError: - error_msg = "Set the %s env variable" % setting - raise ImproperlyConfigured(error_msg) - - -# Allow Django runserver to serve SVG files -# https://code.djangoproject.com/ticket/20162 -import mimetypes -mimetypes.add_type('image/svg+xml', '.svg') - -LANGUAGES = ( - ('en', _('English')), - ('pt-br', _('Portuguese')), - ('es', _('Spanish')), -) - -DJANGO_DATE_FORMAT_TO_JS = { - 'pt-br': ('pt-BR', 'dd/MM/yyyy'), - 'es': ('es', 'dd/MM/yyyy'), -} - -LANGUAGE_CODE = 'en' - -# The absolute path to the folder containing the attachments -ATTACHMENTS_FOLDER_PATH = '/mnt/trac/attachments/' - -# ORDERING_DATA receives the options to order for as it's keys and a dict as -# value, if you want to order for the last name, you can use something like: -# 'last_name': {'name': 'Last Name', 'fields': 'last_name'} inside the dict, -# you pass two major keys (name, fields) -# The major key name is the name to appear on the template -# the major key fields it show receive the name of the fields to order for in -# the indexes - -ORDERING_DATA = { - 'latest': { - 'name': _(u'Recent activity'), - 'fields': ('-modified', '-created'), - }, - 'hottest': { - 'name': _(u'Relevance'), - 'fields': None, - }, -} - - -# File type groupings is a tuple of tuples containg what it should filter, -# how it should be displayed, and a tuple of which mimetypes it includes -FILE_TYPE_GROUPINGS = ( - ('document', _(u'Document'), - ('doc', 'docx', 'odt', 'otx', 'dotx', 'pdf', 'ott')), - ('presentation', _(u'Presentation'), ('ppt', 'pptx', 'odp')), - ('text', _(u'Text'), ('txt', 'po', 'conf', 'log')), - ('code', _(u'Code'), - ('py', 'php', 'js', 'sql', 'sh', 'patch', 'diff', 'html', '')), - ('compressed', _(u'Compressed'), ('rar', 'zip', 'gz', 'tgz', 'bz2')), - ('image', _(u'Image'), - ('jpg', 'jpeg', 'png', 'tiff', 'gif', 'svg', 'psd', 'planner', 'cdr')), - ('spreadsheet', _(u'Spreadsheet'), - ('ods', 'xls', 'xlsx', 'xslt', 'csv')), -) - -# the following variable define how many characters should be shown before -# a highlighted word, to make sure that the highlighted word will appear -HIGHLIGHT_NUM_CHARS_BEFORE_MATCH = 30 -HAYSTACK_CUSTOM_HIGHLIGHTER = 'colab.utils.highlighting.ColabHighlighter' - -HAYSTACK_CONNECTIONS = { - 'default': { - 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', - 'URL': 'http://localhost:8983/solr/', - } -} - -CACHES = { - 'default': { - 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', - 'LOCATION': '127.0.0.1:11211', - } -} - -DATABASE_ROUTERS = [] - - -TEMPLATE_CONTEXT_PROCESSORS = ( - 'django.contrib.auth.context_processors.auth', - 'django.core.context_processors.debug', - 'django.core.context_processors.i18n', - 'django.core.context_processors.media', - 'django.core.context_processors.static', - 'django.core.context_processors.tz', - 'django.contrib.messages.context_processors.messages', - 'django.core.context_processors.request', - 'django_mobile.context_processors.is_mobile', - 'super_archives.context_processors.mailarchive', - 'proxy.context_processors.proxied_apps', - 'home.context_processors.robots', -) - -MIDDLEWARE_CLASSES = ( - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.locale.LocaleMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'django_mobile.middleware.MobileDetectionMiddleware', - 'django_mobile.middleware.SetFlavourMiddleware', - 'tz.middleware.TimezoneMiddleware', -) - -# Add the django_browserid authentication backend. -AUTHENTICATION_BACKENDS = ( - 'django.contrib.auth.backends.ModelBackend', - 'accounts.auth.ColabBrowserIDBackend', -) - -STATICFILES_DIRS = ( - os.path.join(BASE_DIR, 'static'), -) - -TEMPLATE_DIRS = ( - os.path.join(BASE_DIR, 'templates'), -) - -LOCALE_PATHS = ( - os.path.join(BASE_DIR, 'locale'), -) - -AUTH_USER_MODEL = 'accounts.User' - -from django.contrib.messages import constants as messages -MESSAGE_TAGS = { - messages.INFO: 'alert-info', - messages.SUCCESS: 'alert-success', - messages.WARNING: 'alert-warning', - messages.ERROR: 'alert-danger', -} - -### Feedzilla (planet) -from feedzilla.settings import * -FEEDZILLA_PAGE_SIZE = 5 -FEEDZILLA_SITE_TITLE = _(u'Planet Colab') -FEEDZILLA_SITE_DESCRIPTION = _(u'Colab blog aggregator') - -### Mailman API settings -MAILMAN_API_URL = 'http://localhost:9000' - -### BrowserID / Persona -SITE_URL = 'localhost:8000' -BROWSERID_AUDIENCES = [SITE_URL, SITE_URL.replace('https', 'http')] - - -LOGIN_URL = '/' -LOGIN_REDIRECT_URL = '/' -LOGIN_REDIRECT_URL_FAILURE = '/' -LOGOUT_REDIRECT_URL = '/user/logout' -BROWSERID_CREATE_USER = False - -REVPROXY_ADD_REMOTE_USER = True - -## Converse.js settings -# This URL must use SSL in order to keep chat sessions secure -CONVERSEJS_BOSH_SERVICE_URL = SITE_URL + '/http-bind' - -CONVERSEJS_ALLOW_CONTACT_REQUESTS = False -CONVERSEJS_SHOW_ONLY_ONLINE_USERS = True - - -# Tastypie settings -TASTYPIE_DEFAULT_FORMATS = ['json', ] - -# Dpaste settings -DPASTE_EXPIRE_CHOICES = ( - ('onetime', _(u'One Time Snippet')), - (3600, _(u'In one hour')), - (3600 * 24 * 7, _(u'In one week')), - (3600 * 24 * 30, _(u'In one month')), - ('never', _(u'Never')), -) -DPASTE_EXPIRE_DEFAULT = DPASTE_EXPIRE_CHOICES[4][0] -DPASTE_DEFAULT_GIST_DESCRIPTION = 'Gist created from Colab DPaste' -DPASTE_DEFAULT_GIST_NAME = 'colab_paste' -DPASTE_LEXER_DEFAULT = 'text' - -from .utils.conf import load_yaml_settings -locals().update(load_yaml_settings()) - -if locals().get('RAVEN_DSN', False): - RAVEN_CONFIG = { - 'dsn': RAVEN_DSN + '?timeout=30', - } - -for app_label in locals().get('PROXIED_APPS', {}).keys(): - INSTALLED_APPS += ('proxy.{}'.format(app_label),) diff --git a/colab/colab/urls.py b/colab/colab/urls.py deleted file mode 100644 index 6d175c6..0000000 --- a/colab/colab/urls.py +++ /dev/null @@ -1,45 +0,0 @@ -from django.conf.urls import patterns, include, url, static -from django.conf import settings -from django.views.generic import TemplateView -from django.contrib import admin - -from accounts.models import User -from search.forms import ColabSearchForm -from super_archives.models import Message - - -admin.autodiscover() - -urlpatterns = patterns('', - url(r'^$', 'home.views.index', name='home'), - url(r'^robots.txt$', 'home.views.robots', name='robots'), - - url(r'^open-data/$', TemplateView.as_view(template_name='open-data.html'), - name='opendata'), - - url(r'^search/', include('search.urls')), - url(r'^archives/', include('super_archives.urls')), - url(r'^api/', include('api.urls')), - url(r'^rss/', include('rss.urls')), - - url(r'^user/', include('accounts.urls')), # Kept for backwards compatibility - url(r'^signup/', include('accounts.urls')), # (same here) TODO: move to nginx - url(r'^account/', include('accounts.urls')), - - url(r'', include('django_browserid.urls')), - - url(r'^planet/', include('feedzilla.urls')), - - url(r'paste/', include('dpaste.urls.dpaste')), - - # Uncomment the next line to enable the admin: - url(r'^colab/admin/', include(admin.site.urls)), - - url(r'^trac/', include('proxy.trac.urls')), -) - -if settings.DEBUG: - urlpatterns += static.static( - settings.MEDIA_URL, - document_root=settings.MEDIA_ROOT - ) diff --git a/colab/colab/utils/__init__.py b/colab/colab/utils/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/colab/colab/utils/__init__.py +++ /dev/null diff --git a/colab/colab/utils/conf.py b/colab/colab/utils/conf.py deleted file mode 100644 index b73904a..0000000 --- a/colab/colab/utils/conf.py +++ /dev/null @@ -1,32 +0,0 @@ - -import os -import yaml - -from django.core.exceptions import ImproperlyConfigured - - -class InaccessibleYAMLSettings(ImproperlyConfigured): - """Settings YAML is Inaccessible. - - Check if the file exists and if you have read permissions.""" - - -def load_yaml_settings(): - yaml_path = os.getenv('COLAB_SETTINGS', '/etc/colab.yaml') - - if not os.path.exists(yaml_path): - msg = "The yaml file {} does not exist".format(yaml_path) - raise InaccessibleYAMLSettings(msg) - - try: - with open(yaml_path) as yaml_file: - yaml_settings = yaml.load(yaml_file.read()) - except IOError: - msg = ('Could not open settings file {}. Please ' - 'check if the file exists and if user ' - 'has read rights.').format(yaml_path) - raise InaccessibleYAMLSettings(msg) - - return yaml_settings - -yaml_settings = load_yaml_settings() diff --git a/colab/colab/utils/highlighting.py b/colab/colab/utils/highlighting.py deleted file mode 100644 index 8f41b7c..0000000 --- a/colab/colab/utils/highlighting.py +++ /dev/null @@ -1,38 +0,0 @@ -from haystack.utils import Highlighter -from django.conf import settings -from django.utils.html import escape, strip_tags - - -class ColabHighlighter(Highlighter): - def highlight(self, text_block): - self.text_block = escape(strip_tags(text_block)) - highlight_locations = self.find_highlightable_words() - start_offset, end_offset = self.find_window(highlight_locations) - return self.render_html(highlight_locations, start_offset, end_offset) - - def find_window(self, highlight_locations): - """Getting the HIGHLIGHT_NUM_CHARS_BEFORE_MATCH setting - to find how many characters before the first word found should - be removed from the window - """ - - if len(self.text_block) <= self.max_length: - return (0, self.max_length) - - num_chars_before = getattr( - settings, - 'HIGHLIGHT_NUM_CHARS_BEFORE_MATCH', - 0 - ) - - best_start, best_end = super(ColabHighlighter, self).find_window( - highlight_locations - ) - if best_start <= num_chars_before: - best_end -= best_start - best_start = 0 - else: - best_start -= num_chars_before - best_end -= num_chars_before - - return (best_start, best_end) diff --git a/colab/colab/wsgi.py b/colab/colab/wsgi.py deleted file mode 100644 index 02679ab..0000000 --- a/colab/colab/wsgi.py +++ /dev/null @@ -1,14 +0,0 @@ -""" -WSGI config for colab project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/ -""" - -import os -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "colab.settings") - -from django.core.wsgi import get_wsgi_application -application = get_wsgi_application() diff --git a/colab/home/views.py b/colab/home/views.py index 607f756..1dd315d 100644 --- a/colab/home/views.py +++ b/colab/home/views.py @@ -6,11 +6,11 @@ from django.core.cache import cache from django.shortcuts import render from django.http import HttpResponse, Http404 -from search.utils import trans from haystack.query import SearchQuerySet #from proxy.trac.models import WikiCollabCount, TicketCollabCount -from super_archives.models import Thread +from colab.search.utils import trans +from colab.super_archives.models import Thread def index(request): diff --git a/colab/manage.py b/colab/manage.py deleted file mode 100644 index a466007..0000000 --- a/colab/manage.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python -import os -import sys - -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "colab.settings") - - from django.core.management import execute_from_command_line - - execute_from_command_line(sys.argv) diff --git a/colab/proxy/gitlab/__init__.py b/colab/proxy/gitlab/__init__.py index a2b3db3..3000109 100644 --- a/colab/proxy/gitlab/__init__.py +++ b/colab/proxy/gitlab/__init__.py @@ -1,3 +1,3 @@ -default_app_config = 'proxy.gitlab.apps.ProxyGitlabAppConfig' +default_app_config = 'colab.proxy.gitlab.apps.ProxyGitlabAppConfig' diff --git a/colab/proxy/gitlab/apps.py b/colab/proxy/gitlab/apps.py index aea37de..11a6d40 100644 --- a/colab/proxy/gitlab/apps.py +++ b/colab/proxy/gitlab/apps.py @@ -3,5 +3,5 @@ from ..utils.apps import ColabProxiedAppConfig class ProxyGitlabAppConfig(ColabProxiedAppConfig): - name = 'proxy.gitlab' + name = 'colab.proxy.gitlab' verbose_name = 'Gitlab Proxy' diff --git a/colab/proxy/jenkins/__init__.py b/colab/proxy/jenkins/__init__.py index 093a0b1..6bed4f7 100644 --- a/colab/proxy/jenkins/__init__.py +++ b/colab/proxy/jenkins/__init__.py @@ -1,3 +1,3 @@ -default_app_config = 'proxy.jenkins.apps.ProxyJenkinsAppConfig' +default_app_config = 'colab.proxy.jenkins.apps.ProxyJenkinsAppConfig' diff --git a/colab/proxy/jenkins/apps.py b/colab/proxy/jenkins/apps.py index b9fb226..e1e0833 100644 --- a/colab/proxy/jenkins/apps.py +++ b/colab/proxy/jenkins/apps.py @@ -3,5 +3,5 @@ from ..utils.apps import ColabProxiedAppConfig class ProxyJenkinsAppConfig(ColabProxiedAppConfig): - name = 'proxy.jenkins' + name = 'colab.proxy.jenkins' verbose_name = 'Jenkins Proxy' diff --git a/colab/proxy/redmine/__init__.py b/colab/proxy/redmine/__init__.py index 38dd692..256ade1 100644 --- a/colab/proxy/redmine/__init__.py +++ b/colab/proxy/redmine/__init__.py @@ -1,3 +1,3 @@ -default_app_config = 'proxy.redmine.apps.ProxyRedmineAppConfig' +default_app_config = 'colab.proxy.redmine.apps.ProxyRedmineAppConfig' diff --git a/colab/proxy/redmine/apps.py b/colab/proxy/redmine/apps.py index 62382e9..1076304 100644 --- a/colab/proxy/redmine/apps.py +++ b/colab/proxy/redmine/apps.py @@ -3,5 +3,5 @@ from ..utils.apps import ColabProxiedAppConfig class ProxyRedmineAppConfig(ColabProxiedAppConfig): - name = 'proxy.redmine' + name = 'colab.proxy.redmine' verbose_name = 'Redmine Proxy' diff --git a/colab/proxy/trac/__init__.py b/colab/proxy/trac/__init__.py index 5cb7f41..b099423 100644 --- a/colab/proxy/trac/__init__.py +++ b/colab/proxy/trac/__init__.py @@ -1,3 +1,3 @@ -default_app_config = 'proxy.trac.apps.ProxyTracAppConfig' +default_app_config = 'colab.proxy.trac.apps.ProxyTracAppConfig' diff --git a/colab/proxy/trac/apps.py b/colab/proxy/trac/apps.py index 371c253..d9e242f 100644 --- a/colab/proxy/trac/apps.py +++ b/colab/proxy/trac/apps.py @@ -3,5 +3,5 @@ from ..utils.apps import ColabProxiedAppConfig class ProxyTracAppConfig(ColabProxiedAppConfig): - name = 'proxy.trac' + name = 'colab.proxy.trac' verbose_name = 'Trac Proxy' diff --git a/colab/proxy/trac/models.py b/colab/proxy/trac/models.py index c71b74d..1343c87 100644 --- a/colab/proxy/trac/models.py +++ b/colab/proxy/trac/models.py @@ -1,12 +1,14 @@ # -*- coding: utf-8 -*- -from django.db import models -from django.conf import settings import os import urllib2 -from accounts.models import User +from django.db import models +from django.conf import settings + from hitcounter.models import HitCounterModelMixin +from colab.accounts.models import User + class Attachment(models.Model, HitCounterModelMixin): url = models.TextField(primary_key=True) diff --git a/colab/proxy/trac/search_indexes.py b/colab/proxy/trac/search_indexes.py index c7c413f..a4c0e97 100644 --- a/colab/proxy/trac/search_indexes.py +++ b/colab/proxy/trac/search_indexes.py @@ -8,7 +8,7 @@ from django.utils.text import slugify from haystack import indexes from haystack.utils import log as logging -from search.base_indexes import BaseIndex +from colab.search.base_indexes import BaseIndex from .models import Attachment, Ticket, Wiki, Revision diff --git a/colab/proxy/trac/signals.py b/colab/proxy/trac/signals.py index 0d477a6..62eb17c 100644 --- a/colab/proxy/trac/signals.py +++ b/colab/proxy/trac/signals.py @@ -3,7 +3,7 @@ from django.db import connections from django.dispatch import receiver from django.db.models.signals import post_save -from accounts.models import User +from colab.accounts.models import User @receiver(post_save, sender=User) diff --git a/colab/rss/feeds.py b/colab/rss/feeds.py index 7bec55f..c17056e 100644 --- a/colab/rss/feeds.py +++ b/colab/rss/feeds.py @@ -6,7 +6,7 @@ from django.utils.translation import ugettext as _ from haystack.query import SearchQuerySet -from super_archives.models import Thread +from colab.super_archives.models import Thread class LatestThreadsFeeds(Feed): diff --git a/colab/search/forms.py b/colab/search/forms.py index 439286e..1b3150f 100644 --- a/colab/search/forms.py +++ b/colab/search/forms.py @@ -8,8 +8,8 @@ from django.utils.translation import ugettext_lazy as _ from haystack.forms import SearchForm from haystack.inputs import AltParser -from accounts.models import User -from super_archives.models import Message, MailingList +from colab.accounts.models import User +from colab.super_archives.models import Message, MailingList class ColabSearchForm(SearchForm): diff --git a/colab/settings.py b/colab/settings.py new file mode 100644 index 0000000..2955515 --- /dev/null +++ b/colab/settings.py @@ -0,0 +1,316 @@ +""" +Django settings for colab project. + +For more information on this file, see +https://docs.djangoproject.com/en/1.7/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.7/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os +BASE_DIR = os.path.dirname(__file__) + +# Used for settings translation +from django.utils.translation import ugettext_lazy as _ + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +TEMPLATE_DEBUG = True + +ALLOWED_HOSTS = [] + +DATABASE_ROUTERS = [] + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # First app to provide AUTH_USER_MODEL to others + 'colab.accounts', + + # Not standard apps + 'cliauth', + 'django_mobile', + 'django_browserid', + 'conversejs', + 'haystack', + 'hitcounter', + 'i18n_model', + 'mptt', + 'dpaste', + + # Own apps + 'colab.home', + 'colab.super_archives', + 'colab.api', + 'colab.rss', + 'colab.planet', + 'colab.search', + 'colab.badger', + 'colab.tz', + + # Feedzilla and deps + 'feedzilla', + 'taggit', + 'common', +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +) + +ROOT_URLCONF = 'colab.urls' + +WSGI_APPLICATION = 'colab.wsgi.application' + +# Internationalization +# https://docs.djangoproject.com/en/1.7/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.7/howto/static-files/ + +STATIC_ROOT = '/usr/share/nginx/colab/static/' +MEDIA_ROOT = '/usr/share/nginx/colab/media/' + +STATIC_URL = '/static/' +MEDIA_URL = '/media/' + + +# Normally you should not import ANYTHING from Django directly +# into your settings, but ImproperlyConfigured is an exception. +from django.core.exceptions import ImproperlyConfigured + + +def get_env_setting(setting): + """ Get the environment setting or return exception """ + try: + return os.environ[setting] + except KeyError: + error_msg = "Set the %s env variable" % setting + raise ImproperlyConfigured(error_msg) + + +# Allow Django runserver to serve SVG files +# https://code.djangoproject.com/ticket/20162 +import mimetypes +mimetypes.add_type('image/svg+xml', '.svg') + +LANGUAGES = ( + ('en', _('English')), + ('pt-br', _('Portuguese')), + ('es', _('Spanish')), +) + +DJANGO_DATE_FORMAT_TO_JS = { + 'pt-br': ('pt-BR', 'dd/MM/yyyy'), + 'es': ('es', 'dd/MM/yyyy'), +} + +LANGUAGE_CODE = 'en' + +# The absolute path to the folder containing the attachments +ATTACHMENTS_FOLDER_PATH = '/mnt/trac/attachments/' + +# ORDERING_DATA receives the options to order for as it's keys and a dict as +# value, if you want to order for the last name, you can use something like: +# 'last_name': {'name': 'Last Name', 'fields': 'last_name'} inside the dict, +# you pass two major keys (name, fields) +# The major key name is the name to appear on the template +# the major key fields it show receive the name of the fields to order for in +# the indexes + +ORDERING_DATA = { + 'latest': { + 'name': _(u'Recent activity'), + 'fields': ('-modified', '-created'), + }, + 'hottest': { + 'name': _(u'Relevance'), + 'fields': None, + }, +} + + +# File type groupings is a tuple of tuples containg what it should filter, +# how it should be displayed, and a tuple of which mimetypes it includes +FILE_TYPE_GROUPINGS = ( + ('document', _(u'Document'), + ('doc', 'docx', 'odt', 'otx', 'dotx', 'pdf', 'ott')), + ('presentation', _(u'Presentation'), ('ppt', 'pptx', 'odp')), + ('text', _(u'Text'), ('txt', 'po', 'conf', 'log')), + ('code', _(u'Code'), + ('py', 'php', 'js', 'sql', 'sh', 'patch', 'diff', 'html', '')), + ('compressed', _(u'Compressed'), ('rar', 'zip', 'gz', 'tgz', 'bz2')), + ('image', _(u'Image'), + ('jpg', 'jpeg', 'png', 'tiff', 'gif', 'svg', 'psd', 'planner', 'cdr')), + ('spreadsheet', _(u'Spreadsheet'), + ('ods', 'xls', 'xlsx', 'xslt', 'csv')), +) + +# the following variable define how many characters should be shown before +# a highlighted word, to make sure that the highlighted word will appear +HIGHLIGHT_NUM_CHARS_BEFORE_MATCH = 30 +HAYSTACK_CUSTOM_HIGHLIGHTER = 'colab.utils.highlighting.ColabHighlighter' + +HAYSTACK_CONNECTIONS = { + 'default': { + 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', + 'URL': 'http://localhost:8983/solr/', + } +} + +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', + 'LOCATION': '127.0.0.1:11211', + } +} + +DATABASE_ROUTERS = [] + + +TEMPLATE_CONTEXT_PROCESSORS = ( + 'django.contrib.auth.context_processors.auth', + 'django.core.context_processors.debug', + 'django.core.context_processors.i18n', + 'django.core.context_processors.media', + 'django.core.context_processors.static', + 'django.core.context_processors.tz', + 'django.contrib.messages.context_processors.messages', + 'django.core.context_processors.request', + 'django_mobile.context_processors.is_mobile', + 'colab.super_archives.context_processors.mailarchive', + 'colab.proxy.context_processors.proxied_apps', + 'colab.home.context_processors.robots', +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django_mobile.middleware.MobileDetectionMiddleware', + 'django_mobile.middleware.SetFlavourMiddleware', + 'colab.tz.middleware.TimezoneMiddleware', +) + +# Add the django_browserid authentication backend. +AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'colab.accounts.auth.ColabBrowserIDBackend', +) + +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, 'static'), +) + +TEMPLATE_DIRS = ( + os.path.join(BASE_DIR, 'templates'), +) + +LOCALE_PATHS = ( + os.path.join(BASE_DIR, 'locale'), +) + +AUTH_USER_MODEL = 'accounts.User' + +from django.contrib.messages import constants as messages +MESSAGE_TAGS = { + messages.INFO: 'alert-info', + messages.SUCCESS: 'alert-success', + messages.WARNING: 'alert-warning', + messages.ERROR: 'alert-danger', +} + +### Feedzilla (planet) +from feedzilla.settings import * +FEEDZILLA_PAGE_SIZE = 5 +FEEDZILLA_SITE_TITLE = _(u'Planet Colab') +FEEDZILLA_SITE_DESCRIPTION = _(u'Colab blog aggregator') + +### Mailman API settings +MAILMAN_API_URL = 'http://localhost:9000' + +### BrowserID / Persona +SITE_URL = 'localhost:8000' +BROWSERID_AUDIENCES = [SITE_URL, SITE_URL.replace('https', 'http')] + + +LOGIN_URL = '/' +LOGIN_REDIRECT_URL = '/' +LOGIN_REDIRECT_URL_FAILURE = '/' +LOGOUT_REDIRECT_URL = '/user/logout' +BROWSERID_CREATE_USER = False + +REVPROXY_ADD_REMOTE_USER = True + +## Converse.js settings +# This URL must use SSL in order to keep chat sessions secure +CONVERSEJS_BOSH_SERVICE_URL = SITE_URL + '/http-bind' + +CONVERSEJS_ALLOW_CONTACT_REQUESTS = False +CONVERSEJS_SHOW_ONLY_ONLINE_USERS = True + + +# Tastypie settings +TASTYPIE_DEFAULT_FORMATS = ['json', ] + +# Dpaste settings +DPASTE_EXPIRE_CHOICES = ( + ('onetime', _(u'One Time Snippet')), + (3600, _(u'In one hour')), + (3600 * 24 * 7, _(u'In one week')), + (3600 * 24 * 30, _(u'In one month')), + ('never', _(u'Never')), +) +DPASTE_EXPIRE_DEFAULT = DPASTE_EXPIRE_CHOICES[4][0] +DPASTE_DEFAULT_GIST_DESCRIPTION = 'Gist created from Colab DPaste' +DPASTE_DEFAULT_GIST_NAME = 'colab_paste' +DPASTE_LEXER_DEFAULT = 'text' + +from .utils.conf import load_yaml_settings +locals().update(load_yaml_settings()) + +if locals().get('RAVEN_DSN', False): + RAVEN_CONFIG = { + 'dsn': RAVEN_DSN + '?timeout=30', + } + INSTALLED_APPS += ('raven.contrib.django.raven_compat',) + +for app_label in locals().get('PROXIED_APPS', {}).keys(): + INSTALLED_APPS += ('colab.proxy.{}'.format(app_label),) diff --git a/colab/super_archives/__init__.py b/colab/super_archives/__init__.py index 78cc9a3..6c60fc3 100644 --- a/colab/super_archives/__init__.py +++ b/colab/super_archives/__init__.py @@ -1,3 +1,3 @@ -default_app_config = 'super_archives.apps.SuperArchivesConfig' +default_app_config = 'colab.super_archives.apps.SuperArchivesConfig' diff --git a/colab/super_archives/apps.py b/colab/super_archives/apps.py index 3dd941a..eca1b7a 100644 --- a/colab/super_archives/apps.py +++ b/colab/super_archives/apps.py @@ -3,7 +3,7 @@ from django.apps import AppConfig class SuperArchivesConfig(AppConfig): - name = 'super_archives' + name = 'colab.super_archives' verbose_name = 'Super Archives' def ready(self): diff --git a/colab/super_archives/management/commands/import_emails.py b/colab/super_archives/management/commands/import_emails.py index 40d18a9..49c3613 100644 --- a/colab/super_archives/management/commands/import_emails.py +++ b/colab/super_archives/management/commands/import_emails.py @@ -12,14 +12,14 @@ from optparse import make_option from django.db import transaction from django.template.defaultfilters import slugify -from super_archives.utils.email import colab_send_email from django.core.management.base import BaseCommand, CommandError from django.template.loader import render_to_string from django.utils.translation import ugettext as _ -from super_archives.models import MailingList, Message, \ +from colab.super_archives.utils.email import colab_send_email +from colab.super_archives.models import MailingList, Message, \ Thread, EmailAddress -from super_archives.management.commands.message import Message as \ +from colab.super_archives.management.commands.message import Message as \ CustomMessage diff --git a/colab/super_archives/management/commands/update_blocks.py b/colab/super_archives/management/commands/update_blocks.py index a76578a..971de18 100644 --- a/colab/super_archives/management/commands/update_blocks.py +++ b/colab/super_archives/management/commands/update_blocks.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from django.core.management.base import BaseCommand -from super_archives.models import Message +from colab.super_archives.models import Message class Command(BaseCommand): diff --git a/colab/super_archives/management/commands/update_keywords.py b/colab/super_archives/management/commands/update_keywords.py index f9a2a9c..be59910 100644 --- a/colab/super_archives/management/commands/update_keywords.py +++ b/colab/super_archives/management/commands/update_keywords.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from django.core.management.base import BaseCommand, CommandError -from super_archives.models import Thread +from colab.super_archives.models import Thread class Command(BaseCommand): diff --git a/colab/super_archives/migrations/0001_initial.py b/colab/super_archives/migrations/0001_initial.py index 110fdd8..7577f10 100644 --- a/colab/super_archives/migrations/0001_initial.py +++ b/colab/super_archives/migrations/0001_initial.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals from django.db import models, migrations import hitcounter.models -import super_archives.models +import colab.super_archives.models import django.db.models.deletion from django.conf import settings import taggit.managers @@ -36,7 +36,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('address', models.EmailField(unique=True, max_length=75)), - ('validation_key', models.CharField(default=super_archives.models.get_validation_key, max_length=32, null=True)), + ('validation_key', models.CharField(default=colab.super_archives.models.get_validation_key, max_length=32, null=True)), ('created', models.DateTimeField(auto_now_add=True)), ('user', models.ForeignKey(related_name=b'emails_not_validated', to=settings.AUTH_USER_MODEL, null=True)), ], @@ -74,7 +74,7 @@ class Migration(migrations.Migration): name='MailingListMembership', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('mailinglist', models.ForeignKey(to='super_archives.MailingList')), + ('mailinglist', models.ForeignKey(to='colab.super_archives.MailingList')), ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), ], options={ @@ -91,7 +91,7 @@ class Migration(migrations.Migration): ('received_time', models.DateTimeField(db_index=True)), ('message_id', models.CharField(max_length=512)), ('spam', models.BooleanField(default=False)), - ('from_address', models.ForeignKey(to='super_archives.EmailAddress')), + ('from_address', models.ForeignKey(to='colab.super_archives.EmailAddress')), ], options={ 'ordering': ('received_time',), @@ -107,7 +107,7 @@ class Migration(migrations.Migration): ('text', models.TextField()), ('is_reply', models.BooleanField(default=False)), ('order', models.IntegerField()), - ('message', models.ForeignKey(related_name=b'blocks', to='super_archives.Message')), + ('message', models.ForeignKey(related_name=b'blocks', to='colab.super_archives.Message')), ], options={ 'ordering': ('order',), @@ -120,7 +120,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('name', models.CharField(max_length=512)), ('value', models.TextField()), - ('Message', models.ForeignKey(to='super_archives.Message')), + ('Message', models.ForeignKey(to='colab.super_archives.Message')), ], options={ }, @@ -133,8 +133,8 @@ class Migration(migrations.Migration): ('subject_token', models.CharField(max_length=512)), ('score', models.IntegerField(default=0, help_text='Thread score', verbose_name='Score')), ('spam', models.BooleanField(default=False)), - ('latest_message', models.OneToOneField(related_name=b'+', null=True, to='super_archives.Message', help_text='Latest message posted', verbose_name='Latest message')), - ('mailinglist', models.ForeignKey(verbose_name='Mailing List', to='super_archives.MailingList', help_text='The Mailing List where is the thread')), + ('latest_message', models.OneToOneField(related_name=b'+', null=True, to='colab.super_archives.Message', help_text='Latest message posted', verbose_name='Latest message')), + ('mailinglist', models.ForeignKey(verbose_name='Mailing List', to='colab.super_archives.MailingList', help_text='The Mailing List where is the thread')), ('tags', taggit.managers.TaggableManager(to='taggit.Tag', through='taggit.TaggedItem', help_text='A comma-separated list of tags.', verbose_name='Tags')), ], options={ @@ -149,7 +149,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('created', models.DateTimeField(auto_now_add=True)), - ('message', models.ForeignKey(to='super_archives.Message')), + ('message', models.ForeignKey(to='colab.super_archives.Message')), ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), ], options={ @@ -167,7 +167,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='message', name='thread', - field=models.ForeignKey(to='super_archives.Thread', null=True), + field=models.ForeignKey(to='colab.super_archives.Thread', null=True), preserve_default=True, ), migrations.AlterUniqueTogether( @@ -177,7 +177,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='keyword', name='thread', - field=models.ForeignKey(to='super_archives.Thread'), + field=models.ForeignKey(to='colab.super_archives.Thread'), preserve_default=True, ), migrations.AlterUniqueTogether( diff --git a/colab/super_archives/search_indexes.py b/colab/super_archives/search_indexes.py index 5d0493e..face2e6 100644 --- a/colab/super_archives/search_indexes.py +++ b/colab/super_archives/search_indexes.py @@ -4,7 +4,7 @@ import math from haystack import indexes -from search.base_indexes import BaseIndex +from colab.search.base_indexes import BaseIndex from .models import Thread diff --git a/colab/super_archives/templatetags/superarchives.py b/colab/super_archives/templatetags/superarchives.py index 13e4899..e1cbfb2 100644 --- a/colab/super_archives/templatetags/superarchives.py +++ b/colab/super_archives/templatetags/superarchives.py @@ -1,9 +1,9 @@ from django import template - -from super_archives.utils import url from django.conf import settings +from colab.super_archives.utils import url + register = template.Library() TEMPLATE_PATH = 'superarchives/tags/' @@ -32,4 +32,4 @@ def pop_from_get(context, **kwargs): context['request'].META['PATH_INFO'], context['request'].META['QUERY_STRING'], **kwargs - ) \ No newline at end of file + ) diff --git a/colab/super_archives/views.py b/colab/super_archives/views.py index 4984993..a38e2c5 100644 --- a/colab/super_archives/views.py +++ b/colab/super_archives/views.py @@ -20,7 +20,7 @@ from django.shortcuts import render, redirect, get_object_or_404 from haystack.query import SearchQuerySet -from accounts.utils import mailman +from colab.accounts.utils import mailman from .utils.email import send_verification_email from .models import MailingList, Thread, EmailAddress, \ EmailAddressValidation, Message diff --git a/colab/urls.py b/colab/urls.py new file mode 100644 index 0000000..801e6db --- /dev/null +++ b/colab/urls.py @@ -0,0 +1,46 @@ +from django.conf.urls import patterns, include, url, static +from django.conf import settings +from django.views.generic import TemplateView +from django.contrib import admin + +from .accounts.models import User +from .search.forms import ColabSearchForm +from .super_archives.models import Message + + +admin.autodiscover() + +urlpatterns = patterns('', + url(r'^$', 'colab.home.views.index', name='home'), + url(r'^robots.txt$', 'colab.home.views.robots', name='robots'), + + url(r'^open-data/$', TemplateView.as_view(template_name='open-data.html'), + name='opendata'), + + url(r'^search/', include('colab.search.urls')), + url(r'^archives/', include('colab.super_archives.urls')), + url(r'^api/', include('colab.api.urls')), + url(r'^rss/', include('colab.rss.urls')), + + url(r'^user/', include('colab.accounts.urls')), # Kept for backwards compatibility + url(r'^signup/', include('colab.accounts.urls')), # (same here) TODO: move to nginx + url(r'^account/', include('colab.accounts.urls')), + + url(r'', include('django_browserid.urls')), + + url(r'^planet/', include('feedzilla.urls')), + + url(r'paste/', include('dpaste.urls.dpaste')), + + # Uncomment the next line to enable the admin: + url(r'^colab/admin/', include(admin.site.urls)), + + url(r'^trac/', include('colab.proxy.trac.urls')), + url(r'^gitlab/', include('colab.proxy.gitlab.urls')), +) + +if settings.DEBUG: + urlpatterns += static.static( + settings.MEDIA_URL, + document_root=settings.MEDIA_ROOT + ) diff --git a/colab/utils/__init__.py b/colab/utils/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/colab/utils/__init__.py diff --git a/colab/utils/conf.py b/colab/utils/conf.py new file mode 100644 index 0000000..b73904a --- /dev/null +++ b/colab/utils/conf.py @@ -0,0 +1,32 @@ + +import os +import yaml + +from django.core.exceptions import ImproperlyConfigured + + +class InaccessibleYAMLSettings(ImproperlyConfigured): + """Settings YAML is Inaccessible. + + Check if the file exists and if you have read permissions.""" + + +def load_yaml_settings(): + yaml_path = os.getenv('COLAB_SETTINGS', '/etc/colab.yaml') + + if not os.path.exists(yaml_path): + msg = "The yaml file {} does not exist".format(yaml_path) + raise InaccessibleYAMLSettings(msg) + + try: + with open(yaml_path) as yaml_file: + yaml_settings = yaml.load(yaml_file.read()) + except IOError: + msg = ('Could not open settings file {}. Please ' + 'check if the file exists and if user ' + 'has read rights.').format(yaml_path) + raise InaccessibleYAMLSettings(msg) + + return yaml_settings + +yaml_settings = load_yaml_settings() diff --git a/colab/utils/highlighting.py b/colab/utils/highlighting.py new file mode 100644 index 0000000..8f41b7c --- /dev/null +++ b/colab/utils/highlighting.py @@ -0,0 +1,38 @@ +from haystack.utils import Highlighter +from django.conf import settings +from django.utils.html import escape, strip_tags + + +class ColabHighlighter(Highlighter): + def highlight(self, text_block): + self.text_block = escape(strip_tags(text_block)) + highlight_locations = self.find_highlightable_words() + start_offset, end_offset = self.find_window(highlight_locations) + return self.render_html(highlight_locations, start_offset, end_offset) + + def find_window(self, highlight_locations): + """Getting the HIGHLIGHT_NUM_CHARS_BEFORE_MATCH setting + to find how many characters before the first word found should + be removed from the window + """ + + if len(self.text_block) <= self.max_length: + return (0, self.max_length) + + num_chars_before = getattr( + settings, + 'HIGHLIGHT_NUM_CHARS_BEFORE_MATCH', + 0 + ) + + best_start, best_end = super(ColabHighlighter, self).find_window( + highlight_locations + ) + if best_start <= num_chars_before: + best_end -= best_start + best_start = 0 + else: + best_start -= num_chars_before + best_end -= num_chars_before + + return (best_start, best_end) diff --git a/colab/wsgi.py b/colab/wsgi.py new file mode 100644 index 0000000..02679ab --- /dev/null +++ b/colab/wsgi.py @@ -0,0 +1,14 @@ +""" +WSGI config for colab project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/ +""" + +import os +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "colab.settings") + +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() diff --git a/scripts/colab-admin b/scripts/colab-admin new file mode 100755 index 0000000..a466007 --- /dev/null +++ b/scripts/colab-admin @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "colab.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) -- libgit2 0.21.2