Exemplo n.º 1
0
def standardDate(event):
    """
    Output a nicely formatted date for an event
    """
    startTime = localize(event.start_time)
    if event.end_time:
        endTime = localize(event.end_time)
        if endTime.day == startTime.day:
            event_date = startTime.strftime('%A') + ', ' + startTime.strftime(
                '%B') + ' ' + startTime.strftime('%d').lstrip('0') + ', '
            event_date += startTime.strftime('%I:%M%p').lower(
            ) + ' - ' + endTime.strftime('%I:%M%p').lower().lstrip('0')
        else:
            event_date = startTime.strftime('%A') + ', ' + startTime.strftime(
                '%B') + ' ' + startTime.strftime('%d').lstrip(
                    '0') + ', ' + startTime.strftime('%I:%M%p').lower().lstrip(
                        '0') + ' - '
            event_date += endTime.strftime('%A') + ', ' + startTime.strftime(
                '%B') + ' ' + startTime.strftime('%d').lstrip(
                    '0') + ', ' + endTime.strftime('%I:%M%p').lower().lstrip(
                        '0')
    else:
        event_date = startTime.strftime('%A') + ', ' + startTime.strftime(
            '%B') + ' ' + startTime.strftime('%d').lstrip('0') + ', '
        event_date += startTime.strftime('%I:%M%p').lower().lstrip('0')
    return event_date
Exemplo n.º 2
0
def shouldShortenEndTime(endTime, startTime):
    """
    Determin whether to shorten the end time
    """
    # Make sure the two values are not null
    if endTime is None or startTime is None:
        return False
    # See if the two are on the same day
    endTime = localize(endTime)
    startTime = localize(startTime)
    return endTime.day == startTime.day
Exemplo n.º 3
0
def standardTime(time):
    """
    Output a datetime object to text in standard format
    """
    time = localize(time)
    return time.strftime('%m/%d/%Y').lstrip('0') + ' @ ' + time.strftime(
        '%I:%M%p').lstrip('0') if time is not None else ''
Exemplo n.º 4
0
def sendEventConfirmationEmail(purchase, manual=False, inviter=None):
    """
    Send event confirmation
    """
    user = purchase.owner
    event = purchase.event
    event_month = DateFormat(localize(event.start_time))
    event_month = event_month.format('M')
    event_day = DateFormat(localize(event.start_time))
    event_day = event_day.format('j')
    organizers = event.organizers.all()
    organizer_list_html = ''
    for organizer in organizers:
        if organizer.image:
            organizer_image = """
                <img width="38" class="organizer_logo" src='""" + organizer.image.source.url + """' style="outline: none; text-decoration: none; width:40px; max-width: 40px; float: left; display: block;" align="left" />
            """
        else:
            organizer_image = ''
        organizer_list_html += """
            <tr class="organizer" style="vertical-align: top; text-align: left; padding: 0;" align="left">
                <td width="40" class="three sub-columns center text-pad-left" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: center; min-width: 0px; width: 25%; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0px 10px 10px;" align="center" valign="top">
                    """ + organizer_image + """
                </td>
                <td class="nine sub-columns last" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: left; min-width: 0px; width: 75%; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0px 0px 10px;" align="left" valign="top">
                    <div class="organizer_name" style="font-size: 16px; margin-top: 10px;">
                        """ + organizer.name + """
                    </div>
                </td>
                <td class="expander" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: left; visibility: hidden; width: 0px; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0;" align="left" valign="top">
                </td>
            </tr>
        """
    to = [{
        'email': user.email,
        'name': user.first_name + ' ' + user.last_name
    }]
    if manual:
        subject = 'You\'re on the Guest List - \'' + event.name + '\''
        header_text = 'You have been added to the guest list by <b>' + inviter.profile.name + '</b>'
        from_name = inviter.profile.name
    else:
        subject = 'Confirmation for \'' + event.name + '\''
        header_text = 'CONFIRMATION | Your tickets to <b>' + organizers[
            0].name + '\'s</b> Event'
        from_name = organizers[0].name
    template = 'confirm-rsvp'
    items = Purchase_item.objects.filter(purchase = purchase) \
                                 .prefetch_related('ticket')
    attFiles = []
    tickets = {}
    ticket_list_html = ''
    for item in items:
        if item.ticket.id in tickets:
            tickets[item.ticket.id]['quantity'] += 1
        else:
            tickets[item.ticket.id] = {
                'name': item.ticket.name,
                'description': item.ticket.description,
                'price': item.ticket.price,
                'quantity': 1
            }
            if item.ticket.attachment:
                attFiles.append(item.ticket.attachment.url)
    for k, ticket in tickets.iteritems():
        if ticket['price'] == 0:
            ticket_price = 'Free'
        else:
            ticket_price = '$' + str(ticket['price'])
        ticket_list_html += """
            <tr class="ticket_top" style="vertical-align: top; text-align: left; padding: 0;" align="left">
                <td class="two sub-columns" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: left; min-width: 0px; width: 16.666666%; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0px 10px 10px 0px;" align="left" valign="top">
                    <div class="ticket_count left-text-pad" style="padding-left: 10px; margin-top: 0; font-size: 20px; font-weight: 500; padding-top: 8px;">
                        """ + str(ticket['quantity']) + """x
                    </div>
                </td>
                <td class="two sub-columns" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: left; min-width: 0px; width: 16.666666%; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0px 10px 10px 0px;" align="left" valign="top">
                    <div class="ticket_price" style="margin-top: 0; color: #FFF; border-radius: 2px; text-align: center; font-weight: 500; background: #4963E4; padding: 8px 0;" align="center">
                        """ + ticket_price + """
                    </div>
                </td>
                <td class="eight sub-columns last" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: left; min-width: 0px; width: 66.666666%; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0px 0px 10px;" align="left" valign="top">
                    <div class="ticket_name right-text-pad" style="padding-right: 10px; margin-top: 0; font-weight: 500; padding-top: 8px;">
                        """ + ticket['name'] + """
                    </div>
                </td>
                <td class="expander" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: left; visibility: hidden; width: 0px; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0;" align="left" valign="top"></td>
            </tr>
            <tr class="ticket_bottom" style="vertical-align: top; text-align: left; border-bottom-width: thin; border-bottom-color: #F6F6F6; border-bottom-style: solid; padding: 0;" align="left">
                <td class="one sub-columns" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: left; min-width: 0px; width: 8.333333%; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0px 10px 10px 0px;" align="left" valign="top">
                </td>
                <td class="one sub-columns" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: left; min-width: 0px; width: 8.333333%; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0px 10px 10px 0px;" align="left" valign="top">
                </td>
                <td class="ten sub-columns last" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: left; min-width: 0px; width: 83.333333%; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0px 0px 10px;" align="left" valign="top">
                    <div class="ticket_description right-text-pad" style="padding-right: 10px; padding-bottom: 10px !important;">
                        """ + ticket['description'] + """
                    </div>
                </td>
                <td class="expander" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; text-align: left; visibility: hidden; width: 0px; line-height: 19px; font-size: 14px; color: #4A4A4A !important; margin: 0; padding: 0;" align="left" valign="top">
                </td>
            </tr>
        """
    reciept_info = ''
    if purchase.amount > 0 and not manual:
        reciept_info = 'TOTAL: $' + str(purchase.amount)
    if event.slug:
        event_url = 'https://bazaarboy.com/' + event.slug
    else:
        event_url = 'https://bazaarboy.com/event/' + str(event.id)
    startTime = localize(event.start_time)
    if event.end_time:
        endTime = localize(event.end_time)
        if endTime.day == startTime.day:
            event_date = '<span style="font-weight: 600;">' + startTime.strftime(
                '%A') + '</span>, '
            event_date += startTime.strftime('%I:%M%p').lower(
            ) + ' - ' + endTime.strftime('%I:%M%p').lower()
        else:
            event_date = startTime.strftime('%A') + ', ' + startTime.strftime(
                '%I:%M%p').lower() + ' - '
            event_date += endTime.strftime('%A') + ', ' + endTime.strftime(
                '%I:%M%p').lower()
    else:
        event_date = '<span style="font-weight: 600;">' + startTime.strftime(
            '%A') + '</span>, '
        event_date += startTime.strftime('%I:%M%p').lower()
    mergeVars = [{
        'rcpt':
        user.email,
        'vars': [{
            'name': 'organizer_list',
            'content': organizer_list_html
        }, {
            'name': 'ticket_list',
            'content': ticket_list_html
        }, {
            'name': 'event_link',
            'content': event_url
        }, {
            'name': 'header_text',
            'content': header_text
        }, {
            'name': 'event_name',
            'content': event.name
        }, {
            'name': 'event_month',
            'content': event_month
        }, {
            'name': 'event_day',
            'content': event_day
        }, {
            'name': 'event_date',
            'content': event_date
        }, {
            'name': 'event_location',
            'content': event.location
        }, {
            'name': 'reciept_info',
            'content': reciept_info
        }]
    }]
    attachments = Ticket_attachment.getTicketAttachments(purchase, items)
    for f in attFiles:
        parts = f.split('/')
        name, filetype, tail = parts[-1].partition('.pdf')
        if settings.BBOY_ENV == 'development':
            content = open(f.lstrip('/')).read().encode('base64')
        else:
            content = urllib2.urlopen(f).read().encode('base64')
        attachments.append({
            'type': mimetypes.guess_type(f)[0],
            'name': name + filetype,
            'content': content
        })
    return sendEmails(to, from_name, subject, template, mergeVars, attachments)
Exemplo n.º 5
0
def sendEventReminder(purchase, tz):
    """
    Send event reminder 24 hours before event
    """
    user = purchase.owner
    event = purchase.event
    event_month = DateFormat(localize(event.start_time))
    event_month = event_month.format('M')
    event_day = DateFormat(localize(event.start_time))
    event_day = event_day.format('j')
    organizers = event.organizers.all()
    to = [{
        'email': user.email,
        'name': user.first_name + ' ' + user.last_name
    }]
    subject = 'Reminder for ' + event.name
    from_name = organizers[0].name
    from_email = ''
    if organizers[0].email:
        from_email = organizers[0].email
    template = 'event-reminder'
    items = Purchase_item.objects.filter(purchase = purchase) \
                                 .prefetch_related('ticket')
    reciept_info = ''
    if event.slug:
        event_url = 'https://bazaarboy.com/' + event.slug
    else:
        event_url = 'https://bazaarboy.com/event/' + str(event.id)
    startTime = event.start_time.astimezone(tz)
    startTime = tz.normalize(startTime)
    if event.end_time:
        endTime = event.end_time.astimezone(tz)
        endTime = tz.normalize(endTime)
        if endTime.day == startTime.day:
            event_date = '<span style="font-weight: 600;">' + startTime.strftime(
                '%A') + '</span>, '
            event_date += startTime.strftime('%I:%M%p').lower(
            ) + ' - ' + endTime.strftime('%I:%M%p').lower()
        else:
            event_date = startTime.strftime('%A') + ', ' + startTime.strftime(
                '%I:%M%p').lower() + ' - '
            event_date += endTime.strftime('%A') + ', ' + endTime.strftime(
                '%I:%M%p').lower()
    else:
        event_date = '<span style="font-weight: 600;">' + startTime.strftime(
            '%A') + '</span>, '
        event_date += startTime.strftime('%I:%M%p').lower()
    event_address = ''
    event_map = ''
    if event.latitude and event.longitude:
        event_address += "<div style='margin-bottom:5px; text-decoration:underline;'>Event Address</div>"
        address = Geocoder.reverse_geocode(event.latitude, event.longitude)
        address = [x.strip() for x in address[0].formatted_address.split(',')]
        for address_component in address:
            if address_component != 'USA':
                event_address += str(address_component) + "<br />"
        event_map = u'<a href="https://maps.google.com/?saddr=' + str(
            event.latitude
        ) + ',' + str(
            event.longitude
        ) + '"><img src="http://maps.google.com/maps/api/staticmap?center=' + str(
            event.latitude) + ',' + str(
                event.longitude) + '&zoom=15&size=300x150&markers=' + str(
                    event.latitude) + ',' + str(event.longitude) + '" /></a>'
    mergeVars = [{
        'rcpt':
        user.email,
        'vars': [{
            'name': 'first_name',
            'content': user.first_name
        }, {
            'name': 'organizer_email',
            'content': from_email
        }, {
            'name': 'event_link',
            'content': event_url
        }, {
            'name': 'event_name',
            'content': event.name
        }, {
            'name': 'event_month',
            'content': event_month
        }, {
            'name': 'event_day',
            'content': event_day
        }, {
            'name': 'event_date',
            'content': event_date
        }, {
            'name': 'event_location',
            'content': event.location
        }, {
            'name': 'event_address',
            'content': event_address
        }, {
            'name': 'event_map',
            'content': event_map
        }]
    }]
    attachments = Ticket_attachment.getTicketAttachments(purchase, items)
    return sendEmails(to, from_name, subject, template, mergeVars, attachments)
Exemplo n.º 6
0
def sendManualEventInvite(event, email, subject, inviter, custom_message=''):
    if Unsubscribe.objects.filter(email=email).exists():
        return False
    event_month = DateFormat(localize(event.start_time))
    event_month = event_month.format('M')
    event_day = DateFormat(localize(event.start_time))
    event_day = event_day.format('j')
    organizers = event.organizers.all()
    organizer_list_html = ''
    if event.slug:
        event_url = 'https://bazaarboy.com/' + event.slug
    else:
        event_url = 'https://bazaarboy.com/event/' + str(event.id)
    for organizer in organizers:
        if organizer.image:
            organizer_image = """
                <td class='logo' style='-webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: middle; text-align: left; color: #222222; font-family: 'Avenir', 'Helvetica', 'Arial', sans-serif; font-weight: normal; line-height: 19px; font-size: 14px; width: 40px !important; margin: 0; padding: 0px 0px 0;' align='left' valign='middle'>
                    <img src='""" + organizer.image.source.url.split(
                "?", 1
            )[0] + """' style='outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; width: 35px !important; max-width: 35px !important; float: left; clear: both; display: block;' align='left' />
                </td>
            """
        else:
            organizer_image = ''
        organizer_list_html += """
            <table class='organizer' style='border-collapse: separate; vertical-align: top; text-align: left; margin-bottom: 10px; padding: 0; font-family: 'Avenir', 'Helvetica', 'Arial', sans-serif;'>
                <tr style='vertical-align: top; text-align: left; padding: 0; font-family: 'Avenir', 'Helvetica', 'Arial', sans-serif;' align='left'>
                    """ + organizer_image + """
                    <td class='name' style='-webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: middle; text-align: left; color: #222222; font-family: "Avenir", "Helvetica", "Arial", sans-serif; font-weight: normal; line-height: 19px; font-size: 14px; margin: 0; padding: 0px 0px 0 10px; padding-left: 5px;' align='left' valign='middle'>
                        """ + organizer.name + """
                    </td>
                </tr>
            </table>
        """
    if custom_message.strip() != '':
        custom_message = "<i>" + custom_message + "</i>"
    to = [{'email': email}]
    if subject.strip() == '':
        subject = 'Invitation to \'' + event.name + '\''
    key = hashlib.sha512(email + UNSUBSCRIBE_SALT).hexdigest()
    template = 'event-invitation-1'
    mergeVars = [{
        'rcpt':
        email,
        'vars': [{
            'name': 'organizer_list',
            'content': organizer_list_html
        }, {
            'name': 'inviter',
            'content': inviter
        }, {
            'name': 'custom_message',
            'content': custom_message
        }, {
            'name': 'event_link',
            'content': event_url
        }, {
            'name': 'event_id',
            'content': event.id
        }, {
            'name': 'event_name',
            'content': event.name
        }, {
            'name': 'event_month',
            'content': event_month
        }, {
            'name': 'event_day',
            'content': event_day
        }, {
            'name': 'event_summary',
            'content': event.summary
        }, {
            'name': 'user_email',
            'content': email
        }, {
            'name': 'unsub_key',
            'content': key
        }]
    }]
    return sendEmails(to, inviter, subject, template, mergeVars)