From bd53f64208ae1d63a96d7d5da9df9049a17d5e95 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Mon, 22 Jun 2020 17:25:08 +0200 Subject: [PATCH] add responsible_team to most emails, while here run pre-commit run --all-files --- src/bar/models.py | 1 - src/bar/views.py | 3 +- src/bornhack/routing.py | 1 - src/bornhack/schema.py | 3 +- src/camps/utils.py | 3 +- src/economy/email.py | 26 +++++--- src/economy/views.py | 13 ++-- src/events/models.py | 1 - src/feedback/models.py | 1 - src/feedback/views.py | 3 +- src/info/models.py | 1 - src/info/views.py | 3 +- src/ircbot/irc3module.py | 3 +- src/ircbot/models.py | 1 - src/people/views.py | 3 +- src/profiles/models.py | 1 - src/program/consumers.py | 3 +- src/program/email.py | 49 +++++++++++++++ .../commands/notification_worker.py | 3 +- .../migrations/0023_auto_20170218_1243.py | 3 +- .../migrations/0030_auto_20170312_1230.py | 3 +- .../migrations/0033_auto_20170312_1857.py | 3 +- .../migrations/0034_auto_20170314_2012.py | 3 +- .../migrations/0036_auto_20170316_0004.py | 3 +- src/rideshare/models.py | 1 - src/rideshare/views.py | 6 +- src/shop/admin.py | 1 - src/shop/coinify.py | 1 - src/shop/email.py | 10 +-- src/shop/factories.py | 1 - src/shop/forms.py | 1 - src/shop/invoiceworker.py | 1 - src/shop/tests.py | 1 - src/shop/views.py | 1 - src/sponsors/email.py | 3 +- .../commands/email_sponsor_tickets.py | 3 +- .../commands/generate_sponsor_tickets.py | 3 +- src/sponsors/migrations/0001_initial.py | 3 +- src/sponsors/models.py | 1 - src/sponsors/views.py | 3 +- src/teams/admin.py | 3 +- src/teams/email.py | 3 + src/teams/templatetags/teams_tags.py | 1 - src/teams/urls.py | 1 - src/teams/views/guide.py | 3 +- src/teams/views/info.py | 5 +- src/teams/views/members.py | 3 +- src/teams/views/mixins.py | 1 - src/teams/views/shifts.py | 3 +- src/teams/views/tasks.py | 3 +- src/tickets/admin.py | 1 - .../migrations/0007_save_token_to_db.py | 1 - .../migrations/0011_save_badge_token_to_db.py | 1 - src/tickets/models.py | 1 - src/tickets/signals.py | 1 - src/tickets/tests.py | 1 - src/tokens/models.py | 1 - src/tokens/templatetags/token_tags.py | 1 - src/tokens/views.py | 1 - src/utils/admin.py | 2 +- src/utils/email.py | 2 + src/villages/views.py | 5 +- src/wishlist/apps.py | 2 +- src/wishlist/migrations/0001_initial.py | 63 ++++++++++++++----- src/wishlist/urls.py | 2 +- 65 files changed, 167 insertions(+), 121 deletions(-) diff --git a/src/bar/models.py b/src/bar/models.py index 0694ed4f..30d315cf 100644 --- a/src/bar/models.py +++ b/src/bar/models.py @@ -1,5 +1,4 @@ from django.db import models - from utils.models import CampRelatedModel diff --git a/src/bar/views.py b/src/bar/views.py index 6b4ebc63..ffb1eab5 100644 --- a/src/bar/views.py +++ b/src/bar/views.py @@ -1,6 +1,5 @@ -from django.views.generic import ListView - from camps.mixins import CampViewMixin +from django.views.generic import ListView from .models import ProductCategory diff --git a/src/bornhack/routing.py b/src/bornhack/routing.py index 672f3a1f..ea18915a 100644 --- a/src/bornhack/routing.py +++ b/src/bornhack/routing.py @@ -1,7 +1,6 @@ from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from django.conf.urls import url - from program.consumers import ScheduleConsumer application = ProtocolTypeRouter( diff --git a/src/bornhack/schema.py b/src/bornhack/schema.py index 0eba4bfe..1f84ac73 100644 --- a/src/bornhack/schema.py +++ b/src/bornhack/schema.py @@ -1,8 +1,7 @@ +from camps.models import Camp from graphene import ObjectType, Schema, relay from graphene_django import DjangoObjectType from graphene_django.filter import DjangoFilterConnectionField - -from camps.models import Camp from program.schema import ProgramQuery diff --git a/src/camps/utils.py b/src/camps/utils.py index 5958a16b..7446a2e3 100644 --- a/src/camps/utils.py +++ b/src/camps/utils.py @@ -1,8 +1,7 @@ +from camps.models import Camp from django.contrib import admin from django.utils import timezone -from camps.models import Camp - def get_current_camp(): try: diff --git a/src/economy/email.py b/src/economy/email.py index 0a79e057..a0150cac 100644 --- a/src/economy/email.py +++ b/src/economy/email.py @@ -1,7 +1,7 @@ import os from django.conf import settings - +from teams.models import Team from utils.email import add_outgoing_email # expense emails @@ -12,8 +12,10 @@ 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( - "emails/accountingsystem_expense_email.txt", + 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], @@ -26,8 +28,10 @@ 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( - "emails/expense_approved_email.txt", + responsible_team=economy_team, + text_template="emails/expense_approved_email.txt", formatdict=dict(expense=expense), subject="Your expense for %s has been approved." % expense.camp.title, to_recipients=[expense.user.emailaddress_set.get(primary=True).email], @@ -38,8 +42,10 @@ def send_expense_rejected_email(expense): """ Sends an expense-rejected email to the user who created the expense """ + economy_team = Team.objects.get(camp=expense.camp, name=settings.ECONOMY_TEAM_NAME) add_outgoing_email( - "emails/expense_rejected_email.txt", + responsible_team=economy_team, + text_template="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], @@ -54,8 +60,10 @@ 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( - "emails/accountingsystem_revenue_email.txt", + responsible_team=economy_team, + text_template="emails/accountingsystem_revenue_email.txt", formatdict=dict(revenue=revenue), subject="Revenue %s for %s" % (revenue.pk, revenue.camp.title), to_recipients=[settings.ACCOUNTINGSYSTEM_EMAIL], @@ -68,8 +76,10 @@ def send_revenue_approved_email(revenue): """ Sends a revenue-approved email to the user who created the revenue """ + economy_team = Team.objects.get(camp=revenue.camp, name=settings.ECONOMY_TEAM_NAME) add_outgoing_email( - "emails/revenue_approved_email.txt", + responsible_team=economy_team, + text_template="emails/revenue_approved_email.txt", formatdict=dict(revenue=revenue), subject="Your revenue for %s has been approved." % revenue.camp.title, to_recipients=[revenue.user.emailaddress_set.get(primary=True).email], @@ -80,8 +90,10 @@ 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( - "emails/revenue_rejected_email.txt", + responsible_team=economy_team, + text_template="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], diff --git a/src/economy/views.py b/src/economy/views.py index 7c9324bc..3595485a 100644 --- a/src/economy/views.py +++ b/src/economy/views.py @@ -1,6 +1,7 @@ import os import magic +from camps.mixins import CampViewMixin from django.conf import settings from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin @@ -15,8 +16,6 @@ from django.views.generic import ( TemplateView, UpdateView, ) - -from camps.mixins import CampViewMixin from teams.models import Team from utils.email import add_outgoing_email from utils.mixins import RaisePermissionRequiredMixin @@ -238,7 +237,10 @@ class ExpenseCreateView( # send an email to the economy team add_outgoing_email( - "emails/expense_awaiting_approval_email.txt", + responsible_team=Team.objects.get( + camp=self.camp, name=settings.ECONOMY_TEAM_NAME + ), + text_template="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), @@ -405,7 +407,10 @@ class RevenueCreateView( # send an email to the economy team add_outgoing_email( - "emails/revenue_awaiting_approval_email.txt", + responsible_team=Team.objects.get( + camp=self.camp, name=settings.ECONOMY_TEAM_NAME + ), + text_template="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), diff --git a/src/events/models.py b/src/events/models.py index 71cd17e6..56dc2e93 100644 --- a/src/events/models.py +++ b/src/events/models.py @@ -1,5 +1,4 @@ from django.db import models - from teams.models import Team from utils.models import CreatedUpdatedModel diff --git a/src/feedback/models.py b/src/feedback/models.py index 262f5c45..df311700 100644 --- a/src/feedback/models.py +++ b/src/feedback/models.py @@ -1,5 +1,4 @@ from django.db import models - from utils.models import CampRelatedModel, UUIDModel diff --git a/src/feedback/views.py b/src/feedback/views.py index c78769ee..0c338254 100644 --- a/src/feedback/views.py +++ b/src/feedback/views.py @@ -1,10 +1,9 @@ +from camps.mixins import CampViewMixin from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponseRedirect from django.urls import reverse from django.views.generic import CreateView - -from camps.mixins import CampViewMixin from tokens.models import Token from .models import Feedback diff --git a/src/info/models.py b/src/info/models.py index e7c4cc29..e7930c3b 100644 --- a/src/info/models.py +++ b/src/info/models.py @@ -1,7 +1,6 @@ import reversion from django.core.exceptions import ValidationError from django.db import models - from utils.models import CampRelatedModel diff --git a/src/info/views.py b/src/info/views.py index 35651573..cf355be8 100644 --- a/src/info/views.py +++ b/src/info/views.py @@ -1,6 +1,5 @@ -from django.views.generic import ListView - from camps.mixins import CampViewMixin +from django.views.generic import ListView from .models import InfoCategory diff --git a/src/ircbot/irc3module.py b/src/ircbot/irc3module.py index 88a47453..d8a593dd 100644 --- a/src/ircbot/irc3module.py +++ b/src/ircbot/irc3module.py @@ -1,13 +1,12 @@ +import asyncio import logging import re import time -import asyncio import irc3 from asgiref.sync import sync_to_async from django.conf import settings from django.utils import timezone - from ircbot.models import OutgoingIrcMessage from teams.models import Team, TeamMember from teams.utils import get_team_from_irc_channel diff --git a/src/ircbot/models.py b/src/ircbot/models.py index 8f643d04..d9d02429 100644 --- a/src/ircbot/models.py +++ b/src/ircbot/models.py @@ -1,7 +1,6 @@ from django.core.exceptions import ValidationError from django.db import models from django.utils import timezone - from utils.models import CreatedUpdatedModel diff --git a/src/people/views.py b/src/people/views.py index 00330ac9..2e4e9e55 100644 --- a/src/people/views.py +++ b/src/people/views.py @@ -1,6 +1,5 @@ -from django.views.generic import ListView - from camps.models import Camp +from django.views.generic import ListView class PeopleView(ListView): diff --git a/src/profiles/models.py b/src/profiles/models.py index b47c5b6a..5d3c81ec 100644 --- a/src/profiles/models.py +++ b/src/profiles/models.py @@ -1,7 +1,6 @@ from django.contrib.auth.models import User from django.db import models from django.utils.translation import ugettext_lazy as _ - from utils.models import CreatedUpdatedModel, UUIDModel diff --git a/src/program/consumers.py b/src/program/consumers.py index e41648d1..14cb59b5 100644 --- a/src/program/consumers.py +++ b/src/program/consumers.py @@ -1,6 +1,5 @@ -from channels.generic.websocket import JsonWebsocketConsumer - from camps.models import Camp +from channels.generic.websocket import JsonWebsocketConsumer from .models import ( Event, diff --git a/src/program/email.py b/src/program/email.py index a8134ad2..93b76ac9 100644 --- a/src/program/email.py +++ b/src/program/email.py @@ -17,11 +17,13 @@ def add_new_speaker_proposal_email(speaker_proposal): return False return add_outgoing_email( + responsible_team=content_team, text_template="emails/new_speaker_proposal.txt", html_template="emails/new_speaker_proposal.html", to_recipients=content_team.mailing_list, formatdict=formatdict, subject="New speaker proposal '%s' was just submitted" % speaker_proposal.name, + hold=True, ) @@ -35,11 +37,13 @@ def add_new_event_proposal_email(event_proposal): 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=True, ) @@ -53,11 +57,13 @@ def add_speaker_proposal_updated_email(speaker_proposal): 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=True, ) @@ -71,59 +77,93 @@ def add_event_proposal_updated_email(event_proposal): return False return add_outgoing_email( + responsible_team=content_team, text_template="emails/update_event_proposal.txt", html_template="emails/update_event_proposal.html", to_recipients=content_team.mailing_list, formatdict=formatdict, subject="Event proposal '%s' was just updated" % event_proposal.title, + hold=True, ) 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("There is no team with name Content: {}".format(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, ) def add_speaker_proposal_accepted_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("There is no team with name Content: {}".format(e)) + return False + return add_outgoing_email( + responsible_team=content_team, text_template="emails/speaker_proposal_accepted.txt", html_template="emails/speaker_proposal_accepted.html", to_recipients=speaker_proposal.user.email, formatdict=formatdict, subject=f"Your {speaker_proposal.camp.title} speaker proposal '{speaker_proposal.name}' was accepted", + hold=True, ) def add_event_proposal_rejected_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("There is no team with name Content: {}".format(e)) + return False + return add_outgoing_email( + responsible_team=content_team, text_template="emails/event_proposal_rejected.txt", html_template="emails/event_proposal_rejected.html", to_recipients=event_proposal.user.email, formatdict=formatdict, subject=f"Your {event_proposal.camp.title} event proposal '{event_proposal.title}' was rejected", + hold=True, ) def add_event_proposal_accepted_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("There is no team with name Content: {}".format(e)) + return False + return add_outgoing_email( + responsible_team=content_team, text_template="emails/event_proposal_accepted.txt", html_template="emails/event_proposal_accepted.html", to_recipients=event_proposal.user.email, formatdict=formatdict, subject=f"Your {event_proposal.camp.title} event proposal '{event_proposal.title}' was accepted!", + hold=True, ) @@ -131,12 +171,21 @@ 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, ) diff --git a/src/program/management/commands/notification_worker.py b/src/program/management/commands/notification_worker.py index b5147a66..8008a434 100644 --- a/src/program/management/commands/notification_worker.py +++ b/src/program/management/commands/notification_worker.py @@ -2,11 +2,10 @@ import logging from datetime import timedelta from time import sleep +from camps.utils import get_current_camp from django.conf import settings from django.core.management.base import BaseCommand from django.utils import timezone - -from camps.utils import get_current_camp from ircbot.models import OutgoingIrcMessage from program.models import EventInstance diff --git a/src/program/migrations/0023_auto_20170218_1243.py b/src/program/migrations/0023_auto_20170218_1243.py index c64f8372..b3434e35 100644 --- a/src/program/migrations/0023_auto_20170218_1243.py +++ b/src/program/migrations/0023_auto_20170218_1243.py @@ -2,9 +2,8 @@ # Generated by Django 1.10.5 on 2017-02-18 11:43 from __future__ import unicode_literals -from django.db import migrations, models - import program.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/program/migrations/0030_auto_20170312_1230.py b/src/program/migrations/0030_auto_20170312_1230.py index cb5d75ba..302bd9ac 100644 --- a/src/program/migrations/0030_auto_20170312_1230.py +++ b/src/program/migrations/0030_auto_20170312_1230.py @@ -5,11 +5,10 @@ from __future__ import unicode_literals import uuid import django.db.models.deletion +import program.models from django.conf import settings from django.db import migrations, models -import program.models - class Migration(migrations.Migration): diff --git a/src/program/migrations/0033_auto_20170312_1857.py b/src/program/migrations/0033_auto_20170312_1857.py index a1a524cf..fae99b94 100644 --- a/src/program/migrations/0033_auto_20170312_1857.py +++ b/src/program/migrations/0033_auto_20170312_1857.py @@ -5,11 +5,10 @@ from __future__ import unicode_literals import uuid import django.db.models.deletion +import program.models from django.conf import settings from django.db import migrations, models -import program.models - class Migration(migrations.Migration): diff --git a/src/program/migrations/0034_auto_20170314_2012.py b/src/program/migrations/0034_auto_20170314_2012.py index a9316514..3f9cebbd 100644 --- a/src/program/migrations/0034_auto_20170314_2012.py +++ b/src/program/migrations/0034_auto_20170314_2012.py @@ -2,9 +2,8 @@ # Generated by Django 1.10.5 on 2017-03-14 19:12 from __future__ import unicode_literals -from django.db import migrations, models - import program.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/program/migrations/0036_auto_20170316_0004.py b/src/program/migrations/0036_auto_20170316_0004.py index fcb4e303..c49809e7 100644 --- a/src/program/migrations/0036_auto_20170316_0004.py +++ b/src/program/migrations/0036_auto_20170316_0004.py @@ -2,9 +2,8 @@ # Generated by Django 1.10.5 on 2017-03-15 23:04 from __future__ import unicode_literals -from django.db import migrations, models - import program.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/rideshare/models.py b/src/rideshare/models.py index 5d5d8984..25d23937 100644 --- a/src/rideshare/models.py +++ b/src/rideshare/models.py @@ -1,6 +1,5 @@ from django.db import models from django.urls import reverse - from utils.models import CampRelatedModel, UUIDModel diff --git a/src/rideshare/views.py b/src/rideshare/views.py index 96c27120..9875462d 100644 --- a/src/rideshare/views.py +++ b/src/rideshare/views.py @@ -1,3 +1,4 @@ +from camps.mixins import CampViewMixin from django import forms from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin @@ -10,8 +11,7 @@ from django.views.generic import ( ListView, UpdateView, ) - -from camps.mixins import CampViewMixin +from teams.models import Team from utils.email import add_outgoing_email from utils.mixins import UserIsObjectOwnerMixin @@ -44,7 +44,9 @@ class RideDetail(LoginRequiredMixin, CampViewMixin, DetailView): 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( diff --git a/src/shop/admin.py b/src/shop/admin.py index 03235ad3..7e08e25b 100644 --- a/src/shop/admin.py +++ b/src/shop/admin.py @@ -1,5 +1,4 @@ from django.contrib import admin - from tickets.admin import ShopTicketInline from .models import ( diff --git a/src/shop/coinify.py b/src/shop/coinify.py index 2b1a87bf..1c521b47 100644 --- a/src/shop/coinify.py +++ b/src/shop/coinify.py @@ -3,7 +3,6 @@ import logging import requests from django.conf import settings - from vendor.coinify.coinify_api import CoinifyAPI from .models import CoinifyAPICallback, CoinifyAPIInvoice, CoinifyAPIRequest diff --git a/src/shop/email.py b/src/shop/email.py index 60f3ef39..0a48a152 100644 --- a/src/shop/email.py +++ b/src/shop/email.py @@ -5,7 +5,7 @@ from utils.email import add_outgoing_email logger = logging.getLogger("bornhack.%s" % __name__) -def add_creditnote_email(creditnote): +def add_creditnote_email(creditnote, camp): # put formatdict together formatdict = {"creditnote": creditnote} @@ -43,11 +43,3 @@ def add_invoice_email(invoice): attachment=invoice.pdf.read(), attachment_filename=invoice.filename, ) - - -def add_test_email(recipient): - return add_outgoing_email( - text_template="emails/testmail.txt", - to_recipients=recipient, - subject="testmail from bornhack website", - ) diff --git a/src/shop/factories.py b/src/shop/factories.py index 6701d2ec..0b6d9d2c 100644 --- a/src/shop/factories.py +++ b/src/shop/factories.py @@ -2,7 +2,6 @@ import factory from django.utils import timezone from factory.django import DjangoModelFactory from psycopg2.extras import DateTimeTZRange - from utils.factories import UserFactory diff --git a/src/shop/forms.py b/src/shop/forms.py index 9df1ce2c..ee2be52c 100644 --- a/src/shop/forms.py +++ b/src/shop/forms.py @@ -1,6 +1,5 @@ from django import forms from django.forms import modelformset_factory - from shop.models import OrderProductRelation diff --git a/src/shop/invoiceworker.py b/src/shop/invoiceworker.py index eb40c8e3..712f63cf 100644 --- a/src/shop/invoiceworker.py +++ b/src/shop/invoiceworker.py @@ -3,7 +3,6 @@ import logging from django.conf import settings from django.core.files import File from django.db.models import Q - from shop.email import add_creditnote_email, add_invoice_email from shop.models import CreditNote, CustomOrder, Invoice, Order from utils.pdf import generate_pdf_letter diff --git a/src/shop/tests.py b/src/shop/tests.py index 87281e41..880e4923 100644 --- a/src/shop/tests.py +++ b/src/shop/tests.py @@ -2,7 +2,6 @@ from django.test import TestCase from django.urls import reverse from django.utils import timezone from psycopg2.extras import DateTimeTZRange - from shop.forms import OrderProductRelationForm from tickets.factories import TicketTypeFactory from tickets.models import ShopTicket diff --git a/src/shop/views.py b/src/shop/views.py index a7372db6..315e0032 100644 --- a/src/shop/views.py +++ b/src/shop/views.py @@ -19,7 +19,6 @@ from django.views.decorators.csrf import csrf_exempt from django.views.generic import DetailView, FormView, ListView, View from django.views.generic.base import RedirectView from django.views.generic.detail import SingleObjectMixin - from shop.models import ( CreditNote, EpayCallback, diff --git a/src/sponsors/email.py b/src/sponsors/email.py index da885ce3..0834fe10 100644 --- a/src/sponsors/email.py +++ b/src/sponsors/email.py @@ -2,7 +2,7 @@ import logging import os from django.conf import settings - +from teams.models import Team from utils.email import add_outgoing_email logger = logging.getLogger("bornhack.%s" % __name__) @@ -24,6 +24,7 @@ def add_sponsorticket_email(ticket): 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="Sponsor"), text_template="emails/sponsorticket_email.txt", html_template="emails/sponsorticket_email.html", to_recipients=ticket.sponsor.ticket_email, diff --git a/src/sponsors/management/commands/email_sponsor_tickets.py b/src/sponsors/management/commands/email_sponsor_tickets.py index 17689004..2d6407e7 100644 --- a/src/sponsors/management/commands/email_sponsor_tickets.py +++ b/src/sponsors/management/commands/email_sponsor_tickets.py @@ -1,10 +1,9 @@ # coding: utf-8 import logging +from camps.models import Camp from django.core.management.base import BaseCommand from django.utils import timezone - -from camps.models import Camp from sponsors.email import add_sponsorticket_email from sponsors.models import Sponsor diff --git a/src/sponsors/management/commands/generate_sponsor_tickets.py b/src/sponsors/management/commands/generate_sponsor_tickets.py index d2684728..49c0b615 100644 --- a/src/sponsors/management/commands/generate_sponsor_tickets.py +++ b/src/sponsors/management/commands/generate_sponsor_tickets.py @@ -1,8 +1,7 @@ # coding: utf-8 +from camps.models import Camp from django.core.management.base import BaseCommand from django.utils import timezone - -from camps.models import Camp from sponsors.models import Sponsor from tickets.models import SponsorTicket, TicketType diff --git a/src/sponsors/migrations/0001_initial.py b/src/sponsors/migrations/0001_initial.py index 31c64193..841d6624 100644 --- a/src/sponsors/migrations/0001_initial.py +++ b/src/sponsors/migrations/0001_initial.py @@ -2,9 +2,8 @@ # Generated by Django 1.11 on 2017-07-11 21:35 from __future__ import unicode_literals -from django.db import migrations, models - import sponsors.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/sponsors/models.py b/src/sponsors/models.py index 6b56ed36..91bd0534 100644 --- a/src/sponsors/models.py +++ b/src/sponsors/models.py @@ -1,5 +1,4 @@ from django.db import models - from utils.models import CampRelatedModel diff --git a/src/sponsors/views.py b/src/sponsors/views.py index 6b4f193b..26fd6cb7 100644 --- a/src/sponsors/views.py +++ b/src/sponsors/views.py @@ -1,6 +1,5 @@ -from django.views.generic import ListView - from camps.mixins import CampViewMixin +from django.views.generic import ListView from .models import Sponsor diff --git a/src/teams/admin.py b/src/teams/admin.py index 90278ec1..46d7d8eb 100644 --- a/src/teams/admin.py +++ b/src/teams/admin.py @@ -1,6 +1,5 @@ -from django.contrib import admin - from camps.utils import CampPropertyListFilter +from django.contrib import admin from .email import add_added_membership_email, add_removed_membership_email from .models import Team, TeamMember, TeamShift, TeamTask diff --git a/src/teams/email.py b/src/teams/email.py index 258888e6..281458c8 100644 --- a/src/teams/email.py +++ b/src/teams/email.py @@ -9,6 +9,7 @@ def add_added_membership_email(membership): formatdict = {"team": membership.team.name, "camp": membership.team.camp.title} return add_outgoing_email( + responsible_team=membership.team, text_template="emails/add_membership_email.txt", html_template="emails/add_membership_email.html", to_recipients=membership.user.email, @@ -28,6 +29,7 @@ def add_removed_membership_email(membership): html_template = "emails/unapproved_membership_email.html" return add_outgoing_email( + responsible_team=membership.team, text_template=text_template, html_template=html_template, to_recipients=membership.user.email, @@ -40,6 +42,7 @@ def add_new_membership_email(membership): formatdict = {"team": membership.team.name, "camp": membership.team.camp.title} return add_outgoing_email( + responsible_team=membership.team, text_template="emails/new_membership_email.txt", html_template="emails/new_membership_email.html", to_recipients=[ diff --git a/src/teams/templatetags/teams_tags.py b/src/teams/templatetags/teams_tags.py index 43537c2d..9698ab29 100644 --- a/src/teams/templatetags/teams_tags.py +++ b/src/teams/templatetags/teams_tags.py @@ -1,6 +1,5 @@ from django import template from django.utils.safestring import mark_safe - from teams.models import TeamMember register = template.Library() diff --git a/src/teams/urls.py b/src/teams/urls.py index 92ef4e03..fc346e8d 100644 --- a/src/teams/urls.py +++ b/src/teams/urls.py @@ -1,5 +1,4 @@ from django.urls import include, path - from teams.views.base import ( FixIrcAclView, TeamGeneralView, diff --git a/src/teams/views/guide.py b/src/teams/views/guide.py index 38f1f1ec..a92747de 100644 --- a/src/teams/views/guide.py +++ b/src/teams/views/guide.py @@ -1,8 +1,7 @@ +from camps.mixins import CampViewMixin from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin from django.views.generic import DetailView -from camps.mixins import CampViewMixin - from ..models import Team, TeamMember diff --git a/src/teams/views/info.py b/src/teams/views/info.py index a930f471..69e39ed9 100644 --- a/src/teams/views/info.py +++ b/src/teams/views/info.py @@ -1,10 +1,9 @@ +from camps.mixins import CampViewMixin from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponseRedirect from django.views.generic import CreateView, DeleteView, ListView, UpdateView -from reversion.views import RevisionMixin - -from camps.mixins import CampViewMixin from info.models import InfoCategory, InfoItem +from reversion.views import RevisionMixin from ..models import Team from .mixins import EnsureTeamResponsibleMixin, TeamViewMixin diff --git a/src/teams/views/members.py b/src/teams/views/members.py index f93b8eda..5e9b9833 100644 --- a/src/teams/views/members.py +++ b/src/teams/views/members.py @@ -1,11 +1,10 @@ import logging +from camps.mixins import CampViewMixin from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import redirect from django.views.generic import DetailView, UpdateView - -from camps.mixins import CampViewMixin from profiles.models import Profile from ..email import add_added_membership_email, add_removed_membership_email diff --git a/src/teams/views/mixins.py b/src/teams/views/mixins.py index 53a35f08..e4e2ac70 100644 --- a/src/teams/views/mixins.py +++ b/src/teams/views/mixins.py @@ -1,7 +1,6 @@ from django.contrib import messages from django.shortcuts import redirect from django.views.generic.detail import SingleObjectMixin - from teams.models import Team, TeamMember diff --git a/src/teams/views/shifts.py b/src/teams/views/shifts.py index eaa44fc8..e0d762c7 100644 --- a/src/teams/views/shifts.py +++ b/src/teams/views/shifts.py @@ -1,3 +1,4 @@ +from camps.mixins import CampViewMixin from django import forms from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin @@ -16,8 +17,6 @@ from django.views.generic import ( ) from psycopg2.extras import DateTimeTZRange -from camps.mixins import CampViewMixin - from ..models import Team, TeamMember, TeamShift diff --git a/src/teams/views/tasks.py b/src/teams/views/tasks.py index ffdc6f30..6c7a920c 100644 --- a/src/teams/views/tasks.py +++ b/src/teams/views/tasks.py @@ -1,11 +1,10 @@ +from camps.mixins import CampViewMixin from django import forms from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponseNotAllowed, HttpResponseRedirect from django.views.generic import CreateView, DetailView, UpdateView -from camps.mixins import CampViewMixin - from ..models import TaskComment, Team, TeamMember, TeamTask from .mixins import EnsureTeamResponsibleMixin, TeamViewMixin diff --git a/src/tickets/admin.py b/src/tickets/admin.py index a14c0e37..517070fd 100644 --- a/src/tickets/admin.py +++ b/src/tickets/admin.py @@ -1,5 +1,4 @@ from django.contrib import admin - from shop.models import OrderProductRelation from .models import DiscountTicket, ShopTicket, SponsorTicket, TicketType diff --git a/src/tickets/migrations/0007_save_token_to_db.py b/src/tickets/migrations/0007_save_token_to_db.py index cef68d1e..671f2666 100644 --- a/src/tickets/migrations/0007_save_token_to_db.py +++ b/src/tickets/migrations/0007_save_token_to_db.py @@ -1,7 +1,6 @@ # Generated by Django 2.2.2 on 2019-07-18 18:52 from django.conf import settings from django.db import migrations - from tickets.models import create_ticket_token diff --git a/src/tickets/migrations/0011_save_badge_token_to_db.py b/src/tickets/migrations/0011_save_badge_token_to_db.py index dbc0883d..6b3d5b6c 100644 --- a/src/tickets/migrations/0011_save_badge_token_to_db.py +++ b/src/tickets/migrations/0011_save_badge_token_to_db.py @@ -1,7 +1,6 @@ # Generated by Django 2.2.3 on 2019-07-24 18:37 from django.conf import settings from django.db import migrations - from tickets.models import create_ticket_token diff --git a/src/tickets/models.py b/src/tickets/models.py index 1c7661e0..fed0d205 100644 --- a/src/tickets/models.py +++ b/src/tickets/models.py @@ -8,7 +8,6 @@ from django.conf import settings from django.db import models from django.urls import reverse_lazy from django.utils.translation import ugettext_lazy as _ - from shop.models import OrderProductRelation from utils.models import CampRelatedModel, UUIDModel from utils.pdf import generate_pdf_letter diff --git a/src/tickets/signals.py b/src/tickets/signals.py index 40ba19db..70574962 100644 --- a/src/tickets/signals.py +++ b/src/tickets/signals.py @@ -1,7 +1,6 @@ from datetime import datetime from django.db.models import Count - from events.handler import handle_team_event diff --git a/src/tickets/tests.py b/src/tickets/tests.py index 58f5be64..4a91aecb 100644 --- a/src/tickets/tests.py +++ b/src/tickets/tests.py @@ -1,5 +1,4 @@ from django.test import TestCase - from shop.factories import OrderProductRelationFactory from .factories import TicketTypeFactory diff --git a/src/tokens/models.py b/src/tokens/models.py index f21985f5..00dc77e6 100644 --- a/src/tokens/models.py +++ b/src/tokens/models.py @@ -1,5 +1,4 @@ from django.db import models - from utils.models import CampRelatedModel diff --git a/src/tokens/templatetags/token_tags.py b/src/tokens/templatetags/token_tags.py index 3b605009..ddaa1b00 100644 --- a/src/tokens/templatetags/token_tags.py +++ b/src/tokens/templatetags/token_tags.py @@ -1,5 +1,4 @@ from django import template - from tokens.models import TokenFind register = template.Library() diff --git a/src/tokens/views.py b/src/tokens/views.py index 0df86037..962704d6 100644 --- a/src/tokens/views.py +++ b/src/tokens/views.py @@ -1,7 +1,6 @@ from django.conf import settings from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import DetailView, ListView - from utils.models import CampReadOnlyModeError from .models import Token, TokenFind diff --git a/src/utils/admin.py b/src/utils/admin.py index f3a0813d..2e03ff55 100644 --- a/src/utils/admin.py +++ b/src/utils/admin.py @@ -6,4 +6,4 @@ from .models import OutgoingEmail @admin.register(OutgoingEmail) class OutgoingEmailAdmin(admin.ModelAdmin): model = OutgoingEmail - list_display = ["subject", "to_recipients"] + list_display = ["subject", "to_recipients", "processed", "hold", "responsible_team"] diff --git a/src/utils/email.py b/src/utils/email.py index 15a1e1f8..67a3ee82 100644 --- a/src/utils/email.py +++ b/src/utils/email.py @@ -74,6 +74,7 @@ def add_outgoing_email( sender="BornHack ", attachment=None, attachment_filename="", + responsible_team=None, hold=False, ): """ adds an email to the outgoing queue @@ -106,6 +107,7 @@ def add_outgoing_email( cc_recipients=cc_recipients, bcc_recipients=bcc_recipients, hold=hold, + responsible_team=responsible_team, ) if attachment: diff --git a/src/villages/views.py b/src/villages/views.py index 2fca4803..0b7e6854 100644 --- a/src/villages/views.py +++ b/src/villages/views.py @@ -1,3 +1,5 @@ +from camps.mixins import CampViewMixin +from camps.models import Camp from django.contrib.auth.mixins import LoginRequiredMixin from django.http import Http404, HttpResponseRedirect from django.urls import reverse_lazy @@ -10,9 +12,6 @@ from django.views.generic import ( ) from django.views.generic.detail import SingleObjectMixin -from camps.mixins import CampViewMixin -from camps.models import Camp - from .mixins import EnsureWritableCampMixin from .models import Village diff --git a/src/wishlist/apps.py b/src/wishlist/apps.py index 6c0d16f1..f0d7e6bf 100644 --- a/src/wishlist/apps.py +++ b/src/wishlist/apps.py @@ -2,4 +2,4 @@ from django.apps import AppConfig class WishlistConfig(AppConfig): - name = 'wishlist' + name = "wishlist" diff --git a/src/wishlist/migrations/0001_initial.py b/src/wishlist/migrations/0001_initial.py index 227c421e..43a71607 100644 --- a/src/wishlist/migrations/0001_initial.py +++ b/src/wishlist/migrations/0001_initial.py @@ -1,7 +1,7 @@ # Generated by Django 3.0.3 on 2020-02-09 18:24 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): @@ -9,25 +9,58 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('teams', '0051_auto_20190312_1129'), + ("teams", "0051_auto_20190312_1129"), ] operations = [ migrations.CreateModel( - name='Wish', + name="Wish", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created', models.DateTimeField(auto_now_add=True)), - ('updated', models.DateTimeField(auto_now=True)), - ('name', models.CharField(help_text='Short description of the wish', max_length=100)), - ('slug', models.SlugField(help_text='The url slug for this wish')), - ('description', models.TextField(help_text='Description of the needed item. Markdown is supported!')), - ('count', models.IntegerField(default=1, help_text='How many do we need?')), - ('fulfilled', models.BooleanField(default=False, help_text='A Wish is marked as fulfilled when we no longer need the thing.')), - ('team', models.ForeignKey(help_text='The team that needs this thing. When in doubt pick Orga :)', on_delete=django.db.models.deletion.PROTECT, related_name='wishes', to='teams.Team')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("created", models.DateTimeField(auto_now_add=True)), + ("updated", models.DateTimeField(auto_now=True)), + ( + "name", + models.CharField( + help_text="Short description of the wish", max_length=100 + ), + ), + ("slug", models.SlugField(help_text="The url slug for this wish")), + ( + "description", + models.TextField( + help_text="Description of the needed item. Markdown is supported!" + ), + ), + ( + "count", + models.IntegerField(default=1, help_text="How many do we need?"), + ), + ( + "fulfilled", + models.BooleanField( + default=False, + help_text="A Wish is marked as fulfilled when we no longer need the thing.", + ), + ), + ( + "team", + models.ForeignKey( + help_text="The team that needs this thing. When in doubt pick Orga :)", + on_delete=django.db.models.deletion.PROTECT, + related_name="wishes", + to="teams.Team", + ), + ), ], - options={ - 'abstract': False, - }, + options={"abstract": False,}, ), ] diff --git a/src/wishlist/urls.py b/src/wishlist/urls.py index db3db135..5662b2a2 100644 --- a/src/wishlist/urls.py +++ b/src/wishlist/urls.py @@ -1,6 +1,6 @@ from django.urls import path -from .views import WishListView, WishDetailView +from .views import WishDetailView, WishListView app_name = "wishlist" urlpatterns = [