-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ilevkivskyi-colour
- Loading branch information
Showing
48 changed files
with
5,852 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ responses==0.10.5 | |
django-debug-toolbar==1.9.1 | ||
coverage | ||
ddt | ||
model-bakery==1.2.0 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,8 @@ | |
'haystack', | ||
'honeypot', | ||
'waffle', | ||
'ordered_model', | ||
'widget_tweaks', | ||
|
||
'users', | ||
'boxes', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,121 @@ | ||
from ordered_model.admin import OrderedModelAdmin | ||
|
||
from django.urls import path, reverse | ||
from django.contrib import admin | ||
from django.utils.html import mark_safe | ||
from django.shortcuts import get_object_or_404, render | ||
|
||
from .models import Sponsor | ||
from .models import ( | ||
SponsorshipPackage, | ||
SponsorshipProgram, | ||
SponsorshipBenefit, | ||
Sponsor, | ||
Sponsorship, | ||
SponsorContact, | ||
) | ||
from cms.admin import ContentManageableModelAdmin | ||
|
||
|
||
@admin.register(SponsorshipProgram) | ||
class SponsorshipProgramAdmin(OrderedModelAdmin): | ||
ordering = ("order",) | ||
list_display = [ | ||
"name", | ||
"move_up_down_links", | ||
] | ||
|
||
|
||
@admin.register(SponsorshipBenefit) | ||
class SponsorshipBenefitAdmin(OrderedModelAdmin): | ||
ordering = ("program", "order") | ||
list_display = [ | ||
"program", | ||
"short_name", | ||
"package_only", | ||
"internal_value", | ||
"move_up_down_links", | ||
] | ||
list_filter = ["program"] | ||
search_fields = ["name"] | ||
|
||
fieldsets = [ | ||
( | ||
"Public", | ||
{ | ||
"fields": ( | ||
"name", | ||
"description", | ||
"program", | ||
"packages", | ||
"package_only", | ||
"new", | ||
), | ||
}, | ||
), | ||
( | ||
"Internal", | ||
{ | ||
"fields": ( | ||
"internal_description", | ||
"internal_value", | ||
"capacity", | ||
"soft_capacity", | ||
"conflicts", | ||
) | ||
}, | ||
), | ||
] | ||
|
||
|
||
@admin.register(SponsorshipPackage) | ||
class SponsorshipPackageAdmin(OrderedModelAdmin): | ||
ordering = ("order",) | ||
list_display = ["name", "move_up_down_links"] | ||
|
||
|
||
class SponsorContactInline(admin.TabularInline): | ||
model = SponsorContact | ||
extra = 0 | ||
|
||
|
||
@admin.register(Sponsor) | ||
class SponsorAdmin(ContentManageableModelAdmin): | ||
raw_id_fields = ['company'] | ||
inlines = [SponsorContactInline] | ||
|
||
|
||
@admin.register(Sponsorship) | ||
class SponsorshipAdmin(admin.ModelAdmin): | ||
list_display = [ | ||
"sponsor", | ||
"applied_on", | ||
"approved_on", | ||
"start_date", | ||
"end_date", | ||
"display_sponsorship_link", | ||
] | ||
|
||
def get_queryset(self, *args, **kwargs): | ||
qs = super().get_queryset(*args, **kwargs) | ||
return qs.select_related("sponsor") | ||
|
||
def display_sponsorship_link(self, obj): | ||
url = reverse("admin:sponsors_sponsorship_preview", args=[obj.pk]) | ||
return mark_safe(f'<a href="{url}" target="_blank">Click to preview</a>') | ||
|
||
display_sponsorship_link.short_description = "Preview sponsorship" | ||
|
||
def get_list_filter(self, request): | ||
fields = list(super().get_list_filter(request)) | ||
return fields + ['is_published'] | ||
def preview_sponsorship_view(self, request, pk): | ||
sponsorship = get_object_or_404(self.get_queryset(request), pk=pk) | ||
ctx = {"sponsorship": sponsorship} | ||
return render(request, "sponsors/admin/preview-sponsorship.html", context=ctx) | ||
|
||
def get_list_display(self, request): | ||
fields = list(super().get_list_display(request)) | ||
return fields + ['is_published'] | ||
def get_urls(self, *args, **kwargs): | ||
urls = super().get_urls(*args, **kwargs) | ||
custom_urls = [ | ||
path( | ||
"<int:pk>/preview", | ||
self.admin_site.admin_view(self.preview_sponsorship_view), | ||
name="sponsors_sponsorship_preview", | ||
), | ||
] | ||
return custom_urls + urls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import json | ||
|
||
BENEFITS_COOKIE_NAME = "sponsorship_selected_benefits" | ||
|
||
|
||
def get_sponsorship_selected_benefits(request): | ||
sponsorship_selected_benefits = request.COOKIES.get(BENEFITS_COOKIE_NAME) | ||
if sponsorship_selected_benefits: | ||
try: | ||
return json.loads(sponsorship_selected_benefits) | ||
except json.JSONDecodeError: | ||
pass | ||
return {} | ||
|
||
|
||
def set_sponsorship_selected_benefits(response, data): | ||
max_age = 60 * 60 * 24 # one day | ||
response.set_cookie(BENEFITS_COOKIE_NAME, json.dumps(data), max_age=max_age) | ||
|
||
|
||
def delete_sponsorship_selected_benefits(response): | ||
response.delete_cookie(BENEFITS_COOKIE_NAME) |
Oops, something went wrong.