From 2c6bd0469b54aee18ec03fe3bc0d36825271193f Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Wed, 29 Apr 2015 21:35:56 +0000 Subject: [PATCH] Fixes on orchestra deployment --- INSTALL.md | 3 +-- TODO.md | 2 ++ .../project_template/project_name/settings.py | 1 - .../accounts/migrations/0001_initial.py | 4 ++-- orchestra/contrib/domains/serializers.py | 4 ++-- orchestra/contrib/mailboxes/admin.py | 9 ++++++- orchestra/contrib/mailboxes/settings.py | 4 ++-- orchestra/contrib/websites/admin.py | 4 ++-- orchestra/utils/options.py | 2 +- scripts/container/deploy.sh | 24 ++++++++++++------- 10 files changed, 36 insertions(+), 21 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index eb002af0..01ba3a51 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -39,10 +39,9 @@ Django-orchestra can be installed on any Linux system, however it is **strongly 5. Create and configure a Postgres database ```bash sudo python3 manage.py setuppostgres --db_password - python3 manage.py migrate auth + # admin_tools needs accounts and does not have migrations python3 manage.py migrate accounts python3 manage.py migrate - python3 manage.py syncdb ``` 7. Configure celeryd diff --git a/TODO.md b/TODO.md index 56cc6562..97a0c760 100644 --- a/TODO.md +++ b/TODO.md @@ -296,3 +296,5 @@ https://code.djangoproject.com/ticket/24576 # admin edit relevant djanog settings # django SITE_NAME vs ORCHESTRA_SITE_NAME ? + +# accounts.migrations link to last auth migration instead of first diff --git a/orchestra/conf/project_template/project_name/settings.py b/orchestra/conf/project_template/project_name/settings.py index 3accc5c5..84e68271 100644 --- a/orchestra/conf/project_template/project_name/settings.py +++ b/orchestra/conf/project_template/project_name/settings.py @@ -70,4 +70,3 @@ LOCALE_PATHS = ( ORCHESTRA_SITE_NAME = '{{ project_name }}' - diff --git a/orchestra/contrib/accounts/migrations/0001_initial.py b/orchestra/contrib/accounts/migrations/0001_initial.py index 241206b2..e6ff1344 100644 --- a/orchestra/contrib/accounts/migrations/0001_initial.py +++ b/orchestra/contrib/accounts/migrations/0001_initial.py @@ -10,8 +10,8 @@ import django.contrib.auth.models class Migration(migrations.Migration): dependencies = [ - ('auth', '__first__'), - ('contenttypes', '__first__'), + # Permissions and contenttypes + ('auth', '0006_require_contenttypes_0002'), ('systemusers', '0001_initial'), ] diff --git a/orchestra/contrib/domains/serializers.py b/orchestra/contrib/domains/serializers.py index 228016c1..0853d045 100644 --- a/orchestra/contrib/domains/serializers.py +++ b/orchestra/contrib/domains/serializers.py @@ -31,8 +31,8 @@ class DomainSerializer(AccountSerializerMixin, HyperlinkedModelSerializer): def clean_name(self, attrs, source): """ prevent users creating subdomains of other users domains """ name = attrs[source] - top = Domain.get_parent_domain(name) - if top and top.account != self.account: + parent = Domain.get_parent_domain(name) + if parent and parent.account != self.account: raise ValidationError(_("Can not create subdomains of other users domains")) return attrs diff --git a/orchestra/contrib/mailboxes/admin.py b/orchestra/contrib/mailboxes/admin.py index 80482abd..221f19c7 100644 --- a/orchestra/contrib/mailboxes/admin.py +++ b/orchestra/contrib/mailboxes/admin.py @@ -32,7 +32,7 @@ class AutoresponseInline(admin.StackedInline): class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedModelAdmin): list_display = ( - 'name', 'account_link', 'filtering', 'display_addresses', 'display_active', + 'name', 'account_link', 'display_filtering', 'display_addresses', 'display_active', ) list_filter = (IsActiveListFilter, HasAddressListFilter, 'filtering') search_fields = ('account__username', 'account__short_name', 'account__full_name', 'name') @@ -75,6 +75,13 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo display_addresses.short_description = _("Addresses") display_addresses.allow_tags = True + def display_filtering(self, mailbox): + """ becacuse of allow_tags = True """ + return mailbox.get_filtering_display() + display_filtering.short_description = _("Filtering") + display_filtering.admin_order_field = 'filtering' + display_filtering.allow_tags = True + def get_actions(self, request): if settings.MAILBOXES_LOCAL_ADDRESS_DOMAIN: self.actions = (SendMailboxEmail(),) diff --git a/orchestra/contrib/mailboxes/settings.py b/orchestra/contrib/mailboxes/settings.py index bf69ae13..9dd830b9 100644 --- a/orchestra/contrib/mailboxes/settings.py +++ b/orchestra/contrib/mailboxes/settings.py @@ -75,13 +75,13 @@ MAILBOXES_MAILBOX_FILTERINGS = Setting('MAILBOXES_MAILBOX_FILTERINGS', { # value: (verbose_name, filter) 'DISABLE': (_("Disable"), ''), - 'REJECT': (mark_safe_lazy(_("Reject spam (X-Spam-Score≥9)")), textwrap.dedent(""" + 'REJECT': (mark_safe_lazy(_("Reject spam (Score≥9)")), textwrap.dedent(""" require ["fileinto","regex","envelope","vacation","reject","relational","comparator-i;ascii-numeric"]; if header :value "ge" :comparator "i;ascii-numeric" "X-Spam-Score" "9" { discard; stop; }""")), - 'REDIRECT': (mark_safe_lazy(_("Archive spam (X-Spam-Score≥9)")), textwrap.dedent(""" + 'REDIRECT': (mark_safe_lazy(_("Archive spam (Score≥9)")), textwrap.dedent(""" require ["fileinto","regex","envelope","vacation","reject","relational","comparator-i;ascii-numeric"]; if header :value "ge" :comparator "i;ascii-numeric" "X-Spam-Score" "9" { fileinto "Spam"; diff --git a/orchestra/contrib/websites/admin.py b/orchestra/contrib/websites/admin.py index 0633d7fb..7bde2e50 100644 --- a/orchestra/contrib/websites/admin.py +++ b/orchestra/contrib/websites/admin.py @@ -67,7 +67,7 @@ class WebsiteAdmin(SelectAccountAdminMixin, ExtendedModelAdmin): form = WebsiteAdminForm filter_by_account_fields = ['domains'] list_prefetch_related = ('domains', 'content_set__webapp') - search_fields = ('name', 'account__username', 'domains__name') + search_fields = ('name', 'account__username', 'domains__name', 'content__webapp__name') def display_domains(self, website): domains = [] @@ -84,7 +84,7 @@ class WebsiteAdmin(SelectAccountAdminMixin, ExtendedModelAdmin): for content in website.content_set.all(): webapp = content.webapp url = change_url(webapp) - name = "%s on %s" % (webapp.get_type_display(), content.path or '/') + name = "%s on %s" % (webapp.name, content.path or '/') webapps.append('%s' % (url, name)) return '
'.join(webapps) display_webapps.allow_tags = True diff --git a/orchestra/utils/options.py b/orchestra/utils/options.py index 65da0fcb..121d277e 100644 --- a/orchestra/utils/options.py +++ b/orchestra/utils/options.py @@ -44,7 +44,7 @@ def running_syncdb(): def database_ready(): - return not running_syncdb() and 'setuppostgres' not in sys.argv and 'test' not in sys.argv + return not running_syncdb() and 'setuppostgres' not in sys.argv and 'test' not in sys.argv and 'celerybeat' not in sys.argv def dict_setting_to_choices(choices): diff --git a/scripts/container/deploy.sh b/scripts/container/deploy.sh index 1c84f903..2a950906 100755 --- a/scripts/container/deploy.sh +++ b/scripts/container/deploy.sh @@ -4,8 +4,7 @@ # This script is safe to run several times, for example in order to upgrade your deployment -set -u -set -e +set -ue bold=$(tput bold) normal=$(tput sgr0) @@ -46,10 +45,18 @@ CURRENT_VERSION=$($PYTHON_BIN -c "from orchestra import get_version; print(get_v if [[ ! $CURRENT_VERSION ]]; then # First Orchestra installation run "apt-get -y install git python3-pip" - surun "git clone https://github.com/glic3rinu/django-orchestra.git ~/django-orchestra" || surun "export GIT_DIR=~/django-orchestra/.git; git pull" + surun "git clone https://github.com/glic3rinu/django-orchestra.git ~/django-orchestra" || { + # Finishing partial installation + surun "export GIT_DIR=~/django-orchestra/.git; git pull" + } PYTHON_PATH=$($PYTHON_BIN -c "import sys; print([path for path in sys.path if path.startswith('/usr/local/lib/python')][0]);") echo $HOME/django-orchestra/ | sudo tee "$PYTHON_PATH/orchestra.pth" run "cp $HOME/django-orchestra/orchestra/bin/orchestra-admin /usr/local/bin/" +else + # Upgrade and relay on postguprade for finishing up the installation + export GIT_DIR=~/django-orchestra/.git; git pull + $PYTHON_BIN $MANAGE migrate postupgradeorchestra --from $CURRENT_VERSION + exit fi sudo orchestra-admin install_requirements --testing @@ -58,6 +65,8 @@ if [[ ! -e $BASE_DIR ]]; then cd $HOME surun "orchestra-admin startproject $PROJECT_NAME" cd - +else + echo "$BASE_DIT already existis, doing nothing." fi MANAGE="$BASE_DIR/manage.py" @@ -78,24 +87,23 @@ if [[ ! $(sudo su postgres -c "psql -lqt" | awk {'print $1'} | grep '^orchestra$ sudo su postgres -c 'psql -c "ALTER USER orchestra CREATEDB;"' fi -run "$PYTHON_BIN $MANAGE migrate --noinput auth" +# admin_tools needs accounts and does not have migrations run "$PYTHON_BIN $MANAGE migrate --noinput accounts" run "$PYTHON_BIN $MANAGE migrate --noinput" -run "$PYTHON_BIN $MANAGE syncdb --noinput" sudo $PYTHON_BIN $MANAGE setupcelery --username $USER --processes 2 -# Install and configure Nginx web server +# Install and configure Nginx+uwsgi web services surun "mkdir -p $BASE_DIR/static" surun "$PYTHON_BIN $MANAGE collectstatic --noinput" run "apt-get install -y nginx uwsgi uwsgi-plugin-python3" run "$PYTHON_BIN $MANAGE setupnginx" run "service nginx start" -# Apply changes +# Apply changes on related services run "$PYTHON_BIN $MANAGE restartservices" -# Create a orchestra user +# Create orchestra superuser cat <<- EOF | $PYTHON_BIN $MANAGE shell from orchestra.contrib.accounts.models import Account if not Account.objects.filter(username="$USER").exists():