This repository has been archived by the owner on May 1, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Greenfeld
committed
Jul 30, 2015
1 parent
08ea0f2
commit f2280da
Showing
5 changed files
with
36 additions
and
4 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 |
---|---|---|
@@ -1,5 +1,34 @@ | ||
from django.contrib import admin | ||
from django.utils.safestring import mark_safe | ||
|
||
from .behaviors import Spammable | ||
from .exceptions import SpamNotFound | ||
from .models import SpammyPosting | ||
from .utils import spammables | ||
|
||
admin.site.register(SpammyPosting) | ||
class SpammyPostingAdmin(admin.ModelAdmin): | ||
model = SpammyPosting | ||
readonly_fields = ('source', 'created', 'modified',) | ||
|
||
def source(self, instance): | ||
|
||
for spammable in spammables(): | ||
try: | ||
content = spammable.objects.get(spam_flag=instance.pk) | ||
except SpammyPosting.DoesNotExist: | ||
continue | ||
break | ||
else: | ||
raise SpamNotFound(spammable) | ||
|
||
response = """<a href="{0}">{1}</a>""".format( | ||
content.get_absolute_url(), | ||
content | ||
) | ||
|
||
return mark_safe(response) | ||
|
||
source.short_description = "Source URL" | ||
source.allow_tags = True | ||
|
||
admin.site.register(SpammyPosting, SpammyPostingAdmin) |
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,2 @@ | ||
class SpamNotFound(Exception): | ||
"""When the system can't find spam the user defined""" |
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