Changeset 917

Show
Ignore:
Timestamp:
Sat Mar 18 22:53:24 2006
Author:
anonymous
Message:

增加tag初步

Files:

Legend:

Unmodified
Added
Removed
Modified
  • zqlib/tangle/limodou/blog/trunk/blog/utils/forms.py

    r831 r917  
    1   from django import forms  
      1 from django.forms import TextField  
    1 1 from django.core import validators  
    2 2 from django.core.exceptions import ObjectDoesNotExist  
    5 5 from django.utils.text import capfirst  
    6 6 from django.utils.html import escape  
    7   from django.template.defaultfilters import slugify  
    8 7  
    9 8 from django.utils.translation import gettext, gettext_lazy, ngettext  
    10 9  
    11   class TagField(forms.FormField):  
      10 class TagField(TextField):  
    11 10     input_type = "text"  
    12 11     def __init__(self, field_name, choices=[], length=40, maxlength=None, is_required=False, validator_list=[], member_name=None):  
    13 12         # choices is a list of (value, human-readable key) tuples because order matters  
    14 13         self.choices = choices  
      14          
    15 15         self.field_name = field_name  
    16 16         self.length, self.maxlength = length, maxlength  
  • zqlib/tangle/limodou/blog/trunk/blog/apps/profile/manipulator.py

    r916 r917  
    1 1 from django.utils.translation import gettext_lazy as _  
      2 from django.db.models import ObjectDoesNotExist  
    2 3 from apps.woodlog.models import Category, Entry  
      4 from public.apps.tags.models import Tag  
    3 5 from public.apps.easyform import *  
    4   from utils.forms import TagField  
    5 6 import datetime  
    6 7  
     
    39 40              
    40 41         fields.extend([  
    41               dict(type='TagField', verbose_name=_('Tags:'), field_name="tags", length=30, maxlength=100),  
      42             dict(type='TextField', verbose_name=_('Tags:'), field_name="tags", length=40, maxlength=100),  
    41 42             dict(type='CheckboxSelectMultipleField', verbose_name=_('Categories:'), field_name="categories", choices=categories),  
    42 43         ])  
    43 44          
    44           self.init(fields, extra_field_types={'TagField':TagField})  
      45         self.init(fields)  
    44 45          
    45 46     def save(self, data):  
    46   #        tag_ids = data.getlist('tags')  
    47   #        tags = Tag.objects.filter(id__in=tag_ids)  
    48   #        categories_ids = data.getlist('tags')  
    49 47         if not data['summary']:  
    50 48             summary = data['body']  
    77 75             category = Category.objects.get(pk=int(c))  
    78 76             obj.categories.add(category)  
    79            
    80   #        for tag in tags:  
    81   #            obj.tags.add(tag)  
    82            
      77              
      78         tag_names = data['tags'].split()  
      79         tags = []  
      80         for t in tag_names:  
      81             try:  
      82                 o = Tag.objects.get(name=t)  
      83             except ObjectDoesNotExist:  
      84                 o = Tag(name=t)  
      85                 o.save()  
      86             tags.append(o)  
      87         obj.tags.clear()  
      88         for t in tags:  
      89             obj.tags.add(t)  
    83 90          
    84 91 class CategoryManipulator(EasyManipulator):  
  • zqlib/tangle/limodou/blog/trunk/blog/apps/profile/views.py

    r894 r917  
    90 90             data = get_model_data(obj)  
    91 91             data['categories'] = [i['id'] for i in obj.categories.values('id')]  
      92             tags = obj.tags.values('name')  
      93             d = []  
      94             for i in tags:  
      95                 d.append(i['name'])  
      96             d.sort()  
      97             data['tags'] = ' '.join(d)  
    92 98      
    93 99     form = m.form(data=data, errors=errors, path=request.path)  
  • zqlib/tangle/limodou/blog/trunk/blog/apps/woodlog/models.py

    r916 r917  
    4 4 from public.apps.tags.models import Tag  
    5 5 from public.apps.comment.models import Comment  
    6   from utils.models import TagField  
    7 6  
    8 7 class Template(models.Model):  
    43 42 class Entry(models.Model):  
    44 43     title = models.CharField(_('Title'), maxlength=100)  
    45       tags = TagField(Tag, blank=True, verbose_name=_('Tags'), help_text=_(","))  
      44     tags = models.ManyToManyField(Tag, blank=True, verbose_name=_('Tags'))  
    45 44     body = models.TextField(_('Body'))  
    46 45     summary = models.TextField(_('Summary'), blank=True)  
  • zqlib/tangle/limodou/blog/trunk/blog/apps/woodlog/templates/woodlog/detail.html

    r908 r917  
    1 1 {% extends "woodlog/base" %}  
    2   {% load i18n blogtags %}  
      2 {% load i18n blogtags config %}  
    2 2 {% block content %}  
    3 3 <div class="entry">  
    4 4 {% include "woodlog/entry" %}  
    5   <div>{% trans "Tags:" %}{% for tag in object.tags.all %}<a href="/{{ blog_id }}/tags/{{ tag.title }}">{{ tag.title }}</a>{% endfor %}</div>  
    6   <p class="post-info"><a href="{{ object.url }}#comment_add">{% trans "Add Comment" %}</a> {% trans "Categories:" %}{% for category in object.categories.all %}<a href="categories/{{ category.title }}">{{ category.title }}</a> {% endfor %}</p>  
      5 <div>{% trans "Tags:" %}{% for tag in object.tags.all %}<a href="{% get_app_root "tags" %}/{{ tag.name }}">{{ tag.name }}</a>{% endfor %}</div>  
      6 <p class="post-info"><a href="{{ object.url }}#comment_add">{% trans "Add Comment" %}</a> {% trans "Categories:" %}{% for category in object.categories.all %}<a href="{{ blog_id }}/categories/{{ category.name }}">{{ category.name }}</a> {% endfor %}</p>  
    7 7 </div>  
    8 8  
  • zqlib/tangle/limodou/blog/trunk/blog/settings.py

    r916 r917  
    99 99  
    100 100 HOST_URL = {'main':'http://localhost:8000'}  
    101   APP_ROOT = {'blog':'blog', 'setting':'setting'}  
      101 APP_ROOT = {'blog':'blog', 'setting':'setting', 'tags':'tags'}  
    101 101 MODEL_NAMES = {'blog':('woodlog', 'Entry')}  
  • zqlib/tangle/limodou/blog/trunk/blog/public/apps/tags/models.py

    r849 r917  
    3 3 class Tag(models.Model):  
    4 4     name = models.CharField(_('Name'), maxlength=100)  
    5       visible = models.BooleanField(_('is visible'), db_index=True)  
      5     visible = models.BooleanField(_('is visible'), db_index=True, default=True)  
    5 5      
    6 6     def __repr__(self):  
    9 9  
    10 10     def url(self):  
    11           return '/tags/' + self.name  
      11         return self.name  
    11 11      
    12 12     class Meta: