Skip to content

Commit

Permalink
Merge branch 'master' into ilevkivskyi-colour
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Nov 16, 2020
2 parents fba9086 + bcbe083 commit b18a853
Show file tree
Hide file tree
Showing 48 changed files with 5,852 additions and 167 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ static-root/
static/stylesheets/mq.css
static/stylesheets/no-mq.css
static/stylesheets/style.css
__pycache__
*.db
3 changes: 3 additions & 0 deletions base-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ django-waffle==0.14
djangorestframework==3.8.2
django-filter==1.1.0

django-ordered-model==3.4.1
django-widget-tweaks==1.4.8

pygments==2.1.3 # This will be not needed when PEPs are moved to RtD.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ responses==0.10.5
django-debug-toolbar==1.9.1
coverage
ddt
model-bakery==1.2.0
1 change: 1 addition & 0 deletions fixtures/sponsors.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pydotorg/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
'haystack',
'honeypot',
'waffle',
'ordered_model',
'widget_tweaks',

'users',
'boxes',
Expand Down
15 changes: 15 additions & 0 deletions pydotorg/settings/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
'media': 'screen',
},
},
'font-awesome': {
'source_filenames': (
'stylesheets/font-awesome.min.css',
),
'output_filename': 'stylesheets/no-mq.css',
'extra_context': {
'media': 'screen',
},
},
}

PIPELINE_JS = {
Expand All @@ -41,6 +50,12 @@
),
'output_filename': 'js/main-min.js',
},
'sponsors': {
'source_filenames': (
'js/sponsors/applicationForm.js',
),
'output_filename': 'js/sponsors-min.js',
},
'IE8': {
'source_filenames': (
'js/plugins/IE8.js',
Expand Down
120 changes: 112 additions & 8 deletions sponsors/admin.py
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
22 changes: 22 additions & 0 deletions sponsors/cookies.py
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)
Loading

0 comments on commit b18a853

Please sign in to comment.