Changeset 74 for bitstructures/trunk
- Timestamp:
- 05/28/08 20:22:40 (3 months ago)
- Files:
-
- bitstructures/trunk/css/bitstructures.css (modified) (1 diff)
- bitstructures/trunk/db (added)
- bitstructures/trunk/db/update1.sql (added)
- bitstructures/trunk/substructure/models.py (modified) (2 diffs)
- bitstructures/trunk/substructure/urls.py (modified) (1 diff)
- bitstructures/trunk/substructure/views.py (modified) (3 diffs)
- bitstructures/trunk/templates/substructure/base.html (modified) (2 diffs)
- bitstructures/trunk/templates/substructure/blog.html (modified) (1 diff)
- bitstructures/trunk/templates/substructure/entry.html (modified) (1 diff)
- bitstructures/trunk/templates/substructure/tagged-with.html (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
bitstructures/trunk/css/bitstructures.css
r72 r74 77 77 } 78 78 79 p.entry- date{79 p.entry-info { 80 80 margin-top: 0; 81 81 } bitstructures/trunk/substructure/models.py
r6 r74 47 47 return '/drafts/%s' % (self.slug) 48 48 49 def tags(self): 50 entrytags = EntryTag.objects.select_related().filter(entry=self).order_by('number') 51 tags = [] 52 for entrytag in entrytags: 53 tags.append(entrytag.tag) 54 return tags 55 49 56 class Admin: 50 57 fields = ( … … 54 61 list_display = ('title', 'get_absolute_url', 'date_published') 55 62 ordering = ['-date_published'] 63 64 class Tag(models.Model): 65 name = models.CharField(maxlength=50, blank=False) 66 67 def __str__(self): 68 return self.name 69 70 def get_absolute_url(self): 71 return '/tagged-with/%s' % (self.name) 72 73 class Admin: 74 pass 75 76 class EntryTag(models.Model): 77 entry = models.ForeignKey(Entry) 78 tag = models.ForeignKey(Tag) 79 number = models.IntegerField() 80 81 class Admin: 82 list_display = ('entry', 'tag', 'number') 83 ordering = ['entry'] bitstructures/trunk/substructure/urls.py
r73 r74 10 10 (r'^fb-atom.xml$', 'atom_feed'), 11 11 (r'^all$', 'all'), 12 (r'^tagged-with/(?P<tag_name>[a-z0-9-]+)$', 'tagged_with'), 12 13 (r'^robots.txt$', 'robots_txt') 13 14 ) bitstructures/trunk/substructure/views.py
r73 r74 5 5 from django.contrib.sites.models import Site 6 6 from django.conf import settings 7 from bitstructures.substructure.models import Entry 7 from bitstructures.substructure.models import Entry, Tag, EntryTag 8 8 from bitstructures.substructure.codeblocks import MarkdownCodeblocksParser 9 9 … … 94 94 return render_to_response('substructure/all.html', data) 95 95 96 def tagged_with(request, tag_name): 97 tag = get_object_or_404(Tag, name=tag_name) 98 data = get_context_data(request) 99 data['tag'] = tag 100 data['entry_list'] = get_published_entries_with_tag(tag) 101 return render_to_response('substructure/tagged-with.html', data) 102 103 def get_published_entries_with_tag(tag): 104 entrytags = EntryTag.objects.select_related().filter(tag=tag) 105 entry_list = [] 106 for entrytag in entrytags: 107 entry = entrytag.entry 108 if entry.is_published: 109 entry_list.append(entry) 110 return entry_list 111 96 112 def robots_txt(request): 97 113 return HttpResponse(render_to_string('substructure/robots.txt'), … … 107 123 data = { 'MEDIA_URL': settings.MEDIA_URL } 108 124 data['num_published_entries'] = get_published_entries().count() 109 if user_can_change_entry(request):110 data['user_can_change_entry'] = True111 data['drafts'] = get_drafts()112 125 return data 113 114 def user_can_change_entry(request):115 return request.user.has_perm('change_entry')116 117 def get_drafts():118 return Entry.objects.filter(date_published__isnull=True).order_by('title')bitstructures/trunk/templates/substructure/base.html
r72 r74 5 5 6 6 <head> 7 <title> {% block title %}Bitstructures —Simon Bates{% endblock %}</title>7 <title>Bitstructures — {% block title %}Simon Bates{% endblock %}</title> 8 8 <link rel="alternate" type="application/atom+xml" href="/atom.xml"> 9 9 <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/bitstructures.css"> … … 53 53 </div> 54 54 55 {% if drafts %}56 <div id="drafts" class="info-entry">57 <h2>Drafts</h2>58 <ul>59 {% for entry in drafts %}60 <li><a href="{{ entry.get_absolute_url }}">{{ entry.title|escape }}</a></li>61 {% endfor %}62 </ul>63 <p><a href="/admin/substructure/entry/add/">new entry</a></p>64 </div>65 {% endif %}66 67 55 </div> 68 56 </div> bitstructures/trunk/templates/substructure/blog.html
r72 r74 7 7 {% endfor %} 8 8 9 <div class="page-nav">{% if previous_page %}<a href="/{% if not previous_page_first_page %}?page={{ previous_page_num }}{% endif %}">&la quo; newer</a>{% else %}« newer{% endif %}10 | {% if next_page %}<a href="/?page={{ next_page_num }}"> older »</a>{% else %}older »{% endif %}</div>9 <div class="page-nav">{% if previous_page %}<a href="/{% if not previous_page_first_page %}?page={{ previous_page_num }}{% endif %}">← Newer</a>{% else %}← Newer{% endif %} 10 | {% if next_page %}<a href="/?page={{ next_page_num }}">Older →</a>{% else %}Older →{% endif %}</div> 11 11 12 12 {% endblock %} bitstructures/trunk/templates/substructure/entry.html
r42 r74 5 5 <h2><a href="{{ entry.get_absolute_url }}">{{ entry.title|escape }}</a></h2> 6 6 7 {% if entry.date_published %} 8 <p class="entry-date">{{ entry.date_published|date:"F j, Y" }}</p> 9 {% endif %} 10 11 {% if user_can_change_entry %} 12 <p><a href="/admin/substructure/entry/{{ entry.id }}/">edit</a></p> 13 {% endif %} 7 <p class="entry-info">{% if entry.date_published %}{{ entry.date_published|date:"F j, Y" }}<br>{% endif %}Tags: 8 {% for tag in entry.tags %}<a href="{{ tag.get_absolute_url }}">{{ tag.name|escape }}</a> 9 {% endfor %}</p> 14 10 15 11 {{ entry.text|syntax_highlighted_markdown }}
