2017-10-05 23:09:16 +00:00
|
|
|
from django.conf import settings
|
2017-11-16 01:29:50 +00:00
|
|
|
from django.contrib.auth.models import User
|
2017-10-05 23:09:16 +00:00
|
|
|
from django.core.mail import EmailMultiAlternatives
|
|
|
|
from functools import wraps
|
|
|
|
|
|
|
|
|
|
|
|
class MonkeyPatchMiddleware(object):
|
|
|
|
''' Ensures that our monkey patching only gets called after it is safe to do so.'''
|
|
|
|
|
|
|
|
def process_request(self, request):
|
|
|
|
do_monkey_patch()
|
|
|
|
|
|
|
|
|
|
|
|
def do_monkey_patch():
|
|
|
|
patch_stripe_card_defaults()
|
2017-11-16 01:29:50 +00:00
|
|
|
patch_conference_schedule()
|
2017-10-05 23:09:16 +00:00
|
|
|
|
|
|
|
# Remove this function from existence
|
|
|
|
global do_monkey_patch
|
|
|
|
do_monkey_patch = lambda: None
|
|
|
|
|
|
|
|
|
|
|
|
def patch_stripe_card_defaults():
|
|
|
|
from pinax.stripe.actions import sources
|
|
|
|
from collections import defaultdict
|
|
|
|
|
|
|
|
old_sync_card = sources.sync_card
|
|
|
|
|
2017-11-16 01:29:50 +00:00
|
|
|
@wraps(old_sync_card)
|
2017-10-05 23:09:16 +00:00
|
|
|
def sync_card(customer, source):
|
|
|
|
d = defaultdict(str)
|
|
|
|
d.update(source)
|
|
|
|
return old_sync_card(customer, d)
|
|
|
|
|
|
|
|
sources.sync_card = sync_card
|
2017-11-16 01:29:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
def patch_conference_schedule():
|
|
|
|
from symposion.schedule import views as sv
|
|
|
|
from symposion.schedule import models as sm
|
|
|
|
|
|
|
|
old_schedule_json = sv._schedule_json
|
|
|
|
|
|
|
|
@wraps(old_schedule_json)
|
|
|
|
def schedule_json(request):
|
|
|
|
schedule = old_schedule_json(request)
|
|
|
|
|
|
|
|
for slot_data in schedule:
|
|
|
|
slot = sm.Slot.objects.get(id=slot_data["conf_key"])
|
|
|
|
presentation = slot.content
|
|
|
|
if presentation is not None:
|
|
|
|
update_presentation(request, slot_data, presentation)
|
2017-11-16 01:32:07 +00:00
|
|
|
elif slot.kind.label.lower() == "keynote":
|
2017-11-16 01:29:50 +00:00
|
|
|
update_keynote(request, slot_data)
|
2017-11-18 00:23:54 +00:00
|
|
|
elif slot.kind.label.lower() == "housekeeping":
|
2017-11-18 00:26:41 +00:00
|
|
|
update_housekeeping(request, slot_data)
|
2017-11-16 01:29:50 +00:00
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return schedule
|
|
|
|
|
|
|
|
def update_presentation(request, slot_data, presentation):
|
|
|
|
try:
|
2017-11-16 01:57:36 +00:00
|
|
|
slot_data["reviewers"] = (
|
2017-11-16 01:29:50 +00:00
|
|
|
presentation.speaker.conferencespeaker.reviewer
|
|
|
|
if request.user.is_staff else ["redacted"]
|
|
|
|
)
|
|
|
|
slot_data["license"] = "CC BY-SA"
|
|
|
|
slot_data["released"] = presentation.proposal_base.talkproposal.recording_release
|
|
|
|
slot_data["twitter_id"] = presentation.speaker.conferencespeaker.twitter_username
|
|
|
|
except Exception as e:
|
|
|
|
print e
|
|
|
|
|
|
|
|
def update_keynote(request, slot_data):
|
|
|
|
keynotes = {
|
|
|
|
"Brandon Rhodes": (User.objects.get(username="brandon").email, "brandon_rhodes"),
|
|
|
|
"Carina C. Zona": (User.objects.get(username="cczona").email, "cczona"),
|
|
|
|
}
|
|
|
|
for speaker, values in keynotes.items():
|
|
|
|
print speaker
|
|
|
|
if speaker in slot_data["name"]:
|
|
|
|
author_name = speaker
|
|
|
|
author_email, author_twitter_id = values
|
|
|
|
|
2017-11-18 00:23:54 +00:00
|
|
|
slot_data["name"] = "Keynote"
|
2017-11-16 01:29:50 +00:00
|
|
|
slot_data["authors"] = [author_name]
|
|
|
|
slot_data["contact"] = [
|
|
|
|
author_email
|
|
|
|
] if request.user.is_staff else ["redacted"]
|
2017-11-18 00:23:54 +00:00
|
|
|
slot_data["abstract"] = "Keynote presentation from North Bay Python 2017 by " + author_name
|
|
|
|
slot_data["description"] = "Keynote presentation from North Bay Python 2017 by " + author_name
|
2017-11-16 01:29:50 +00:00
|
|
|
slot_data["conf_url"] = "https://2017.northbaypython.org"
|
2017-11-16 02:22:39 +00:00
|
|
|
slot_data["cancelled"] = False
|
2017-11-16 01:57:36 +00:00
|
|
|
slot_data["reviewers"] = ""
|
2017-11-16 01:33:48 +00:00
|
|
|
slot_data["license"] = "CC BY-SA"
|
2017-11-16 01:29:50 +00:00
|
|
|
slot_data["twitter_id"] = author_twitter_id
|
|
|
|
slot_data["released"] = True
|
|
|
|
|
2017-11-18 00:23:54 +00:00
|
|
|
def update_housekeeping(request, slot_data):
|
|
|
|
slot_data["contact"] = [
|
|
|
|
"spam@northbaypython.org"
|
|
|
|
] if request.user.is_staff else ["redacted"]
|
|
|
|
|
|
|
|
|
2017-11-16 01:29:50 +00:00
|
|
|
sv._schedule_json = schedule_json
|