Skip to content

Commit

Permalink
Revert "Add Homepage admin view (#723)"
Browse files Browse the repository at this point in the history
This reverts commit 0acba20.
  • Loading branch information
gvn authored Sep 18, 2017
1 parent 33913db commit c3275af
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 216 deletions.
79 changes: 2 additions & 77 deletions network-api/app/networkapi/homepage/admin.py
Original file line number Diff line number Diff line change
@@ -1,78 +1,3 @@
from django.contrib import admin
from mezzanine.utils.admin import SingletonAdmin
# from django.contrib import admin

from networkapi.homepage.models import (
Homepage,
HomepageLeaders,
HomepageNews,
HomepageHighlights,
)


# Base class for the inline forms for People, News, and Highlights
# containing the common config for each of the forms
class FeatureInlineAdmin(admin.StackedInline):
extra = 0 # Allows us to show the 'Add another' link
min_num = 3
# We override the default template for stacked inlines so that we can
# customize the label for each field
template = 'admin/homepage/homepage/edit_inline/stacked.html'

# To disable the icons that allow you to add/change the related models,
# we set the flags that allow these operations to False on the widgets
# associated with those related model fields. We override the formset
# method to get access to those fields.
def get_formset(self, request, obj=None, **kwargs):
formset = super().get_formset(request, obj, **kwargs)
base_fields = formset.form.base_fields

for field in base_fields:
base_fields[field].widget.can_add_related = False
base_fields[field].widget.can_change_related = False
base_fields[field].label = 'Feature'

return formset

# Only superusers can add new homepage fields
def has_add_permission(self, request):
return request.user.is_superuser


class LeaderInlineAdmin(FeatureInlineAdmin):
model = HomepageLeaders
fields = ('leader',)


class NewsInlineAdmin(FeatureInlineAdmin):
model = HomepageNews
fields = ('news',)
min_num = 4


class HighlightInlineAdmin(FeatureInlineAdmin):
model = HomepageHighlights
fields = ('highlights',)


class HomepageAdmin(SingletonAdmin):
inlines = [
LeaderInlineAdmin,
NewsInlineAdmin,
HighlightInlineAdmin,
]

# We override this function so that we can rename the header shown for this
# admin view
def change_view(self, request, object_id, form_url='', extra_context=None):
extra_context = extra_context or {}
extra_context['title'] = 'Homepage Features'

return super().change_view(
request,
object_id,
form_url,
extra_context=extra_context,
)


admin.site.register(Homepage, HomepageAdmin)
# Register your models here.
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit c3275af

Please sign in to comment.