def invite(campaign_id, data): c = campaign.get(campaign_id) emails = data['to'] message = data['message'] invites = campaign.add_invites(c, emails) if emails: send_invite_email(c, invites, message)
def wrapper(*args, **kwargs): campaign_id = kwargs['id'] c = campaign.get(campaign_id) organizer = campaign.organizer(c) if current_user._get_current_object() != organizer: return message, 401 return fn(*args, **kwargs)
def send_update_post(id=None): c = campaign.get(id) data = request.json if 'to' not in data: return "Updates don't work too well without the 'who'!", 400 if 'message' not in data: return "You must supply a message for the update email!", 400 emails = data['to'].split(',') message = data['message'] send_update_email(c, emails, message) return '', 201
def update(campaign_id, data): c = campaign.get(campaign_id) description = c.description try: description = json.loads(description) except ValueError: description = dict(text=description) if 'updates' not in description: description['updates'] = list() description['updates'].append(data) campaign.update(c, description=json.dumps(description)) return description
def join_get(id=None): c = campaign.get(id) if c is None: return "Unknown campaign.", 404 timestamp_ms = calendar.timegm(c.end.timetuple()) * 1000 _campaign = dict(id=c.id, amount=c.amount, end=timestamp_ms, name=c.name, suggestedContribution=c.suggested_contribution, contributionRequired=string_to_bool(c.suggested_contribution_required)) context = dict(campaign=_campaign, stripe_publishable_key=app.config.get('STRIPE_PUBLIC_KEY'), loggedIn=not current_user.is_anonymous(), success_response="""{"name": "%s", "date": 0, "charge": {"initial": "0", "final": "0"}, "fees": []}""" % c.name) context['require_login'] = not login_fresh() return render_template('pool/join.html', **context)
def join_post(id=None): data = request.json c = campaign.get(id) if c is None: return "Unknown campaign.", 404 usr = current_user._get_current_object() token = data['stripeToken'] full_name = data['fullName'] stripe_private_key = app.config.get('STRIPE_SECRET_KEY') try: user.associate_stripe_token(usr, token, stripe_private_key, True) except (PreviousStripeAssociationError, ExternalAPIUsageError): return make_response(('We boned it, please try again later.', 500)) except (ExternalAPIError, ExternalAPIUnavailableError): return make_response((json.dumps( {'error': 'Request failed due to an external dependency.'}), 424)) charge = c.disburse_funds_when == 'immediately' amount = Decimal(data.get('amount')) curr = data.get('currency') curr = currency.get(curr) fees = fee.get(None, fee_names=['stripe-transaction', 'poold-transaction']) if charge: success = charge_user(usr, c, amount, curr, fees, full_name=full_name) if not success: return make_response(('We boned it, please try again later.', 500)) try: campaign.associate_user(c, usr, 'participant', 'participating', pledge=amount) except DuplicateCampaignUserAssociationError: campaign.update_user_association(c, usr, role=None, pledge=amount) ledger = fee.calculate(fees, amount) ledger['date'] = datetime.utcnow().strftime('%m/%d/%Y') send_receipt_email(c, usr, ledger) ledger = sanitize_json(ledger) ledger['date'] = int(time.time()) * 1000 return make_response( (json.dumps(ledger), 201, [('Content-Type', 'application/json')]))
def join_post(id=None): data = request.json c = campaign.get(id) if c is None: return "Unknown campaign.", 404 usr = current_user._get_current_object() token = data['stripeToken'] full_name = data['fullName'] stripe_private_key = app.config.get('STRIPE_SECRET_KEY') try: user.associate_stripe_token(usr, token, stripe_private_key, True) except (PreviousStripeAssociationError, ExternalAPIUsageError): return make_response(('We boned it, please try again later.', 500)) except (ExternalAPIError, ExternalAPIUnavailableError): return make_response((json.dumps({'error': 'Request failed due to an external dependency.'}), 424)) charge = c.disburse_funds_when == 'immediately' amount = Decimal(data.get('amount')) curr = data.get('currency') curr = currency.get(curr) fees = fee.get(None, fee_names=['stripe-transaction', 'poold-transaction']) if charge: success = charge_user(usr, c, amount, curr, fees, full_name=full_name) if not success: return make_response(('We boned it, please try again later.', 500)) try: campaign.associate_user(c, usr, 'participant', 'participating', pledge=amount) except DuplicateCampaignUserAssociationError: campaign.update_user_association(c, usr, role=None, pledge=amount) ledger = fee.calculate(fees, amount) ledger['date'] = datetime.utcnow().strftime('%m/%d/%Y') send_receipt_email(c, usr, ledger) ledger = sanitize_json(ledger) ledger['date'] = int(time.time()) * 1000 return make_response((json.dumps(ledger), 201, [('Content-Type', 'application/json')]))
def join_get(id=None): c = campaign.get(id) if c is None: return "Unknown campaign.", 404 timestamp_ms = calendar.timegm(c.end.timetuple()) * 1000 _campaign = dict(id=c.id, amount=c.amount, end=timestamp_ms, name=c.name, suggestedContribution=c.suggested_contribution, contributionRequired=string_to_bool( c.suggested_contribution_required)) context = dict( campaign=_campaign, stripe_publishable_key=app.config.get('STRIPE_PUBLIC_KEY'), loggedIn=not current_user.is_anonymous(), success_response= """{"name": "%s", "date": 0, "charge": {"initial": "0", "final": "0"}, "fees": []}""" % c.name) context['require_login'] = not login_fresh() return render_template('pool/join.html', **context)
def view(id): c = campaign.get(id) usr = current_user._get_current_object() if c is None: return '', 404 organizer = campaign.organizer(c) organizer_is_viewing = usr == organizer if not usr.is_anonymous(): campaign_association = [p for p in usr.campaigns if p.campaign == c] campaign_association = campaign_association[0] if campaign_association else None if campaign_association is not None: campaign_association.pledge = campaign_association.pledge.quantize(QUANTIZE_DOLLARS) if campaign_association.pledge else 0 else: campaign_association = None is_participant = campaign_association is not None community = list() for participant in c.participants: gravatar_url = app.gravatar(participant.user.email or '*****@*****.**', size=60) joined_date_ms = calendar.timegm(participant.created.timetuple()) * 1000 new = {'name': participant.user.display_name, 'username': participant.user.username, 'email': participant.user.email, 'link': '/profile/%s' % participant.user.username, 'gravatar': gravatar_url, 'isOrganizer': participant.user == organizer, 'joinedDate': joined_date_ms, 'amount': str(participant.pledge) if participant.pledge else 0, 'invitee': False} if not organizer_is_viewing: base_name = new['email'].split('@')[0] new['email'] = '%s@...' % base_name community.append(new) for invitee in c.invitees: if invitee.accepted is not None: continue gravatar_url = app.gravatar(invitee.user.email, size=60) if invitee.user else None gravatar_url = app.gravatar(invitee.email, size=60) if gravatar_url is None else gravatar_url invited_date_ms = calendar.timegm(invitee.created.timetuple()) * 1000 new = {'name': invitee.user.display_name if invitee.user else None, 'username': invitee.user.username if invitee.user else None, 'email': invitee.email, 'link': '/profile/%s' % participant.user.username if invitee.user else None, 'gravatar': gravatar_url, 'isOrganizer': False, 'joinedDate': invited_date_ms, 'invitee': True, 'amount': 0} if not organizer_is_viewing: base_name = new['email'].split('@')[0] new['email'] = '%s@...' % base_name community.append(new) timestamp_ms = calendar.timegm(c.end.timetuple()) * 1000 is_active = time.time() * 1000 <= timestamp_ms # This is a temporary shim while we transition campaign descriptions to # JSON data try: c.description = json.loads(c.description) except ValueError: c.description = {'text': c.description} context = dict(title="Pool: %s" % c.name, campaign=c, organizer=organizer, participants=json.dumps(community), timestamp=timestamp_ms, invitees=c.participants, is_organizer=organizer_is_viewing, is_participant=is_participant, is_active=is_active, campaign_association=campaign_association) return render_template('pool/view.html', **context)
def view(id): c = campaign.get(id) usr = current_user._get_current_object() if c is None: return '', 404 organizer = campaign.organizer(c) organizer_is_viewing = usr == organizer if not usr.is_anonymous(): campaign_association = [p for p in usr.campaigns if p.campaign == c] campaign_association = campaign_association[ 0] if campaign_association else None if campaign_association is not None: campaign_association.pledge = campaign_association.pledge.quantize( QUANTIZE_DOLLARS) if campaign_association.pledge else 0 else: campaign_association = None is_participant = campaign_association is not None community = list() for participant in c.participants: gravatar_url = app.gravatar(participant.user.email or '*****@*****.**', size=60) joined_date_ms = calendar.timegm( participant.created.timetuple()) * 1000 new = { 'name': participant.user.display_name, 'username': participant.user.username, 'email': participant.user.email, 'link': '/profile/%s' % participant.user.username, 'gravatar': gravatar_url, 'isOrganizer': participant.user == organizer, 'joinedDate': joined_date_ms, 'amount': str(participant.pledge) if participant.pledge else 0, 'invitee': False } if not organizer_is_viewing: base_name = new['email'].split('@')[0] new['email'] = '%s@...' % base_name community.append(new) for invitee in c.invitees: if invitee.accepted is not None: continue gravatar_url = app.gravatar(invitee.user.email, size=60) if invitee.user else None gravatar_url = app.gravatar( invitee.email, size=60) if gravatar_url is None else gravatar_url invited_date_ms = calendar.timegm(invitee.created.timetuple()) * 1000 new = { 'name': invitee.user.display_name if invitee.user else None, 'username': invitee.user.username if invitee.user else None, 'email': invitee.email, 'link': '/profile/%s' % participant.user.username if invitee.user else None, 'gravatar': gravatar_url, 'isOrganizer': False, 'joinedDate': invited_date_ms, 'invitee': True, 'amount': 0 } if not organizer_is_viewing: base_name = new['email'].split('@')[0] new['email'] = '%s@...' % base_name community.append(new) timestamp_ms = calendar.timegm(c.end.timetuple()) * 1000 is_active = time.time() * 1000 <= timestamp_ms # This is a temporary shim while we transition campaign descriptions to # JSON data try: c.description = json.loads(c.description) except ValueError: c.description = {'text': c.description} context = dict(title="Pool: %s" % c.name, campaign=c, organizer=organizer, participants=json.dumps(community), timestamp=timestamp_ms, invitees=c.participants, is_organizer=organizer_is_viewing, is_participant=is_participant, is_active=is_active, campaign_association=campaign_association) return render_template('pool/view.html', **context)