forked from brosner/django-announcements
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add crud views with pluggable view mixin
- idea for this is to quickly standup a staff admin for announcements and provide your own authentication rules via the mixin.
- Loading branch information
Showing
5 changed files
with
133 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django import forms | ||
|
||
from announcements.models import Announcement | ||
|
||
|
||
class AnnouncementForm(forms.ModelForm): | ||
|
||
class Meta: | ||
model = Announcement | ||
fields = [ | ||
"title", | ||
"content", | ||
"site_wide", | ||
"members_only", | ||
"dismissal_type", | ||
"publish_start", | ||
"publish_end" | ||
] |
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,30 @@ | ||
from django.conf import settings | ||
from django.utils.importlib import import_module | ||
|
||
|
||
def _resolve(mixin_setting): | ||
if isinstance(mixin_setting, basestring): | ||
try: | ||
mod_name, klass_name = mixin_setting.rsplit(".", 1) | ||
except ValueError: | ||
raise Exception("Improperly configured.") | ||
try: | ||
mod = import_module(mod_name) | ||
except ImportError: | ||
raise Exception("Could not import %s" % mod_name) | ||
try: | ||
klass = getattr(mod, klass_name) | ||
except AttributeError: | ||
raise Exception("The module '%s' does not contain '%s'." % (mod_name, klass_name)) | ||
mixin_setting = klass | ||
return mixin_setting | ||
|
||
|
||
class DefaultProtectedMixin(object): | ||
|
||
pass | ||
|
||
|
||
ProtectedMixin = _resolve( | ||
getattr(settings, "ANNOUNCEMENTS_PROTECTED_MIXIN", DefaultProtectedMixin) | ||
) |
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,6 @@ | ||
import django.dispatch | ||
|
||
|
||
announcement_created = django.dispatch.Signal(providing_args=["announcement", "request"]) | ||
announcement_updated = django.dispatch.Signal(providing_args=["announcement", "request"]) | ||
announcement_deleted = django.dispatch.Signal(providing_args=["announcement", "request"]) |
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,7 +1,15 @@ | ||
from django.conf.urls.defaults import * | ||
|
||
from announcements.views import detail, dismiss | ||
from announcements.views import CreateAnnouncementView, UpdateAnnouncementView | ||
from announcements.views import DeleteAnnouncementView, AnnouncementListView | ||
|
||
urlpatterns = patterns("", | ||
url(r"^(?P<pk>\d+)/$", "announcements.views.detail", name="announcements_detail"), | ||
url(r"^(?P<pk>\d+)/hide/$", "announcements.views.dismiss", name="announcement_dismiss") | ||
url(r"announcement/(?P<pk>\d+)/$", detail, name="announcements_detail"), | ||
url(r"announcement/(?P<pk>\d+)/hide/$", dismiss, name="announcement_dismiss"), | ||
|
||
url(r"announcement/create/$", CreateAnnouncementView.as_view(), name="announcements_create"), | ||
url(r"announcement/(?P<pk>\d+)/update/$", UpdateAnnouncementView.as_view(), name="announcements_update"), | ||
url(r"announcement/(?P<pk>\d+)/delete/$", DeleteAnnouncementView.as_view(), name="announcements_delete"), | ||
url(r"", AnnouncementListView.as_view(), name="announcements_list"), | ||
) |
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