Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b18a853

Browse files
authored
Merge branch 'master' into ilevkivskyi-colour
2 parents fba9086 + bcbe083 commit b18a853

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5852
-167
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ static-root/
1515
static/stylesheets/mq.css
1616
static/stylesheets/no-mq.css
1717
static/stylesheets/style.css
18+
__pycache__
19+
*.db

base-requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ django-waffle==0.14
3737
djangorestframework==3.8.2
3838
django-filter==1.1.0
3939

40+
django-ordered-model==3.4.1
41+
django-widget-tweaks==1.4.8
42+
4043
pygments==2.1.3 # This will be not needed when PEPs are moved to RtD.

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ responses==0.10.5
1212
django-debug-toolbar==1.9.1
1313
coverage
1414
ddt
15+
model-bakery==1.2.0

fixtures/sponsors.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

pydotorg/settings/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@
151151
'haystack',
152152
'honeypot',
153153
'waffle',
154+
'ordered_model',
155+
'widget_tweaks',
154156

155157
'users',
156158
'boxes',

pydotorg/settings/pipeline.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
'media': 'screen',
3232
},
3333
},
34+
'font-awesome': {
35+
'source_filenames': (
36+
'stylesheets/font-awesome.min.css',
37+
),
38+
'output_filename': 'stylesheets/no-mq.css',
39+
'extra_context': {
40+
'media': 'screen',
41+
},
42+
},
3443
}
3544

3645
PIPELINE_JS = {
@@ -41,6 +50,12 @@
4150
),
4251
'output_filename': 'js/main-min.js',
4352
},
53+
'sponsors': {
54+
'source_filenames': (
55+
'js/sponsors/applicationForm.js',
56+
),
57+
'output_filename': 'js/sponsors-min.js',
58+
},
4459
'IE8': {
4560
'source_filenames': (
4661
'js/plugins/IE8.js',

sponsors/admin.py

Lines changed: 112 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,121 @@
1+
from ordered_model.admin import OrderedModelAdmin
2+
3+
from django.urls import path, reverse
14
from django.contrib import admin
5+
from django.utils.html import mark_safe
6+
from django.shortcuts import get_object_or_404, render
27

3-
from .models import Sponsor
8+
from .models import (
9+
SponsorshipPackage,
10+
SponsorshipProgram,
11+
SponsorshipBenefit,
12+
Sponsor,
13+
Sponsorship,
14+
SponsorContact,
15+
)
416
from cms.admin import ContentManageableModelAdmin
517

618

19+
@admin.register(SponsorshipProgram)
20+
class SponsorshipProgramAdmin(OrderedModelAdmin):
21+
ordering = ("order",)
22+
list_display = [
23+
"name",
24+
"move_up_down_links",
25+
]
26+
27+
28+
@admin.register(SponsorshipBenefit)
29+
class SponsorshipBenefitAdmin(OrderedModelAdmin):
30+
ordering = ("program", "order")
31+
list_display = [
32+
"program",
33+
"short_name",
34+
"package_only",
35+
"internal_value",
36+
"move_up_down_links",
37+
]
38+
list_filter = ["program"]
39+
search_fields = ["name"]
40+
41+
fieldsets = [
42+
(
43+
"Public",
44+
{
45+
"fields": (
46+
"name",
47+
"description",
48+
"program",
49+
"packages",
50+
"package_only",
51+
"new",
52+
),
53+
},
54+
),
55+
(
56+
"Internal",
57+
{
58+
"fields": (
59+
"internal_description",
60+
"internal_value",
61+
"capacity",
62+
"soft_capacity",
63+
"conflicts",
64+
)
65+
},
66+
),
67+
]
68+
69+
70+
@admin.register(SponsorshipPackage)
71+
class SponsorshipPackageAdmin(OrderedModelAdmin):
72+
ordering = ("order",)
73+
list_display = ["name", "move_up_down_links"]
74+
75+
76+
class SponsorContactInline(admin.TabularInline):
77+
model = SponsorContact
78+
extra = 0
79+
80+
781
@admin.register(Sponsor)
882
class SponsorAdmin(ContentManageableModelAdmin):
9-
raw_id_fields = ['company']
83+
inlines = [SponsorContactInline]
84+
85+
86+
@admin.register(Sponsorship)
87+
class SponsorshipAdmin(admin.ModelAdmin):
88+
list_display = [
89+
"sponsor",
90+
"applied_on",
91+
"approved_on",
92+
"start_date",
93+
"end_date",
94+
"display_sponsorship_link",
95+
]
96+
97+
def get_queryset(self, *args, **kwargs):
98+
qs = super().get_queryset(*args, **kwargs)
99+
return qs.select_related("sponsor")
100+
101+
def display_sponsorship_link(self, obj):
102+
url = reverse("admin:sponsors_sponsorship_preview", args=[obj.pk])
103+
return mark_safe(f'<a href="{url}" target="_blank">Click to preview</a>')
104+
105+
display_sponsorship_link.short_description = "Preview sponsorship"
10106

11-
def get_list_filter(self, request):
12-
fields = list(super().get_list_filter(request))
13-
return fields + ['is_published']
107+
def preview_sponsorship_view(self, request, pk):
108+
sponsorship = get_object_or_404(self.get_queryset(request), pk=pk)
109+
ctx = {"sponsorship": sponsorship}
110+
return render(request, "sponsors/admin/preview-sponsorship.html", context=ctx)
14111

15-
def get_list_display(self, request):
16-
fields = list(super().get_list_display(request))
17-
return fields + ['is_published']
112+
def get_urls(self, *args, **kwargs):
113+
urls = super().get_urls(*args, **kwargs)
114+
custom_urls = [
115+
path(
116+
"<int:pk>/preview",
117+
self.admin_site.admin_view(self.preview_sponsorship_view),
118+
name="sponsors_sponsorship_preview",
119+
),
120+
]
121+
return custom_urls + urls

sponsors/cookies.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import json
2+
3+
BENEFITS_COOKIE_NAME = "sponsorship_selected_benefits"
4+
5+
6+
def get_sponsorship_selected_benefits(request):
7+
sponsorship_selected_benefits = request.COOKIES.get(BENEFITS_COOKIE_NAME)
8+
if sponsorship_selected_benefits:
9+
try:
10+
return json.loads(sponsorship_selected_benefits)
11+
except json.JSONDecodeError:
12+
pass
13+
return {}
14+
15+
16+
def set_sponsorship_selected_benefits(response, data):
17+
max_age = 60 * 60 * 24 # one day
18+
response.set_cookie(BENEFITS_COOKIE_NAME, json.dumps(data), max_age=max_age)
19+
20+
21+
def delete_sponsorship_selected_benefits(response):
22+
response.delete_cookie(BENEFITS_COOKIE_NAME)

0 commit comments

Comments
 (0)