Ejemplo n.º 1
0
    def form_valid(self, form):
        expense = form.save(commit=False)
        expense.user = self.request.user
        expense.camp = self.camp
        expense.save()

        # a message for the user
        messages.success(
            self.request,
            "The expense has been saved. It is now awaiting approval by the economy team.",
        )

        # send an email to the economy team
        add_outgoing_email(
            "emails/expense_awaiting_approval_email.txt",
            formatdict=dict(expense=expense),
            subject="New %s expense for %s Team is awaiting approval" %
            (expense.camp.title, expense.responsible_team.name),
            to_recipients=[settings.ECONOMYTEAM_EMAIL],
        )

        # return to the expense list page
        return HttpResponseRedirect(
            reverse('economy:expense_list',
                    kwargs={'camp_slug': self.camp.slug}))
Ejemplo n.º 2
0
    def form_valid(self, form):
        expense = form.save(commit=False)
        expense.user = self.request.user
        expense.camp = self.camp
        expense.creditor = self.credebtor
        expense.save()

        # a message for the user
        messages.success(
            self.request,
            "The expense has been saved. It is now awaiting approval by the economy team.",
        )

        # send an email to the economy team
        add_outgoing_email(
            responsible_team=Team.objects.get(
                camp=self.camp,
                name=settings.ECONOMY_TEAM_NAME,
            ),
            text_template="emails/expense_awaiting_approval_email.txt",
            formatdict={"expense": expense},
            subject="New %s expense for %s Team is awaiting approval" %
            (expense.camp.title, expense.responsible_team.name),
            to_recipients=[settings.ECONOMYTEAM_EMAIL],
        )

        # return to the expense list page
        return HttpResponseRedirect(
            reverse("economy:expense_list",
                    kwargs={"camp_slug": self.camp.slug}), )
Ejemplo n.º 3
0
 def post(self, request, **kwargs):
     form = ContactRideForm(request.POST)
     if form.is_valid():
         ride = self.get_object()
         info_team = Team.objects.get(camp=self.camp, name="Info")
         add_outgoing_email(
             responsible_team=info_team,
             text_template="rideshare/emails/contact_mail.txt",
             to_recipients=[
                 ride.user.emailaddress_set.get(primary=True).email
             ],
             formatdict=dict(
                 rideshare_url="https://bornhack.dk{}".format(
                     reverse(
                         "rideshare:detail",
                         kwargs={
                             "camp_slug": self.camp.slug,
                             "pk": ride.pk
                         },
                     )),
                 message=form.cleaned_data["message"],
             ),
             subject="BornHack rideshare message!",
         )
     messages.info(request, "Your message has been sent.")
     return HttpResponseRedirect(ride.get_absolute_url())
Ejemplo n.º 4
0
    def form_valid(self, form):
        revenue = form.save(commit=False)
        revenue.user = self.request.user
        revenue.camp = self.camp
        revenue.debtor = self.credebtor
        revenue.save()

        # a message for the user
        messages.success(
            self.request,
            "The revenue has been saved. It is now awaiting approval by the economy team.",
        )

        # send an email to the economy team
        add_outgoing_email(
            "emails/revenue_awaiting_approval_email.txt",
            formatdict=dict(revenue=revenue),
            subject="New %s revenue for %s Team is awaiting approval"
            % (revenue.camp.title, revenue.responsible_team.name),
            to_recipients=[settings.ECONOMYTEAM_EMAIL],
        )

        # return to the revenue list page
        return HttpResponseRedirect(
            reverse("economy:revenue_list", kwargs={"camp_slug": self.camp.slug})
        )
Ejemplo n.º 5
0
def send_revenue_rejected_email(revenue):
    """
    Sends an revenue-rejected email to the user who created the revenue
    """
    add_outgoing_email(
        "emails/revenue_rejected_email.txt",
        formatdict=dict(revenue=revenue),
        subject="Your revenue for %s has been rejected." % revenue.camp.title,
        to_recipients=[revenue.user.emailaddress_set.get(primary=True).email],
    )
Ejemplo n.º 6
0
def send_expense_rejected_email(expense):
    """
    Sends an expense-rejected email to the user who created the expense
    """
    add_outgoing_email(
        "emails/expense_rejected_email.txt",
        formatdict=dict(expense=expense),
        subject="Your expense for %s has been rejected." % expense.camp.title,
        to_recipients=[expense.user.emailaddress_set.get(primary=True).email],
    )
Ejemplo n.º 7
0
def send_expense_approved_email(expense):
    """
    Sends an expense-approved email to the user who created the expense
    """
    economy_team = Team.objects.get(camp=expense.camp, name=settings.ECONOMY_TEAM_NAME)
    add_outgoing_email(
        responsible_team=economy_team,
        text_template="emails/expense_approved_email.txt",
        formatdict={"expense": expense},
        subject="Your expense for %s has been approved." % expense.camp.title,
        to_recipients=[expense.user.emailaddress_set.get(primary=True).email],
    )
Ejemplo n.º 8
0
def send_revenue_rejected_email(revenue):
    """
    Sends an revenue-rejected email to the user who created the revenue
    """
    economy_team = Team.objects.get(camp=revenue.camp, name=settings.ECONOMY_TEAM_NAME)
    add_outgoing_email(
        responsible_team=economy_team,
        text_template="emails/revenue_rejected_email.txt",
        formatdict={"revenue": revenue},
        subject="Your revenue for %s has been rejected." % revenue.camp.title,
        to_recipients=[revenue.user.emailaddress_set.get(primary=True).email],
    )
Ejemplo n.º 9
0
def send_accountingsystem_expense_email(expense):
    """
    Sends an email to the accountingsystem with the invoice as an attachment,
    and with the expense uuid and description in email subject
    """
    add_outgoing_email(
        "emails/accountingsystem_expense_email.txt",
        formatdict=dict(expense=expense),
        subject="Expense %s for %s" % (expense.pk, expense.camp.title),
        to_recipients=[settings.ACCOUNTINGSYSTEM_EMAIL],
        attachment=expense.invoice.read(),
        attachment_filename=os.path.basename(expense.invoice.file.name),
    )
Ejemplo n.º 10
0
def send_accountingsystem_revenue_email(revenue):
    """
    Sends an email to the accountingsystem with the invoice as an attachment,
    and with the revenue uuid and description in email subject
    """
    economy_team = Team.objects.get(camp=revenue.camp, name=settings.ECONOMY_TEAM_NAME)
    add_outgoing_email(
        responsible_team=economy_team,
        text_template="emails/accountingsystem_revenue_email.txt",
        formatdict={"revenue": revenue},
        subject=f"Revenue {revenue.pk} for {revenue.camp.title}",
        to_recipients=[settings.ACCOUNTINGSYSTEM_EMAIL],
        attachment=revenue.invoice.read(),
        attachment_filename=os.path.basename(revenue.invoice.file.name),
    )
Ejemplo n.º 11
0
def add_event_scheduled_email(eventinstance, action):
    formatdict = {"eventinstance": eventinstance, "action": action}
    recipients = [
        speaker.email for speaker in eventinstance.event.speakers.all()
    ]
    recipients.append(eventinstance.event.proposal.user.email)

    try:
        content_team = Team.objects.get(camp=eventinstance.camp,
                                        name="Content")
    except ObjectDoesNotExist as e:
        logger.info("There is no team with name Content: {}".format(e))
        return False

    # loop over unique recipients and send an email to each
    for rcpt in set(recipients):
        return add_outgoing_email(
            responsible_team=content_team,
            text_template="emails/event_scheduled.txt",
            html_template="emails/event_scheduled.html",
            to_recipients=rcpt,
            formatdict=formatdict,
            subject=
            f"Your {eventinstance.camp.title} event '{eventinstance.event.title}' has been {action}!",
            hold=True,
        )
Ejemplo n.º 12
0
def send_accountingsystem_expense_email(expense):
    """
    Sends an email to the accountingsystem with the invoice as an attachment,
    and with the expense uuid and description in email subject
    """
    economy_team = Team.objects.get(camp=expense.camp,
                                    name=settings.ECONOMY_TEAM_NAME)
    add_outgoing_email(
        responsible_team=economy_team,
        text_template="emails/accountingsystem_expense_email.txt",
        formatdict=dict(expense=expense),
        subject="Expense %s for %s" % (expense.pk, expense.camp.title),
        to_recipients=[settings.ACCOUNTINGSYSTEM_EMAIL],
        attachment=expense.invoice.read(),
        attachment_filename=os.path.basename(expense.invoice.file.name),
    )
Ejemplo n.º 13
0
def add_new_membership_email(membership):
    formatdict = {
        "team":
        membership.team.name,
        "camp":
        membership.team.camp.title,
        "memberlist_link":
        "https://bornhack.dk/{}/teams/{}/members".format(
            membership.team.camp.slug,
            membership.team.slug,
        ),
    }

    return add_outgoing_email(
        responsible_team=membership.team,
        text_template="emails/new_membership_email.txt",
        html_template="emails/new_membership_email.html",
        to_recipients=[
            resp.email for resp in membership.team.responsible_members.all()
        ],
        formatdict=formatdict,
        subject="New membership request for {} at {}".format(
            membership.team.name,
            membership.team.camp.title,
        ),
    )
Ejemplo n.º 14
0
def add_sponsorticket_email(ticket):
    # put formatdict together
    formatdict = {
        "ticket": ticket,
    }

    subject = "{} {} Sponsor Ticket {}".format(
        ticket.sponsor.camp.title,
        ticket.sponsor.name,
        ticket.uuid,
    )

    filename = f"sponsor_ticket_{ticket.pk}.pdf"
    with open(os.path.join(settings.PDF_ARCHIVE_PATH, filename), "rb") as f:
        # add email to outgoing email queue
        return add_outgoing_email(
            responsible_team=Team.objects.get(
                camp=ticket.sponsor.camp,
                name="Sponsors",
            ),
            text_template="emails/sponsorticket_email.txt",
            html_template="emails/sponsorticket_email.html",
            to_recipients=ticket.sponsor.ticket_email,
            formatdict=formatdict,
            subject=subject,
            attachment=f.read(),
            attachment_filename=filename,
        )
Ejemplo n.º 15
0
def add_added_membership_email(membership):
    formatdict = {"team": membership.team.name, "camp": membership.team.camp.title}

    return add_outgoing_email(
        text_template="emails/add_membership_email.txt",
        html_template="emails/add_membership_email.html",
        to_recipients=membership.user.email,
        formatdict=formatdict,
        subject="Team update from {}".format(membership.team.camp.title),
    )
Ejemplo n.º 16
0
def add_added_membership_email(membership):
    formatdict = {
        'team': membership.team.name,
        'camp': membership.team.camp.title
    }

    return add_outgoing_email(text_template='emails/add_membership_email.txt',
                              html_template='emails/add_membership_email.html',
                              to_recipients=membership.user.email,
                              formatdict=formatdict,
                              subject='Team update from {}'.format(
                                  membership.team.camp.title))
Ejemplo n.º 17
0
def add_added_membership_email(membership):
    formatdict = {
        'team': membership.team.name,
        'camp': membership.team.camp.title
    }

    return add_outgoing_email(
        text_template='emails/add_membership_email.txt',
        html_template='emails/add_membership_email.html',
        to_recipients=membership.user.email,
        formatdict=formatdict,
        subject='Team update from {}'.format(membership.team.camp.title)
    )
Ejemplo n.º 18
0
def add_new_membership_email(membership):
    formatdict = {
        'team': membership.team.name,
        'camp': membership.team.camp.title
    }

    return add_outgoing_email(
        text_template='emails/new_membership_email.txt',
        html_template='emails/new_membership_email.html',
        to_recipients=[resp.email for resp in membership.team.responsible],
        formatdict=formatdict,
        subject='New membership request for {} at {}'.format(
            membership.team.name, membership.team.camp.title))
Ejemplo n.º 19
0
def add_new_membership_email(membership):
    formatdict = {"team": membership.team.name, "camp": membership.team.camp.title}

    return add_outgoing_email(
        text_template="emails/new_membership_email.txt",
        html_template="emails/new_membership_email.html",
        to_recipients=[
            resp.email for resp in membership.team.responsible_members.all()
        ],
        formatdict=formatdict,
        subject="New membership request for {} at {}".format(
            membership.team.name, membership.team.camp.title
        ),
    )
Ejemplo n.º 20
0
def add_event_scheduled_email(slot):
    formatdict = {"slot": slot}
    # add all speaker emails
    recipients = [speaker.email for speaker in slot.event.speakers.all()]
    # also add the submitting users email
    recipients.append(slot.event.proposal.user.email)

    try:
        content_team = Team.objects.get(camp=slot.camp, name="Content")
    except ObjectDoesNotExist as e:
        logger.info(f"There is no team with name Content: {e}")
        return False

    # loop over unique recipients and send an email to each
    for rcpt in set(recipients):
        add_outgoing_email(
            responsible_team=content_team,
            text_template="emails/event_scheduled.txt",
            html_template="emails/event_scheduled.html",
            to_recipients=rcpt,
            formatdict=formatdict,
            subject=f"Your {slot.camp.title} event '{slot.event.title}' has been scheduled!",
            hold=True,
        )
Ejemplo n.º 21
0
def add_creditnote_email(creditnote):
    # put formatdict together
    formatdict = {"creditnote": creditnote}

    subject = "BornHack creditnote %s" % creditnote.pk

    # add email to outgoing email queue
    return add_outgoing_email(
        text_template="emails/creditnote_email.txt",
        html_template="emails/creditnote_email.html",
        to_recipients=creditnote.user.email,
        formatdict=formatdict,
        subject=subject,
        attachment=creditnote.pdf.read(),
        attachment_filename=creditnote.filename,
    )
Ejemplo n.º 22
0
def add_eventproposal_updated_email(eventproposal):
    formatdict = {"proposal": eventproposal}

    try:
        content_team = Team.objects.get(camp=eventproposal.camp, name="Content")
    except ObjectDoesNotExist as e:
        logger.info("There is no team with name Content: {}".format(e))
        return False

    return add_outgoing_email(
        text_template="emails/update_eventproposal.txt",
        html_template="emails/update_eventproposal.html",
        to_recipients=content_team.mailing_list,
        formatdict=formatdict,
        subject="Event proposal '%s' was just updated" % eventproposal.title,
    )
Ejemplo n.º 23
0
def add_new_speakerproposal_email(speakerproposal):
    formatdict = {"proposal": speakerproposal}

    try:
        content_team = Team.objects.get(camp=speakerproposal.camp, name="Content")
    except ObjectDoesNotExist as e:
        logger.info("There is no team with name Content: {}".format(e))
        return False

    return add_outgoing_email(
        text_template="emails/new_speakerproposal.txt",
        html_template="emails/new_speakerproposal.html",
        to_recipients=content_team.mailing_list,
        formatdict=formatdict,
        subject="New speaker proposal '%s' was just submitted" % speakerproposal.name,
    )
Ejemplo n.º 24
0
def add_new_membership_email(membership):
    formatdict = {
        'team': membership.team.name,
        'camp': membership.team.camp.title
    }

    return add_outgoing_email(
        text_template='emails/new_membership_email.txt',
        html_template='emails/new_membership_email.html',
        to_recipients=[resp.email for resp in membership.team.responsible],
        formatdict=formatdict,
        subject='New membership request for {} at {}'.format(
            membership.team.name,
            membership.team.camp.title
        )
    )
Ejemplo n.º 25
0
def add_removed_membership_email(membership):
    formatdict = {"team": membership.team.name, "camp": membership.team.camp.title}

    if membership.approved:
        text_template = ("emails/remove_membership_email.txt",)
        html_template = "emails/remove_membership_email.html"
    else:
        text_template = ("emails/unapproved_membership_email.txt",)
        html_template = "emails/unapproved_membership_email.html"

    return add_outgoing_email(
        text_template=text_template,
        html_template=html_template,
        to_recipients=membership.user.email,
        formatdict=formatdict,
        subject="Team update from {}".format(membership.team.camp.title),
    )
Ejemplo n.º 26
0
def add_village_approve_email(village):
    formatdict = {"village": village}

    try:
        orga_team = Team.objects.get(camp=village.camp, name="Orga")
    except ObjectDoesNotExist as e:
        logger.info(f"There is no team with name Orga: {e}")
        return False

    return add_outgoing_email(
        responsible_team=orga_team,
        text_template="emails/village_approve.txt",
        html_template="emails/village_approve.html",
        to_recipients="*****@*****.**",
        formatdict=formatdict,
        subject="Village created or updated, approval needed",
        hold=False,
    )
Ejemplo n.º 27
0
def add_speaker_proposal_rejected_email(speaker_proposal):
    formatdict = {"proposal": speaker_proposal}

    try:
        content_team = Team.objects.get(camp=speaker_proposal.camp, name="Content")
    except ObjectDoesNotExist as e:
        logger.info(f"There is no team with name Content: {e}")
        return False

    return add_outgoing_email(
        responsible_team=content_team,
        text_template="emails/speaker_proposal_rejected.txt",
        html_template="emails/speaker_proposal_rejected.html",
        to_recipients=speaker_proposal.user.email,
        formatdict=formatdict,
        subject=f"Your {speaker_proposal.camp.title} speaker proposal '{speaker_proposal.name}' was rejected",
        hold=True,
    )
Ejemplo n.º 28
0
def add_invoice_email(invoice):
    # put formatdict together
    formatdict = {
        'ordernumber': invoice.order.pk,
        'invoicenumber': invoice.pk,
        'filename': invoice.filename,
    }

    subject = 'BornHack invoice %s' % invoice.pk

    # add email to outgoing email queue
    return add_outgoing_email(text_template='emails/invoice_email.txt',
                              html_template='emails/invoice_email.html',
                              to_recipients=invoice.order.user.email,
                              formatdict=formatdict,
                              subject=subject,
                              attachment=invoice.pdf.read(),
                              attachment_filename=invoice.filename)
Ejemplo n.º 29
0
def add_speaker_proposal_updated_email(speaker_proposal):
    formatdict = {"proposal": speaker_proposal}

    try:
        content_team = Team.objects.get(camp=speaker_proposal.camp, name="Content")
    except ObjectDoesNotExist as e:
        logger.info(f"There is no team with name Content: {e}")
        return False

    return add_outgoing_email(
        responsible_team=content_team,
        text_template="emails/update_speaker_proposal.txt",
        html_template="emails/update_speaker_proposal.html",
        to_recipients=content_team.mailing_list,
        formatdict=formatdict,
        subject="Speaker proposal '%s' was just updated" % speaker_proposal.name,
        hold=False,
    )
Ejemplo n.º 30
0
def add_new_event_proposal_email(event_proposal):
    formatdict = {"proposal": event_proposal}

    try:
        content_team = Team.objects.get(camp=event_proposal.camp, name="Content")
    except ObjectDoesNotExist as e:
        logger.info(f"There is no team with name Content: {e}")
        return False

    return add_outgoing_email(
        responsible_team=content_team,
        text_template="emails/new_event_proposal.txt",
        html_template="emails/new_event_proposal.html",
        to_recipients=content_team.mailing_list,
        formatdict=formatdict,
        subject="New event proposal '%s' was just submitted" % event_proposal.title,
        hold=False,
    )
Ejemplo n.º 31
0
def add_creditnote_email(creditnote):
    # put formatdict together
    formatdict = {
        'creditnote': creditnote,
    }

    subject = 'BornHack creditnote %s' % creditnote.pk

    # add email to outgoing email queue
    return add_outgoing_email(
        text_template='emails/creditnote_email.txt',
        html_template='emails/creditnote_email.html',
        to_recipients=creditnote.user.email,
        formatdict=formatdict,
        subject=subject,
        attachment=creditnote.pdf.read(),
        attachment_filename=creditnote.filename
    )
Ejemplo n.º 32
0
def add_removed_membership_email(membership):
    formatdict = {
        'team': membership.team.name,
        'camp': membership.team.camp.title
    }

    if membership.approved:
        text_template = 'emails/remove_membership_email.txt',
        html_template = 'emails/remove_membership_email.html'
    else:
        text_template = 'emails/unapproved_membership_email.txt',
        html_template = 'emails/unapproved_membership_email.html'

    return add_outgoing_email(text_template=text_template,
                              html_template=html_template,
                              to_recipients=membership.user.email,
                              formatdict=formatdict,
                              subject='Team update from {}'.format(
                                  membership.team.camp.title))
Ejemplo n.º 33
0
def add_invoice_email(invoice):
    # put formatdict together
    formatdict = {
        "ordernumber": invoice.order.pk,
        "invoicenumber": invoice.pk,
        "filename": invoice.filename,
    }

    subject = "BornHack invoice %s" % invoice.pk

    # add email to outgoing email queue
    return add_outgoing_email(
        text_template="emails/invoice_email.txt",
        html_template="emails/invoice_email.html",
        to_recipients=invoice.order.user.email,
        formatdict=formatdict,
        subject=subject,
        attachment=invoice.pdf.read(),
        attachment_filename=invoice.filename,
    )
Ejemplo n.º 34
0
def add_removed_membership_email(membership):
    formatdict = {
        'team': membership.team.name,
        'camp': membership.team.camp.title
    }

    if membership.approved:
        text_template = 'emails/remove_membership_email.txt',
        html_template = 'emails/remove_membership_email.html'
    else:
        text_template = 'emails/unapproved_membership_email.txt',
        html_template = 'emails/unapproved_membership_email.html'

    return add_outgoing_email(
        text_template=text_template,
        html_template=html_template,
        to_recipients=membership.user.email,
        formatdict=formatdict,
        subject='Team update from {}'.format(membership.team.camp.title)
    )
Ejemplo n.º 35
0
def add_invoice_email(invoice):
    # put formatdict together
    formatdict = {
        'ordernumber': invoice.order.pk,
        'invoicenumber': invoice.pk,
        'filename': invoice.filename,
    }

    subject = 'BornHack invoice %s' % invoice.pk

    # add email to outgoing email queue
    return add_outgoing_email(
        text_template='emails/invoice_email.txt',
        html_template='emails/invoice_email.html',
        to_recipients=invoice.order.user.email,
        formatdict=formatdict,
        subject=subject,
        attachment=invoice.pdf.read(),
        attachment_filename=invoice.filename
    )
Ejemplo n.º 36
0
def add_eventproposal_updated_email(eventproposal):
    formatdict = {
        'proposal': eventproposal
    }

    try:
        content_team = Team.objects.get(
            camp=eventproposal.camp, name='Content'
        )

        return add_outgoing_email(
            text_template='emails/update_eventproposal.txt',
            html_template='emails/update_eventproposal.html',
            to_recipients=content_team.mailing_list,
            formatdict=formatdict,
            subject='New event proposal for {}'.format(
                eventproposal.camp.title
            )
        )
    except ObjectDoesNotExist as e:
        logger.info('There is no team with name Content: {}'.format(e))
        return False
Ejemplo n.º 37
0
def add_test_email(recipient):
    return add_outgoing_email(
        text_template='emails/testmail.txt',
        to_recipients=recipient,
        subject='testmail from bornhack website'
    )