diff options
author | bnewbold <bnewbold@eta.mit.edu> | 2009-02-01 06:25:10 -0500 |
---|---|---|
committer | bnewbold <bnewbold@eta.mit.edu> | 2009-02-01 06:25:10 -0500 |
commit | c7b29da94d3b85ec91f0d5e2789db11a43473df5 (patch) | |
tree | a5502674da4a9ed8367f911112d34c094481e83c /bn_django/journal | |
parent | 0988ee83c8a8b24801624beae78ceba1bfa82d07 (diff) | |
download | bnewnet-c7b29da94d3b85ec91f0d5e2789db11a43473df5.tar.gz bnewnet-c7b29da94d3b85ec91f0d5e2789db11a43473df5.zip |
lots went on:
* rss feeds
* some admin interface stuff
* blah
running issues:
* admin interface with model inheretence?
* rss feeds: unicode cool?
* proper year/month implementation (don't want day)
* right side bar info
* dating issue (datetime vs date)
Diffstat (limited to 'bn_django/journal')
19 files changed, 325 insertions, 34 deletions
diff --git a/bn_django/journal/admin.py b/bn_django/journal/admin.py new file mode 100644 index 0000000..3f1024c --- /dev/null +++ b/bn_django/journal/admin.py @@ -0,0 +1,51 @@ +from django.contrib import admin +from bn_django.journal.models import * + +class EntryAdmin(admin.ModelAdmin): + #fieldsets = ( + #(None, { + #'fields': ('title', 'date', 'html_content', 'author', 'subjournal') + #}, ), + ##('Advanced options', { + #'classes': ('collapse',), + #'fields': ('slug',)})) + #prepopulated_fields = {'slug': ('title'),'text_content': ('html_content')} + #date_hierarchy = 'date' + #list_display = ('date', 'title', 'subjournal', 'author') + search_fields = ('title','text_content') + +class MicroEntryAdmin(admin.ModelAdmin): + #fieldsets = ( + #(None, { + #'fields': ('title', 'date', 'html_content', 'author', + #'subjournal',), }), + #('Advanced options', { + #'classes': ('collapse',), + #'fields': ('slug',)})) + prepopulated_fields = {'slug': ('title'),'text_content': ('html_content')} + date_hierarchy = 'date' + list_display = ('date', 'title', 'subjournal', 'author') + search_fields = ('title','text_content') + +class SubJournalAdmin(admin.ModelAdmin): + pass + +class LinkArtifactAdmin(admin.ModelAdmin): + pass + +class CodeAdmin(admin.ModelAdmin): + pass + +class VideoAdmin(admin.ModelAdmin): + pass + +class ImageAdmin(admin.ModelAdmin): + pass + +admin.site.register(Entry,EntryAdmin) +admin.site.register(MicroEntry,EntryAdmin) +admin.site.register(SubJournal) +admin.site.register(LinkArtifact) +admin.site.register(CodeArtifact) +admin.site.register(VideoArtifact) +admin.site.register(ImageArtifact) diff --git a/bn_django/journal/feeds.py b/bn_django/journal/feeds.py new file mode 100644 index 0000000..3577c46 --- /dev/null +++ b/bn_django/journal/feeds.py @@ -0,0 +1,34 @@ +from django.contrib.syndication.feeds import Feed +from models import Entry, MicroEntry, LinkArtifact + + +class LatestEntries(Feed): + title = "bnewbold.net journal entries" + link = "/journal/entries/" + description = " " + + def items(self): + return Entry.objects.order_by('-date')[:5] + +class LatestMicroEntries(Feed): + title = "bnewbold.net microentries" + link = "/journal/microentries/" + description = "Quick updates" + + def items(self): + return MicroEntry.objects.order_by('-date')[:5] + +class LatestLinks(Feed): + title = "bnewbold.net links" + link = "/artifacts/links/" + description = "Links to love" + + def items(self): + return LinkArtifact.objects.order_by('-date')[:5] + + def item_link(self,item): + return item.url + +feed_list = {'latest_entries':LatestEntries, + 'latest_microentries':LatestMicroEntries, + 'latest_links':LatestLinks } diff --git a/bn_django/journal/models.py b/bn_django/journal/models.py index d296f1f..20107c9 100644 --- a/bn_django/journal/models.py +++ b/bn_django/journal/models.py @@ -10,6 +10,9 @@ class SubJournal(models.Model): slug = models.SlugField() description = models.TextField("description of content",blank=True) + def __unicode__(self): + return self.name + class Meta: get_latest_by = 'date' ordering = ['-date'] @@ -17,7 +20,7 @@ class SubJournal(models.Model): class JournalCommon(models.Model): author = User("User who created this") date = models.DateTimeField("associated day", auto_now=True) - last_edited = models.DateField("day last edited", auto_now_add=True) + last_edited = models.DateTimeField("day last edited", auto_now_add=True) subjournal = models.ForeignKey(SubJournal,blank=True,null=True) defunct = models.BooleanField("is this entry all around done with?",default=False,blank=False) private = models.BooleanField("is this entry for validated users only?",default=False,blank=False) @@ -32,13 +35,24 @@ class Entry(JournalCommon): title = models.CharField("entry title", max_length=384) slug = models.SlugField() + def __unicode__(self): + return self.title + def get_absolute_url(self): - return "/journal/%s/"%self.slug + #return "/journal/entries/%04d/%02d/%02d/%s/"%(self.date.year, self.date.month, self.date.day, self.slug) + return "/journal/entries/%s/"%self.slug class MicroEntry(JournalCommon): html_content = models.TextField("html format content", blank=False) text_content = models.TextField("text version of content", blank=True,null=True) + def __unicode__(self): + self.text_content[:50] + + def get_absolute_url(self): + return "/journal/microentries/%s/"%self.id + #return "/journal/microentries/%04d/%02d/%02d/%s/"%(self.date.year, self.date.month, self.date.day, self.slug) + class Artifact(JournalCommon): html_caption = models.TextField("html format caption", blank=True) text_caption = models.TextField("text format caption", blank=True) @@ -61,6 +75,12 @@ class CodeArtifact(Artifact): class LinkArtifact(Artifact): url = models.URLField("external link to something wonderful!",verify_exists=False) + def __unicode__(self): + return self.title + + def get_absolute_url(self): + return "/artifacts/links/%s/"% self.id + class ImageArtifact(Artifact,Photo): """Multiply inherets from the photo app """ @@ -76,13 +96,3 @@ def delete_thumbnails(sender, instance, signal, *args, **kwargs): signals.post_save.connect(build_display_images, sender=ImageArtifact) signals.pre_delete.connect(delete_thumbnails, sender=ImageArtifact) - -from django.contrib import admin - -admin.site.register(Entry) -admin.site.register(MicroEntry) -admin.site.register(SubJournal) -admin.site.register(LinkArtifact) -admin.site.register(CodeArtifact) -admin.site.register(VideoArtifact) -admin.site.register(ImageArtifact) diff --git a/bn_django/journal/templates/feeds/latest_entries_description.html b/bn_django/journal/templates/feeds/latest_entries_description.html new file mode 100644 index 0000000..6f28865 --- /dev/null +++ b/bn_django/journal/templates/feeds/latest_entries_description.html @@ -0,0 +1 @@ +{{obj.html_content|safe|truncatewords_html:300}} diff --git a/bn_django/journal/templates/feeds/latest_entries_title.html b/bn_django/journal/templates/feeds/latest_entries_title.html new file mode 100644 index 0000000..e12d8e1 --- /dev/null +++ b/bn_django/journal/templates/feeds/latest_entries_title.html @@ -0,0 +1 @@ +{{obj.title|safe}} diff --git a/bn_django/journal/templates/feeds/latest_links_description.html b/bn_django/journal/templates/feeds/latest_links_description.html new file mode 100644 index 0000000..32c8857 --- /dev/null +++ b/bn_django/journal/templates/feeds/latest_links_description.html @@ -0,0 +1 @@ +{{ obj.html_caption|safe|truncatewords_html:200}} diff --git a/bn_django/journal/templates/feeds/latest_links_title.html b/bn_django/journal/templates/feeds/latest_links_title.html new file mode 100644 index 0000000..65599bb --- /dev/null +++ b/bn_django/journal/templates/feeds/latest_links_title.html @@ -0,0 +1 @@ +{{ obj.title }}: {{ obj.url }} diff --git a/bn_django/journal/templates/feeds/latest_microentries_description.html b/bn_django/journal/templates/feeds/latest_microentries_description.html new file mode 100644 index 0000000..427823d --- /dev/null +++ b/bn_django/journal/templates/feeds/latest_microentries_description.html @@ -0,0 +1 @@ +{{obj.html_content|safe|truncatewords_html:160}} diff --git a/bn_django/journal/templates/feeds/latest_microentries_title.html b/bn_django/journal/templates/feeds/latest_microentries_title.html new file mode 100644 index 0000000..d992ff6 --- /dev/null +++ b/bn_django/journal/templates/feeds/latest_microentries_title.html @@ -0,0 +1 @@ +{{obj.title}} diff --git a/bn_django/journal/templates/journal/entry_archive_month.html b/bn_django/journal/templates/journal/entry_archive_month.html new file mode 100644 index 0000000..a9e72da --- /dev/null +++ b/bn_django/journal/templates/journal/entry_archive_month.html @@ -0,0 +1,35 @@ +{% extends "journal/base.html" %} +{% load comments %} + +{% block title %}Journal Entries{% endblock %} + +{% block content %} +<br /> +<div class="notice"> +This page has an <a href="/journal/entries/rss.xml">RSS feed</a>. +<br /> +See also <a href="/artifacts/">artifacts</a>, <a href="microentries"> +microentries</a>. + +</div> +{% if object_list %} + {% for item in object_list %} + {% get_comment_count for item as comment_count %} + <h3><a href="{{ item.get_absolute_url }}"> + {% if item.title %}{{item.title}}{%else%}[Untitled]{%endif%}</a></h3> + <i>{{item.date|date:"D, d/m/Y @H:i"}} by {{ item.author.username }}. + <a href="{{ item.get_absolute_url }}#commentary">{{ comment_count }} comments</a></i> + <p style="padding-left:30px"> + {{ item.html_content|truncatewords_html:256 }} + </p> + {% endfor %} +{% else %} +<p>No entries have been entered yet!</p> +{% endif %} + +{% if is_paginated %} {% if has_previous %} +<a href="./?page={{ previous }}">« previous</a> | +{% endif %} {% if has_next %} +<a href="./?page={{ next }}">next »</a> +{% endif %} {% endif %} +{% endblock %} diff --git a/bn_django/journal/templates/journal/entry_archive_year.html b/bn_django/journal/templates/journal/entry_archive_year.html new file mode 100644 index 0000000..a9e72da --- /dev/null +++ b/bn_django/journal/templates/journal/entry_archive_year.html @@ -0,0 +1,35 @@ +{% extends "journal/base.html" %} +{% load comments %} + +{% block title %}Journal Entries{% endblock %} + +{% block content %} +<br /> +<div class="notice"> +This page has an <a href="/journal/entries/rss.xml">RSS feed</a>. +<br /> +See also <a href="/artifacts/">artifacts</a>, <a href="microentries"> +microentries</a>. + +</div> +{% if object_list %} + {% for item in object_list %} + {% get_comment_count for item as comment_count %} + <h3><a href="{{ item.get_absolute_url }}"> + {% if item.title %}{{item.title}}{%else%}[Untitled]{%endif%}</a></h3> + <i>{{item.date|date:"D, d/m/Y @H:i"}} by {{ item.author.username }}. + <a href="{{ item.get_absolute_url }}#commentary">{{ comment_count }} comments</a></i> + <p style="padding-left:30px"> + {{ item.html_content|truncatewords_html:256 }} + </p> + {% endfor %} +{% else %} +<p>No entries have been entered yet!</p> +{% endif %} + +{% if is_paginated %} {% if has_previous %} +<a href="./?page={{ previous }}">« previous</a> | +{% endif %} {% if has_next %} +<a href="./?page={{ next }}">next »</a> +{% endif %} {% endif %} +{% endblock %} diff --git a/bn_django/journal/templates/journal/entry_detail.html b/bn_django/journal/templates/journal/entry_detail.html index 9c74ed6..b68e4b6 100644 --- a/bn_django/journal/templates/journal/entry_detail.html +++ b/bn_django/journal/templates/journal/entry_detail.html @@ -1,8 +1,8 @@ {% extends "journal/base.html" %} -{# {% load markup %} #} {% load comments %} + {% block path %}{{ block.super }} - »<a href="../{{ object.slug }}"> {{ object.title }}</a> + »<a href="{{object.get_absolute_url}}"> {{ object.title }}</a> {% endblock %} {% block title %} diff --git a/bn_django/journal/templates/journal/entry_list.html b/bn_django/journal/templates/journal/entry_list.html index caa07af..8902552 100644 --- a/bn_django/journal/templates/journal/entry_list.html +++ b/bn_django/journal/templates/journal/entry_list.html @@ -1,18 +1,34 @@ {% extends "journal/base.html" %} -{# {% load markup %} #} +{% load comments %} {% block title %}Journal Entries{% endblock %} +{% block otherhead %}{{ block.super}} +<link rel="alternate" type="application/rss+xml" title="RSS" href="/journal/rss/latest_entries/"> +{% endblock %} + {% block content %} <br /> +<div class="notice"> +This page has an <a href="/journal/rss/latest_entries/">RSS feed</a>. +<br /> +See also <a href="/artifacts/">artifacts</a>, <a href="microentries"> +microentries</a>. + +</div> {% if object_list %} -<ul> {% for item in object_list %} - <li /><a href="/journal/entries/{{ item.slug }}/">{{item.title}} + {% get_comment_count for item as comment_count %} + <h3><a href="{{ item.get_absolute_url }}"> + {% if item.title %}{{item.title}}{%else%}[Untitled]{%endif%}</a></h3> + <i>{{item.date|date:"D, d/m/Y @H:i"}} by {{ item.author.username }}. + <a href="{{ item.get_absolute_url }}#commentary">{{ comment_count }} comments</a></i> + <p style="padding-left:30px"> + {{ item.html_content|truncatewords_html:256 }} + </p> {% endfor %} -</ul> {% else %} -<p>No entries have been entered yet.</p> +<p>No entries have been entered yet!</p> {% endif %} {% if is_paginated %} {% if has_previous %} diff --git a/bn_django/journal/templates/journal/linkartifact_list.html b/bn_django/journal/templates/journal/linkartifact_list.html index 829e627..51e9ebe 100644 --- a/bn_django/journal/templates/journal/linkartifact_list.html +++ b/bn_django/journal/templates/journal/linkartifact_list.html @@ -1,5 +1,9 @@ {% extends "journal/base.html" %} +{% block otherhead %}{{ block.super}} +<link rel="alternate" type="application/rss+xml" title="RSS" href="/journal/rss/latest_links/"> +{% endblock %} + {% block path %}<a href="/artifacts/">artifacts</a> »<a href="/artifacts/links/"> links</a> {% endblock %} @@ -8,6 +12,12 @@ {% block content %} <br /> +<div class="notice"> +This page has an <a href="/journal/rss/latest_links/">RSS feed</a>. +<br /> +microentries</a>. +</div> + {% if object_list %} <ul> {% for item in object_list %} diff --git a/bn_django/journal/templates/journal/microentry_arhive_month.html b/bn_django/journal/templates/journal/microentry_arhive_month.html new file mode 100644 index 0000000..eca642d --- /dev/null +++ b/bn_django/journal/templates/journal/microentry_arhive_month.html @@ -0,0 +1,31 @@ +{% extends "journal/base.html" %} +{% load comments %} + +{% block path %}{{block.super}} + »<a href="/journal/microentries/"> microentries</a> + +{% block title %}Journal Microentries{% endblock %} + +{% block content %} +<br /> +{% if object_list %} + {% for item in object_list %} + <b>{{item.date|date:"D, d/m/Y @H:i"}}: + <a href="{{ item.get_absolute_url }}"> + {% if item.title %}{{item.title}}{%else%}[Untitled]{%endif%}</a></b> + <p style="padding-left:30px"> + {{ item.html_content|truncatewords_html:256 }} + {% get_comment_count for item as comment_count %} + (<a href="{{ item.get_absolute_url }}#commentary">{{ comment_count }} comments</a>) + </p> + {% endfor %} +{% else %} +<p>No entries have been entered yet!</p> +{% endif %} + +{% if is_paginated %} {% if has_previous %} +<a href="./?page={{ previous }}">« previous</a> | +{% endif %} {% if has_next %} +<a href="./?page={{ next }}">next »</a> +{% endif %} {% endif %} +{% endblock %} diff --git a/bn_django/journal/templates/journal/microentry_arhive_year.html b/bn_django/journal/templates/journal/microentry_arhive_year.html new file mode 100644 index 0000000..eca642d --- /dev/null +++ b/bn_django/journal/templates/journal/microentry_arhive_year.html @@ -0,0 +1,31 @@ +{% extends "journal/base.html" %} +{% load comments %} + +{% block path %}{{block.super}} + »<a href="/journal/microentries/"> microentries</a> + +{% block title %}Journal Microentries{% endblock %} + +{% block content %} +<br /> +{% if object_list %} + {% for item in object_list %} + <b>{{item.date|date:"D, d/m/Y @H:i"}}: + <a href="{{ item.get_absolute_url }}"> + {% if item.title %}{{item.title}}{%else%}[Untitled]{%endif%}</a></b> + <p style="padding-left:30px"> + {{ item.html_content|truncatewords_html:256 }} + {% get_comment_count for item as comment_count %} + (<a href="{{ item.get_absolute_url }}#commentary">{{ comment_count }} comments</a>) + </p> + {% endfor %} +{% else %} +<p>No entries have been entered yet!</p> +{% endif %} + +{% if is_paginated %} {% if has_previous %} +<a href="./?page={{ previous }}">« previous</a> | +{% endif %} {% if has_next %} +<a href="./?page={{ next }}">next »</a> +{% endif %} {% endif %} +{% endblock %} diff --git a/bn_django/journal/templates/journal/microentry_detail.html b/bn_django/journal/templates/journal/microentry_detail.html index bb94853..245fe32 100644 --- a/bn_django/journal/templates/journal/microentry_detail.html +++ b/bn_django/journal/templates/journal/microentry_detail.html @@ -3,7 +3,7 @@ {% load comments %} {% block path %}{{ block.super }} »<a href="/journal/microentries/"> microentries</a> - »<a href="/journal/microentries/{{ object.id }}"> {{ object.title }}</a> + »<a href="{{ item.get_absolute_url }}"> {{ object.title }}</a> {% endblock %} {% block title %} @@ -13,7 +13,7 @@ {% block content %}<br /> {% if object %}<div class="right_stuff"> <p class="date">dated {{ object.date }}, -{% if object.author %}<br />written by {{ object.author }},{% endif %} +{% if object.author %}<br />written by {{ object.author.username }},{% endif %} {% if object.last_edited %}<br />last edited {{ object.last_edited }}.{% endif %} </div> <p class="journal_entry">{{ object.html_content|safe }}</p> diff --git a/bn_django/journal/templates/journal/microentry_list.html b/bn_django/journal/templates/journal/microentry_list.html index aac07e7..54e63e5 100644 --- a/bn_django/journal/templates/journal/microentry_list.html +++ b/bn_django/journal/templates/journal/microentry_list.html @@ -1,23 +1,34 @@ {% extends "journal/base.html" %} +{% load comments %} -{% block path %}{{block.parent}} - »<a href="/journal/microentries/"> microentries</a> - »<a href="/journal/microentries/{{ object.id }}"> {{ object.title }}</a>{%endif%} +{% block otherhead %}{{ block.super}} +<link rel="alternate" type="application/rss+xml" title="RSS" href="/journal/rss/latest_microentries/"> +{% endblock %} + +{% block path %}{{block.super}} + »<a href="/journal/microentries/"> microentries</a>{% endblock %} -{% block title %}Journal Micro-entries{% endblock %} +{% block title %}Journal Microentries{% endblock %} {% block content %} <br /> +<div class="notice"> +This page has an <a href="/journal/rss/latest_microentries/">RSS feed</a>. +</div> + {% if object_list %} -<ul> {% for item in object_list %} - <li /><a href="/journal/microentries/{{ item.id }}/"> - {% if item.title %}{{item.title}}{%else%}[Untitled]{%endif%}</a> - ({{item.date}}) + <b>{{item.date|date:"D, d/m/Y @H:i"}}: + <a href="{{ item.get_absolute_url }}"> + {% if item.title %}{{item.title}}{%else%}[Untitled]{%endif%}</a></b> + <p style="padding-left:30px"> + {{ item.html_content|truncatewords_html:256 }} + {% get_comment_count for item as comment_count %} + (<a href="{{ item.get_absolute_url }}#commentary">{{ comment_count }} comments</a>) + </p> {% endfor %} -</ul> {% else %} -<p>No entries have been entered yet.</p> +<p>No microentries have been entered yet!</p> {% endif %} {% if is_paginated %} {% if has_previous %} diff --git a/bn_django/journal/urls.py b/bn_django/journal/urls.py index 4267e17..4b50f40 100644 --- a/bn_django/journal/urls.py +++ b/bn_django/journal/urls.py @@ -2,6 +2,7 @@ from django.conf.urls.defaults import * from django.conf import settings from models import Entry, MicroEntry +from feeds import feed_list urlpatterns = patterns('django.views.generic.list_detail', (r'^$', 'object_list', @@ -10,11 +11,31 @@ urlpatterns = patterns('django.views.generic.list_detail', (r'^entries/$', 'object_list', dict(queryset=Entry.objects.order_by('-date'), paginate_by=35, allow_empty=False)), - (r'^entries/(?P<slug>[\d\w-]+)/$', 'object_detail', - dict(queryset=Entry.objects.all(), slug_field='slug')), (r'^microentries/$', 'object_list', dict(queryset=MicroEntry.objects.order_by('-date'), paginate_by=35, allow_empty=False)), (r'^microentries/(?P<object_id>\d+)/$', 'object_detail', - dict(queryset=MicroEntry.objects.all())), + dict(queryset=Entry.objects.order_by('-date'))), + (r'^entries/(?P<slug>[\d\w-]+)/$', 'object_detail', + dict(queryset=Entry.objects.order_by('-date'))), ) + +urlpatterns += patterns('', + (r'^rss/(?P<url>.*)/$','django.contrib.syndication.views.feed', + {'feed_dict':feed_list}) +) + +#urlpatterns += patterns('django.views.generic.date_based', + #(r'^entries/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[\d\w-]+)/$', 'object_detail', + #dict(queryset=Entry.objects.all(), date_field='date')), + #(r'^entries/(?P<year>\d{4})/(?P<month>\d{2})/$', 'archive_month', + #dict(queryset=Entry.objects.all(), date_field='date')), + #(r'^entries/(?P<year>\d{4})/$', 'archive_year', + #dict(queryset=Entry.objects.all(), date_field='date')), + #(r'^microentries/(?P<year>\d{4])/(?P<month>\d{2})/(?P<day>\d{2})/(?P<object_id>\d+)/$', 'object_detail', + #dict(queryset=MicroEntry.objects.all())), + #(r'^microentries/(?P<year>\d{4})/(?P<month>\d{2})/$', 'archive_month', + #dict(queryset=MicroEntry.objects.all())), + #(r'^microentries/(?P<year>\d{4])/$', 'archive_year', + #dict(queryset=MicroEntry.objects.all())), +#) |