diff --git a/admin.py b/admin.py index efb096b5..f1f224f3 100644 --- a/admin.py +++ b/admin.py @@ -8,6 +8,10 @@ from regluit import payment from djcelery.admin import TaskState, WorkerState, TaskMonitor, WorkerMonitor, \ IntervalSchedule, CrontabSchedule, PeriodicTask, PeriodicTaskAdmin +from notification.admin import NoticeTypeAdmin, NoticeSettingAdmin, NoticeAdmin +from notification.models import NoticeType, NoticeSetting, Notice, ObservedItem, NoticeQueueBatch + +import pickle class RegluitAdmin(AdminSite): login_template = 'registration/login.html' @@ -67,7 +71,16 @@ class PaymentResponseAdmin(ModelAdmin): pass class ReceiverAdmin(ModelAdmin): - ordering = ('email',) + ordering = ('email',) + +def notice_queue_batch_data(obj): + return pickle.loads(str(obj.pickled_data).decode("base64")) +notice_queue_batch_data.short_description = 'unpickled_data' + +class NoticeQueueBatchAdmin(ModelAdmin): + # show the pickled data in a form humans can parse more easily + list_display = (notice_queue_batch_data,) + pass admin_site = RegluitAdmin("Admin") @@ -99,3 +112,12 @@ admin_site.register(WorkerState, WorkerMonitor) admin_site.register(IntervalSchedule) admin_site.register(CrontabSchedule) admin_site.register(PeriodicTask, PeriodicTaskAdmin) + +# add the django-notification admin panel +# https://github.com/jtauber/django-notification/blob/master/notification/admin.py + +admin_site.register(NoticeQueueBatch, NoticeQueueBatchAdmin) +admin_site.register(NoticeType, NoticeTypeAdmin) +admin_site.register(NoticeSetting, NoticeSettingAdmin) +admin_site.register(Notice, NoticeAdmin) +admin_site.register(ObservedItem) diff --git a/core/management/commands/random_tasks.py b/core/management/commands/random_tasks.py index 2278cf7f..72ab0bb1 100644 --- a/core/management/commands/random_tasks.py +++ b/core/management/commands/random_tasks.py @@ -1,3 +1,10 @@ +""" + +a command that creates a given number of random tasks to test out celery + + +""" + from django.core.management.base import BaseCommand from regluit.core import tasks from regluit.core.models import CeleryTask @@ -11,6 +18,16 @@ class Command(BaseCommand): args = "" def handle(self, num_tasks, action, **options): + """ + actions: + + c: create num_tasks tasks + s: print state of existing tasks + d: delete all tasks + an integer: compute factorial of the integer -- can then follow up with s to find the state + """ + import django + django.db.transaction.enter_transaction_management() if action == 'c': for i in xrange(int(num_tasks)): n = random.randint(1,1000) @@ -41,4 +58,4 @@ class Command(BaseCommand): ct.save() except Exception, e: print e - \ No newline at end of file + django.db.transaction.commit() \ No newline at end of file diff --git a/deploy/crontab_please.txt b/deploy/crontab_please.txt new file mode 100644 index 00000000..ad80fae8 --- /dev/null +++ b/deploy/crontab_please.txt @@ -0,0 +1,23 @@ +# Edit this file to introduce tasks to be run by cron. +# +# Each task to run has to be defined through a single line +# indicating with different fields when the task will be run +# and what command to run for the task +# +# To define the time you can provide concrete values for +# minute (m), hour (h), day of month (dom), month (mon), +# and day of week (dow) or use '*' in these fields (for 'any').# +# Notice that tasks will be started based on the cron's system +# daemon's notion of time and timezones. +# +# Output of the crontab jobs (including errors) is sent through +# email to the user the crontab file belongs to (unless redirected). +# +# For example, you can run a backup of all your user accounts +# at 5 a.m every week with: +# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ +# +# For more information see the manual pages of crontab(5) and cron(8) +# +# m h dom mon dow command +* * * * * cd /opt/regluit; source /opt/regluit/ENV/bin/activate; /opt/regluit/ENV/bin/django-admin.py emit_notices --settings=regluit.settings.please > /opt/regluit/deploy/emit_notices.log 2>&1 ; touch /opt/regluit/deploy/last-cron diff --git a/deploy/crontab_prod.txt b/deploy/crontab_prod.txt new file mode 100644 index 00000000..b7576f03 --- /dev/null +++ b/deploy/crontab_prod.txt @@ -0,0 +1,23 @@ +# Edit this file to introduce tasks to be run by cron. +# +# Each task to run has to be defined through a single line +# indicating with different fields when the task will be run +# and what command to run for the task +# +# To define the time you can provide concrete values for +# minute (m), hour (h), day of month (dom), month (mon), +# and day of week (dow) or use '*' in these fields (for 'any').# +# Notice that tasks will be started based on the cron's system +# daemon's notion of time and timezones. +# +# Output of the crontab jobs (including errors) is sent through +# email to the user the crontab file belongs to (unless redirected). +# +# For example, you can run a backup of all your user accounts +# at 5 a.m every week with: +# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ +# +# For more information see the manual pages of crontab(5) and cron(8) +# +# m h dom mon dow command +* * * * * /opt/regluit/deploy/emit_notices.sh diff --git a/deploy/emit_notices.sh b/deploy/emit_notices.sh new file mode 100644 index 00000000..ca9b597d --- /dev/null +++ b/deploy/emit_notices.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# run django-admin.py emit_notices + +cd /opt/regluit +source /opt/regluit/ENV/bin/activate +/opt/regluit/ENV/bin/django-admin.py emit_notices --settings=regluit.settings.prod > /opt/regluit/deploy/emit_notices.log 2>&1 +touch /opt/regluit/deploy/last-cron diff --git a/deploy/update-prod b/deploy/update-prod index e631f551..68310d40 100755 --- a/deploy/update-prod +++ b/deploy/update-prod @@ -9,4 +9,6 @@ django-admin.py collectstatic --noinput --settings regluit.settings.prod sudo /etc/init.d/apache2 restart sudo /etc/init.d/celeryd restart sudo /etc/init.d/celerybeat restart +chmod +x deploy/emit_notices.sh +crontab deploy/crontab_prod.txt touch /opt/regluit/deploy/last-update diff --git a/deploy/update-regluit b/deploy/update-regluit index c677dae9..6f276194 100755 --- a/deploy/update-regluit +++ b/deploy/update-regluit @@ -15,4 +15,5 @@ django-admin.py collectstatic --noinput --settings regluit.settings.please sudo /etc/init.d/apache2 restart sudo /etc/init.d/celeryd restart sudo /etc/init.d/celerybeat restart -touch /opt/regluit/deploy/last-update +crontab deploy/crontab_please.txt +touch /opt/regluit/deploy/last-update \ No newline at end of file diff --git a/frontend/templates/pledge.html b/frontend/templates/pledge.html index 65db093a..0117617c 100644 --- a/frontend/templates/pledge.html +++ b/frontend/templates/pledge.html @@ -41,7 +41,11 @@
- + + {% if faqmenu == 'modify' %} +

You have pledged ${{preapproval_amount}}. If you would like to modify your pledge, please use the following form.

+ {% endif %} + {% comment %} Even there is a CampaignPledgeForm in frontend/forms.py , the "widget" for premium_id is implemented in HTML here for now. {% endcomment %} @@ -73,7 +77,7 @@ {% endfor %} - +
diff --git a/frontend/templates/pledge_complete.html b/frontend/templates/pledge_complete.html index edaf667b..05a5ed16 100644 --- a/frontend/templates/pledge_complete.html +++ b/frontend/templates/pledge_complete.html @@ -32,7 +32,7 @@ we need the share options and also something like the home page slide show to gi

Thank you!

-

You're now ungluing {{work.title}}.

+

You're now ungluing {{work.title}}.

You can help even more by sharing this campaign with your friends:

Copy/paste this into your site:
diff --git a/frontend/templates/pledge_modify.html b/frontend/templates/pledge_modify.html deleted file mode 100644 index 3570425e..00000000 --- a/frontend/templates/pledge_modify.html +++ /dev/null @@ -1,97 +0,0 @@ -{% extends "basepledge.html" %} - -{% block title %}Pledge (Modify){% endblock %} - -{% block extra_extra_head %} - - -{% endblock %} - -{% block doccontent %} -
-
-
- {{ work.title }} -
- -
-

{{ work.title }}

-

{{ work.author }}

-

{{ work.publication_date }}

- -
- - - -
- -
-
- {{ work.last_campaign.supporters.count }} Ungluers have pledged ${{ work.last_campaign.current_total }} -
-
- book list status -
-
-
-
- -
-
- ${{ work.last_campaign.target }} needed by
- {{ work.last_campaign.deadline }} -
-
- -
-
- -

You have pledged ${{preapproval_amount}}. If you would like to modify your pledge, please use the following form.

- {% comment %} - Even there is a CampaignPledgeForm in frontend/forms.py , the "widget" for premium_id is implemented in HTML here for now. - {% endcomment %} - -
- {% csrf_token %} - {{ form.non_field_errors }} -
{{ form.preapproval_amount.label_tag }}: {{ form.preapproval_amount.errors }}${{ form.preapproval_amount }}
- - {% comment %} - not supported yet; don't display - {{ form.anonymous.label_tag }}: {{ form.anonymous.errors }}{{ form.anonymous }} - {% endcomment %} - - - - -
-
- -{% endblock %} - - diff --git a/frontend/templates/work.html b/frontend/templates/work.html index 9089a91e..681920fc 100644 --- a/frontend/templates/work.html +++ b/frontend/templates/work.html @@ -103,7 +103,7 @@ $j(document).ready(function(){
{% if status == 'ACTIVE' %} {% if pledged %} -
+
{% else %}
{% endif %} diff --git a/frontend/views.py b/frontend/views.py index d3a0f717..1b96d6c9 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -479,7 +479,7 @@ class PledgeModifyView(FormView): """ A view to handle request to change an existing pledge """ - template_name="pledge_modify.html" + template_name="pledge.html" form_class = CampaignPledgeForm embedded = False @@ -529,7 +529,7 @@ class PledgeModifyView(FormView): form_class = self.get_form_class() form = form_class(initial=data) - context.update({'work':work,'campaign':campaign, 'premiums':premiums, 'form':form,'preapproval_amount':preapproval_amount, 'premium_id':premium_id, 'faqmenu': 'pledge'}) + context.update({'work':work,'campaign':campaign, 'premiums':premiums, 'form':form,'preapproval_amount':preapproval_amount, 'premium_id':premium_id, 'faqmenu': 'modify'}) return context diff --git a/static/css/documentation.css b/static/css/documentation.css index 4c6edd62..dbfe9e3a 100644 --- a/static/css/documentation.css +++ b/static/css/documentation.css @@ -570,7 +570,7 @@ h2.thank-you { font-size: 34px; color: #8dc63f; } -.pledge_complete { +.pledge_complete, .pledge_complete a { font-size: 14px; line-height: 17px; margin-bottom: 14px; @@ -579,7 +579,7 @@ h2.thank-you { width: 960px !important; } h3 .pledge_indent { - margin-left: 215px; + margin-left: 240px; } ul.social.pledge { margin-bottom: 150px; diff --git a/static/less/documentation.less b/static/less/documentation.less index 1fdca883..c2743f70 100644 --- a/static/less/documentation.less +++ b/static/less/documentation.less @@ -294,10 +294,10 @@ h2.thank-you { color: @call-to-action; } -.pledge_complete { +.pledge_complete, .pledge_complete a { font-size: 14px; line-height: 17px; - margin-bottom: 14px; + margin-bottom: 14px; } #js-slide .jsmodule.pledge { @@ -305,7 +305,7 @@ h2.thank-you { } h3 .pledge_indent { - margin-left: 215px; + margin-left: 240px; } ul.social.pledge { diff --git a/sysadmin/cloudwatch.py b/sysadmin/cloudwatch.py index 44a9be18..001a09ca 100644 --- a/sysadmin/cloudwatch.py +++ b/sysadmin/cloudwatch.py @@ -3,6 +3,10 @@ import boto # connect up parts of the Amazon infrastructure +# notes: to delete snapshots I have made of instances, one has to deregister the AMI first and then delete the snapshot + +GLUEJAR_ACCOUNT_ID = 439256357102 + ec2 = boto.connect_ec2() cw = boto.connect_cloudwatch() rds = boto.connect_rds() @@ -17,12 +21,23 @@ def all_zones(): def all_rds(): return rds.get_all_dbinstances() + +def all_snapshots(owner=GLUEJAR_ACCOUNT_ID): + """by default, return only snapshots owned by Gluejar -- None returns all snapshots available to us""" + return ec2.get_all_snapshots(owner=owner) def instance(tag_name): try: return ec2.get_all_instances(filters={'tag:Name' : tag_name})[0].instances[0] except Exception, e: return None + +def all_images(owners=(GLUEJAR_ACCOUNT_ID, )): + return ec2.get_all_images(owners=owners) + +def stop_instances(instances): + return ec2.stop_instances(instance_ids=[instance.id for instance in instances]) + def console_output(instance): """returnn console output of instance"""