Show
Ignore:
Timestamp:
05/28/08 20:22:40 (7 months ago)
Author:
simon
Message:

Implemented tagging.
Switched to arrows for the "Newer | Older" navigation.
Removed special behaviour for logged in users.

Location:
bitstructures/trunk/substructure
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • bitstructures/trunk/substructure/models.py

    r6 r74  
    4747            return '/drafts/%s' % (self.slug) 
    4848 
     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 
    4956    class Admin: 
    5057        fields = ( 
     
    5461        list_display = ('title', 'get_absolute_url', 'date_published') 
    5562        ordering = ['-date_published'] 
     63 
     64class 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 
     76class 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  
    1010    (r'^fb-atom.xml$', 'atom_feed'), 
    1111    (r'^all$', 'all'), 
     12    (r'^tagged-with/(?P<tag_name>[a-z0-9-]+)$', 'tagged_with'), 
    1213    (r'^robots.txt$', 'robots_txt') 
    1314) 
  • bitstructures/trunk/substructure/views.py

    r73 r74  
    55from django.contrib.sites.models import Site 
    66from django.conf import settings 
    7 from bitstructures.substructure.models import Entry 
     7from bitstructures.substructure.models import Entry, Tag, EntryTag 
    88from bitstructures.substructure.codeblocks import MarkdownCodeblocksParser 
    99 
     
    9494    return render_to_response('substructure/all.html', data) 
    9595 
     96def 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 
     103def 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 
    96112def robots_txt(request): 
    97113    return HttpResponse(render_to_string('substructure/robots.txt'), 
     
    107123    data = { 'MEDIA_URL': settings.MEDIA_URL } 
    108124    data['num_published_entries'] = get_published_entries().count() 
    109     if user_can_change_entry(request): 
    110         data['user_can_change_entry'] = True 
    111         data['drafts'] = get_drafts() 
    112125    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')