Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discount report #38

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ COPY static ./static
COPY manage.py ./


FROM base as dev
FROM base AS dev

# Set environment variables for development
ENV DJANGO_ENV="dev"
Expand All @@ -39,7 +39,7 @@ COPY requirements.dev.txt ./
RUN pip install --no-cache-dir -r requirements.dev.txt


FROM base as prod
FROM base AS prod

# Set environment variables for production
ENV DJANGO_ENV="prod"
Expand All @@ -49,7 +49,7 @@ ENV NODE_ENV="production"
# Install node dependencies
RUN npm install

# Copy code
# Copy code
COPY server ./server
COPY client ./client
COPY scripts ./scripts
Expand Down
4 changes: 4 additions & 0 deletions app/client/components/admin/AdminNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ const navbarSections: AdminNavBarSection[] = [
linkTitle: "Preferences of paid users (CSV)",
href: reverse("list_csv_preferences_paid"),
},
{
linkTitle: "List of users that got a discount (CSV)",
ref-humbold marked this conversation as resolved.
Show resolved Hide resolved
href: reverse("list_csv_preferences_with_discounts"),
},
{
linkTitle: "User --> Room (CSV)",
href: reverse("list_csv_room_by_user"),
Expand Down
12 changes: 9 additions & 3 deletions app/server/conferences/management/commands/create_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ def create_random_user_with_preferences(zosia, id):
is_student = id % 2 == 1
student_number = random.randint(100000, 999999) if is_student else ''

discount_round = 0
if is_student:
# Not all student get a discounts
discount_round = random.randint(0, 3)

UserPreferences.objects.create(
user=u,
zosia=zosia,
Expand All @@ -208,7 +213,8 @@ def create_random_user_with_preferences(zosia, id):
bonus_minutes=bonus,
is_student=is_student,
student_number=student_number,
terms_accepted=True
terms_accepted=True,
discount_round=discount_round,
)
return u

Expand Down Expand Up @@ -237,7 +243,7 @@ def create_sponsor(number):
[SponsorInternals.TYPE_BRONZE,
SponsorInternals.TYPE_SILVER,
SponsorInternals.TYPE_GOLD])

logo_path = 'https://s3.amazonaws.com/freebiesupply/large/2x/google-logo-transparent.png' if random.random() < 0.5 else None

data = {
Expand Down Expand Up @@ -280,7 +286,7 @@ def handle(self, *args, **kwargs):
create_contact_to_organizer(zosia, sample_organizer_user)
self.stdout.write('Contact to sample organizer created')

user_num = 7
user_num = 15
for i in range(1, user_num + 1):
user_with_prefs = create_random_user_with_preferences(zosia, i)
self.stdout.write(f"Created random user #{i}")
Expand Down
2 changes: 2 additions & 0 deletions app/server/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
name='list_csv_preferences_all'),
path('preferences/list/paid', views.list_csv_preferences_paid,
name='list_csv_preferences_paid'),
path('preferences/list/discounts', views.list_csv_preferences_with_discounts,
name='list_csv_preferences_with_discounts'),
path('lectures/list/all', views.list_csv_lectures,
name='list_csv_lectures'),
path('register/', views.register, name='user_zosia_register'),
Expand Down
17 changes: 14 additions & 3 deletions app/server/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def profile(request):
registration_open and not current_zosia.is_registration_over or \
current_prefs and (current_zosia.is_registration_over or
current_zosia.registration_suspended)

price = None
transfer_title = None
shirt_type = None
Expand Down Expand Up @@ -202,7 +202,7 @@ def mail_to_all(request):
form.send_mail()
text = form.cleaned_data.get('text')
subject = form.cleaned_data.get('subject')
receivers = map(lambda user: user.email, form.receivers())
receivers = map(lambda user: user.email, form.receivers())
return AdminUsersSendEmailComplete(text=text, subject=subject, receivers=receivers).render(request)

return AdminUsersSendEmail(form=form).render(request)
Expand Down Expand Up @@ -299,7 +299,7 @@ def user_preferences_edit(request, pk=None):
kwargs['instance'] = user_preferences

form = UserPreferencesAdminForm(request.POST or None, **kwargs)

if request.method == 'POST':
if form.is_valid():
form.save()
Expand Down Expand Up @@ -445,6 +445,17 @@ def list_csv_preferences_paid(request):
return csv_response(header, data_list, filename="list_csv_preferences_paid")


@staff_member_required
@require_http_methods(['GET'])
def list_csv_preferences_with_discounts(request):
prefs = (UserPreferences.objects.select_related('user')
.exclude(discount_round=0).order_by("user__last_name", "user__first_name"))
header = ("User", "Payment accepted", "Student", "Discount Round")
data_list = [(p.user, p.payment_accepted, p.is_student, p.discount_round) for p in prefs]

return csv_response(header, data_list, filename="list_csv_preferences_with_discounts")


@staff_member_required
@require_http_methods(['GET'])
def list_csv_lectures(request):
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
db:
image: postgres
Expand Down