From 6caf838549b008d9552ef280d3ed0eebc4f2046e Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Fri, 4 Mar 2016 09:46:39 +0000 Subject: [PATCH] Minor improvements --- TODO.md | 23 ------ orchestra/contrib/bills/actions.py | 2 +- orchestra/contrib/bills/admin.py | 22 +++++- .../contrib/saas/backends/wordpressmu.py | 30 +++++--- orchestra/contrib/webapps/backends/php.py | 72 ++++++++++-------- orchestra/contrib/websites/backends/apache.py | 75 ++++++++++--------- requirements.txt | 2 +- 7 files changed, 118 insertions(+), 108 deletions(-) diff --git a/TODO.md b/TODO.md index 8590a3fc..77c7988e 100644 --- a/TODO.md +++ b/TODO.md @@ -391,23 +391,6 @@ short URLS: https://github.com/rsvp/gitio link backend help text variables to settings/#var_name -make python3 default python on the fucking docker container - -autocomplete; on the form header and type="search" -To latest developers to post on this thread: I implemented the workaround I described in comment #14 nearly three months ago, and it has worked perfectly since then. While we would all prefer that "autocomplete=off" function properly at all times, it still functions properly if you include in your form an input element with any other autocomplete value. - -I simply added this code to my layout: - -
- -
- -Once I did this, all of my "autocomplete=off" elements were respected by Chrome. - -http://makandracards.com/makandra/24933-chrome-34+-firefox-38+-ie11+-ignore-autocomplete-off - - - mkhomedir_helper or create ssh homes with bash.rc and such # warnings if some plugins are disabled, like make routes red @@ -424,8 +407,6 @@ mkhomedir_helper or create ssh homes with bash.rc and such # email usage -webkit-column-count:3;-moz-column-count:3;column-count:3; -# wordpressmu custom_url: set blog.domain - # validate_user on saas.wordpress to detect if username already exists before attempting to create a blog @@ -440,10 +421,6 @@ mkhomedir_helper or create ssh homes with bash.rc and such shit_happend, otherwise schedule for first query # Entry.objects.filter()[:1].first() (LIMIT 1) -# put "Coordinate Apache restart" inside a bash function for clarity - - -# show base and total desglosed # Reverse lOgHistory order by date (lastest first) diff --git a/orchestra/contrib/bills/actions.py b/orchestra/contrib/bills/actions.py index 9a340921..7692334a 100644 --- a/orchestra/contrib/bills/actions.py +++ b/orchestra/contrib/bills/actions.py @@ -89,7 +89,7 @@ def close_bills(modeladmin, request, queryset, action='close_bills'): 'formset': formset, 'obj': get_object_from_url(modeladmin, request), } - templete = 'admin/orchestra/generic_confirmation.html' + template = 'admin/orchestra/generic_confirmation.html' if action == 'close_send_download_bills': template = 'admin/bills/bill/close_send_download_bills.html' return render(request, template, context) diff --git a/orchestra/contrib/bills/admin.py b/orchestra/contrib/bills/admin.py index 4631b15d..6baffda2 100644 --- a/orchestra/contrib/bills/admin.py +++ b/orchestra/contrib/bills/admin.py @@ -198,8 +198,9 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): change_list_template = 'admin/bills/change_list.html' fieldsets = ( (None, { - 'fields': ['number', 'type', 'amend_of_link', 'account_link', 'display_total', - 'display_payment_state', 'is_sent', 'comments'], + 'fields': ['number', 'type', 'amend_of_link', 'account_link', + 'display_total_with_subtotals', 'display_payment_state', + 'is_sent', 'comments'], }), (_("Dates"), { 'classes': ('collapse',), @@ -227,7 +228,7 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): ) readonly_fields = ( 'number', 'display_total', 'is_sent', 'display_payment_state', 'created_on_display', - 'closed_on_display', 'updated_on_display' + 'closed_on_display', 'updated_on_display', 'display_total_with_subtotals', ) inlines = [BillLineInline, ClosedBillLineInline] date_hierarchy = 'closed_on' @@ -252,11 +253,24 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): num_lines.short_description = _("lines") def display_total(self, bill): - return "%s &%s;" % (bill.compute_total(), settings.BILLS_CURRENCY.lower()) + currency = settings.BILLS_CURRENCY.lower() + return '%s &%s;' % (bill.compute_total(), currency) display_total.allow_tags = True display_total.short_description = _("total") display_total.admin_order_field = 'approx_total' + def display_total_with_subtotals(self, bill): + currency = settings.BILLS_CURRENCY.lower() + subtotals = [] + for tax, subtotal in bill.compute_subtotals().items(): + subtotals.append(_("Subtotal %s%% VAT %s &%s;") % (tax, subtotal[0], currency)) + subtotals.append(_("Taxes %s%% VAT %s &%s;") % (tax, subtotal[1], currency)) + subtotals = '\n'.join(subtotals) + return '%s &%s;' % (subtotals, bill.compute_total(), currency) + display_total_with_subtotals.allow_tags = True + display_total_with_subtotals.short_description = _("total") + display_total_with_subtotals.admin_order_field = 'approx_total' + def type_link(self, bill): bill_type = bill.type.lower() url = reverse('admin:bills_%s_changelist' % bill_type) diff --git a/orchestra/contrib/saas/backends/wordpressmu.py b/orchestra/contrib/saas/backends/wordpressmu.py index 7f79d1da..d310dd5a 100644 --- a/orchestra/contrib/saas/backends/wordpressmu.py +++ b/orchestra/contrib/saas/backends/wordpressmu.py @@ -151,7 +151,8 @@ class WordpressMuBackend(ServiceController): SELECT b.blog_id, b.domain, m.domain, b.path FROM wp_domain_mapping AS m, wp_blogs AS b WHERE m.blog_id = b.blog_id AND m.active AND %(IDENT)s;") ) - if [[ ${existing[0]} != '' ]]; then + if [[ ${existing[0]} != "" ]]; then + echo "Existing blog with ID ${existing[0]}" # Clear custom domain if [[ "%(custom_domain)s" == "" ]]; then mysql %(db_name)s --execute=" @@ -168,21 +169,27 @@ class WordpressMuBackend(ServiceController): WHERE m.blog_id = b.blog_id AND m.active AND %(IDENT)s;" fi elif [[ "%(custom_domain)s" != "" ]]; then + echo "Non existing blog with custom domain %(domain)s" blog=( $(mysql -Nrs %(db_name)s --execute=" SELECT blog_id, path FROM wp_blogs WHERE domain = '%(domain)s';") ) - mysql %(db_name)s --execute=" - UPDATE wp_domain_mapping - SET active = 0 - WHERE active AND blog_id = ${blog[0]}; - INSERT INTO wp_domain_mapping - (blog_id, domain, active) VALUES (${blog[0]}, '%(custom_domain)s', 1);" - if [[ "${blog[1]}" != "%(custom_path)s" ]]; then + if [[ "${blog[0]}" != "" ]]; then + echo "Blog %(domain)s found, ID: ${blog[0]}" mysql %(db_name)s --execute=" - UPDATE wp_blogs - SET path = '%(custom_path)s' - WHERE blog_id = ${blog[0]};" + UPDATE wp_domain_mapping + SET active = 0 + WHERE active AND blog_id = ${blog[0]}; + INSERT INTO wp_domain_mapping + (blog_id, domain, active) VALUES (${blog[0]}, '%(custom_domain)s', 1);" + if [[ "${blog[1]}" != "%(custom_path)s" ]]; then + mysql %(db_name)s --execute=" + UPDATE wp_blogs + SET path = '%(custom_path)s' + WHERE blog_id = ${blog[0]};" + fi + else + echo "Blog %(domain)s not found" fi fi""") % context ) @@ -207,6 +214,7 @@ class WordpressMuBackend(ServiceController): }) return context + class WordpressMuTraffic(ApacheTrafficByHost): __doc__ = ApacheTrafficByHost.__doc__ verbose_name = _("Wordpress MU Traffic") diff --git a/orchestra/contrib/webapps/backends/php.py b/orchestra/contrib/webapps/backends/php.py index 4119f8e0..264cfa1f 100644 --- a/orchestra/contrib/webapps/backends/php.py +++ b/orchestra/contrib/webapps/backends/php.py @@ -140,10 +140,45 @@ class PHPBackend(WebAppServiceMixin, ServiceController): def prepare(self): super(PHPBackend, self).prepare() - # Coordinate apache restart with php backend in order not to overdo it self.append(textwrap.dedent(""" - backend="PHPBackend" - echo "$backend" >> /dev/shm/restart.apache2""") + BACKEND="PHPBackend" + echo "$BACKEND" >> /dev/shm/reload.apache2 + + function coordinate_apache_reload () { + # Coordinate Apache reload with other concurrent backends (e.g. Apache2Backend) + is_last=0 + counter=0 + while ! mv /dev/shm/reload.apache2 /dev/shm/reload.apache2.locked; do + sleep 0.1; + if [[ $counter -gt 4 ]]; then + echo "[ERROR]: Apache reload synchronization deadlocked!" >&2 + exit 10 + fi + counter=$(($counter+1)) + done + state="$(grep -v "$BACKEND" /dev/shm/reload.apache2.locked)" || is_last=1 + [[ $is_last -eq 0 ]] && { + echo "$state" | grep -v ' RELOAD$' || is_last=1 + } + if [[ $is_last -eq 1 ]]; then + echo "[DEBUG]: Last backend to run, update: $UPDATED_APACHE, state: '$state'" + if [[ $UPDATED_APACHE -eq 1 || "$state" =~ .*RELOAD$ ]]; then + if service apache2 status > /dev/null; then + service apache2 reload + else + service apache2 start + fi + fi + rm /dev/shm/reload.apache2.locked + else + echo -n "$state" > /dev/shm/reload.apache2.locked + if [[ $UPDATED_APACHE -eq 1 ]]; then + echo -e "[DEBUG]: Apache will be reloaded by another backend:\\n${state}" + echo "$BACKEND RELOAD" >> /dev/shm/reload.apache2.locked + fi + mv /dev/shm/reload.apache2.locked /dev/shm/reload.apache2 + fi + }""") ) def commit(self): @@ -155,36 +190,7 @@ class PHPBackend(WebAppServiceMixin, ServiceController): if [[ $UPDATED_FPM -eq 1 ]]; then %(reload_pool)s fi - - # Coordinate Apache restart with other concurrent backends (e.g. Apache2Backend) - is_last=0 - mv /dev/shm/restart.apache2 /dev/shm/restart.apache2.locked || { - sleep 0.2 - mv /dev/shm/restart.apache2 /dev/shm/restart.apache2.locked - } - state="$(grep -v "$backend" /dev/shm/restart.apache2.locked)" || is_last=1 - [[ $is_last -eq 0 ]] && { - echo "$state" | grep -v ' RESTART$' || is_last=1 - } - if [[ $is_last -eq 1 ]]; then - echo "Last backend to run, update: $UPDATED_APACHE, state: '$state'" - if [[ $UPDATED_APACHE -eq 1 || "$state" =~ .*RESTART$ ]]; then - if service apache2 status > /dev/null; then - service apache2 reload - else - service apache2 start - fi - fi - rm /dev/shm/restart.apache2.locked - else - echo -n "$state" > /dev/shm/restart.apache2.locked - if [[ $UPDATED_APACHE -eq 1 ]]; then - echo -e "Apache will be restarted by another backend:\\n${state}" - echo "$backend RESTART" >> /dev/shm/restart.apache2.locked - fi - mv /dev/shm/restart.apache2.locked /dev/shm/restart.apache2 - fi - # End of coordination + coordinate_apache_reload """) % context ) super(PHPBackend, self).commit() diff --git a/orchestra/contrib/websites/backends/apache.py b/orchestra/contrib/websites/backends/apache.py index 6214fd68..f23fe769 100644 --- a/orchestra/contrib/websites/backends/apache.py +++ b/orchestra/contrib/websites/backends/apache.py @@ -108,7 +108,7 @@ class Apache2Backend(ServiceController): apache_conf += self.render_redirect_https(context) context['apache_conf'] = apache_conf.strip() self.append(textwrap.dedent(""" - # Generate Apache site config for %(site_name)s + # Generate Apache config for site %(site_name)s read -r -d '' apache_conf << 'EOF' || true %(apache_conf)s EOF @@ -145,44 +145,49 @@ class Apache2Backend(ServiceController): super(Apache2Backend, self).prepare() # Coordinate apache restart with php backend in order not to overdo it self.append(textwrap.dedent(""" - backend="Apache2Backend" - echo "$backend" >> /dev/shm/restart.apache2""") + BACKEND="Apache2Backend" + echo "$BACKEND" >> /dev/shm/restart.apache2 + + function coordinate_apache_reload () { + # Coordinate Apache reload with other concurrent backends (e.g. PHPBackend) + is_last=0 + counter=0 + while ! mv /dev/shm/reload.apache2 /dev/shm/reload.apache2.locked; do + if [[ $counter -gt 4 ]]; then + echo "[ERROR]: Apache reload synchronization deadlocked!" >&2 + exit 10 + fi + counter=$(($counter+1)) + sleep 0.1; + done + state="$(grep -v "$BACKEND" /dev/shm/reload.apache2.locked)" || is_last=1 + [[ $is_last -eq 0 ]] && { + echo "$state" | grep -v ' RELOAD$' || is_last=1 + } + if [[ $is_last -eq 1 ]]; then + echo "[DEBUG]: Last backend to run, update: $UPDATED_APACHE, state: '$state'" + if [[ $UPDATED_APACHE -eq 1 || "$state" =~ .*RELOAD$ ]]; then + if service apache2 status > /dev/null; then + service apache2 reload + else + service apache2 start + fi + fi + rm /dev/shm/reload.apache2.locked + else + echo -n "$state" > /dev/shm/reload.apache2.locked + if [[ $UPDATED_APACHE -eq 1 ]]; then + echo -e "[DEBUG]: Apache will be reloaded by another backend:\\n${state}" + echo "$BACKEND RELOAD" >> /dev/shm/reload.apache2.locked + fi + mv /dev/shm/reload.apache2.locked /dev/shm/reload.apache2 + fi + }""") ) def commit(self): """ reload Apache2 if necessary """ - self.append(textwrap.dedent(""" - # Coordinate Apache restart with other concurrent backends (e.g. PHPBackend) - is_last=0 - mv /dev/shm/restart.apache2 /dev/shm/restart.apache2.locked || { - sleep 0.2 - mv /dev/shm/restart.apache2 /dev/shm/restart.apache2.locked - } - state="$(grep -v "$backend" /dev/shm/restart.apache2.locked)" || is_last=1 - [[ $is_last -eq 0 ]] && { - echo "$state" | grep -v ' RESTART$' || is_last=1 - } - if [[ $is_last -eq 1 ]]; then - echo "Last backend to run, update: $UPDATED_APACHE, state: '$state'" - if [[ $UPDATED_APACHE -eq 1 || "$state" =~ .*RESTART$ ]]; then - if service apache2 status > /dev/null; then - service apache2 reload - else - service apache2 start - fi - fi - rm /dev/shm/restart.apache2.locked - else - echo -n "$state" > /dev/shm/restart.apache2.locked - if [[ $UPDATED_APACHE -eq 1 ]]; then - echo -e "Apache will be restarted by another backend:\\n${state}" - echo "$backend RESTART" >> /dev/shm/restart.apache2.locked - fi - mv /dev/shm/restart.apache2.locked /dev/shm/restart.apache2 - fi - # End of coordination - """) - ) + self.append("coordinate_apache_reload") super(Apache2Backend, self).commit() def get_directives(self, directive, context): diff --git a/requirements.txt b/requirements.txt index 6fc0c656..884ac771 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ celery==3.1.16 kombu==3.0.23 billiard==3.3.0.18 Markdown==2.4 -djangorestframework==3.1.2 +djangorestframework==3.3.2 ecdsa==0.11 Pygments==1.6 django-filter==0.7