diff --git a/links/__init__.py b/links/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/links/models.py b/links/models.py new file mode 100644 index 0000000..be528f4 --- /dev/null +++ b/links/models.py @@ -0,0 +1,140 @@ +from django.db import models +from djapps.misc.markup import markup_help, parse_markup +from djapps.tags.models import Tag +from djapps.tags import fields + + +class LinkCategory (models.Model): + + name = models.CharField (_('name'), maxlength=200, ) + + description= models.TextField (_('description'), editable=False,) + description_markup = models.TextField (_('description'), + blank=True, + help_text = markup_help['docutils'], + ) + + priority = models.PositiveIntegerField (_('priority'), + unique = True, + help_text = _('Categories will be sorted by this field.') + ) + + permalink = models.SlugField (_('permalink'), + unique=True, + prepopulate_from=('name',), + help_text = _('Easy-to-link name (good, if short, twice good).'), + ) + + pub_date = models.DateTimeField (_('publication date'), auto_now=True,) + + icon = models.ImageField (_('icon'), + upload_to = 'events/category', + blank = True, + height_field = 'icon_height', width_field = 'icon_width', + help_text = _('Optional icon for the category.'), + ) + # bug#1537 : height and width aren't refreshed on re-save + icon_height = models.IntegerField(_('icon height'), blank = True, null=True,) + icon_width = models.IntegerField(_('icon width'), blank = True, null=True, ) + + + + class Meta: + verbose_name = _('link category') + verbose_name_plural = _('link categories') + ordering = ['priority'] + class Admin: + fields = ( + (None, {'fields': ('name', 'description_markup', 'priority',),}), + (_('Advanced'), { + 'fields': ('permalink', 'pub_date', 'icon',), + 'classes': 'collapse', + } ), + ) + list_display = ('name', 'priority',) + + + def __str__ (self): + return self.name + + def save (self): + parse_markup (self) + super(LinkCategory, self).save() + + #def get_absolute_url (self): + #pass + + + + +class LinksPerCategory (models.Manager): + def get_query_set (self): + return super(LinksPerCategory, self).get_query_set().order_by('category', 'pub_date',) + + +class Link (models.Model): + """Link (url, name, description) with metadata: category, tags, and source.""" + name = models.CharField (_('name'), maxlength=200, ) + url = models.URLField (_('url'), verify_exists=False) + + description = models.TextField (_('description'), editable=False,) + description_markup = models.TextField (_('description'), + blank=True, + help_text = markup_help['docutils'] + ) + + category = models.ForeignKey ( LinkCategory, + verbose_name=_('category'), + blank = True, + ) + + via_name = models.CharField ( _('via (name)'), + maxlength=200, + blank=True, + help_text = 'Source of the link. Brief description.', + ) + via_url = models.URLField (_('via (url)'), verify_exists=False, + blank=True, + help_text = 'Source of the link. URL.' + ) + + pub_date = models.DateTimeField (_('publication date'), auto_now=True,) + permalink = models.SlugField (_('permalink'), + prepopulate_from = ('name',), + unique = True, + ) + + tags = fields.TagsField(Tag, + blank = True, + ) + + objects = models.Manager() + categorized = LinksPerCategory() + + class Meta: + verbose_name = _('link') + verbose_name_plural = _('links') + order_with_respect_to = 'category' + ordering = ['pub_date'] + + class Admin: + list_display = ('name', 'url', 'pub_date',) + list_filter = ('category',) + search_fields = ('name',) + fields = ( + (None, {'fields': ( ('name', 'category',), 'url', + 'description_markup', 'tags', 'via_name', 'via_url',),}), + (_('Advanced'), {'fields': ('permalink','pub_date',), + 'classes': 'collapse',}), + ) + + def __str__ (self): + return self.name + + def save (self): + parse_markup (self) + super(Link, self).save() + + #def get_absolute_url (self): + #pass + diff --git a/links/templates/links/link_list.html b/links/templates/links/link_list.html new file mode 100644 index 0000000..27d28e5 --- /dev/null +++ b/links/templates/links/link_list.html @@ -0,0 +1,31 @@ +{% extends "base.html" %} + +{% block content %} + +{% regroup object_list by category as grouped %} + + +{% endblock %} diff --git a/links/urls.py b/links/urls.py new file mode 100644 index 0000000..73be344 --- /dev/null +++ b/links/urls.py @@ -0,0 +1,14 @@ +from django.conf.urls.defaults import * +from uecweb.links.models import Link + +link_dict = { 'queryset': Link.categorized.all() } +#link_dict_permalink = dict(link_dict, slug_field='permalink') +#categ_dict = {'queryset': LinkCategory.objects.all() } +#categ_dict_slug = dict(categ_dict, slug_field='permalink') + +urlpatterns = patterns('django.views.generic.list_detail', + (r'^$', 'object_list', link_dict), + #(r'^(?P[\w-]+)/$', 'object_detail', categ_dict_slug), + #(r'^[\w-]+/(?P[\w-]+)/$', 'object_detail', link_dict_slug), +) + diff --git a/links/views.py b/links/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/links/views.py @@ -0,0 +1 @@ +# Create your views here.