Changeset 162

Show
Ignore:
Timestamp:
10/14/07 18:47:20 (2 years ago)
Author:
mksoft
Message:

Fixes for unicode branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/apps/accounts/forms.py

    r154 r162  
    11from django import newforms as forms 
    22from models import ATTRIBUTE_CHOICES 
    3 from django.utils.translation import gettext as _ 
     3from django.utils.translation import ugettext as _ 
    44 
    55class AttributeForm(forms.Form): 
  • trunk/apps/accounts/models.py

    r152 r162  
    11from django.db import models 
    22from django.contrib.auth.models import User 
    3 from django.utils.translation import gettext_lazy as _ 
     3from django.utils.translation import ugettext_lazy as _ 
    44 
    55class Profile(models.Model): 
  • trunk/apps/blogs/feeds.py

    r127 r162  
    2323from lahak.vertical.tags.models import TaggedItem 
    2424from lahak.vertical.core.feeds import LahakFeed 
    25  
     25from django.utils.translation import ugettext as _ 
    2626 
    2727class LatestEntries(LahakFeed): 
    2828    """Syndication for all the blogs""" 
    2929 
    30     title = (_("%s's blogs") % LahakFeed.site_name).decode('utf-8') 
     30    title = _("%s's blogs") % LahakFeed.site_name 
    3131    link = BLOGS_ROOT 
    32     description = (_("Updates from all the blogs at %s") % LahakFeed.site_name).decode('utf-8') 
     32    description = _("Updates from all the blogs at %s") % LahakFeed.site_name 
    3333 
    3434    title_template = 'blogs/feed_all_title.html' 
     
    3636 
    3737    def items(self): 
    38         "for this item we need a different __str__ which includes the blog name" 
     38        "for this item we need to include the blog name" 
    3939        return Entry.objects.filter(publish=True).order_by('-updated')[:10] 
    4040 
     
    5757 
    5858    def title(self, obj): 
    59         return obj.get_blog_title().decode('utf-8') 
     59        return obj.get_blog_title() 
    6060 
    6161    def description(self,obj): 
    6262        desc = _("Updates from %(name)s's blog at %(site)s") % \ 
    6363            {'name':obj.author.username, 'site':self.site_name } 
    64         return desc.decode('utf-8') 
     64        return desc 
    6565 
    6666    def link(self, obj): 
  • trunk/apps/blogs/models.py

    r149 r162  
    2424from django.core.validators import isSlug, isInteger, ValidationError 
    2525from django.shortcuts import get_object_or_404 
     26from django.utils.translation import ugettext_lazy as _ 
    2627 
    2728class BlogManager(models.Manager): 
     
    6566            blog_id = self.id 
    6667 
    67         return "%s%s/" % (BLOGS_ROOT, blog_id) 
     68        return u"%s%s/" % (BLOGS_ROOT, blog_id) 
    6869 
    69     def __str__(self): 
     70    def __unicode__(self): 
    7071        return self.get_blog_title() 
    7172 
     
    124125        return crumbs 
    125126 
    126     def __str__(self): 
     127    def __unicode__(self): 
    127128        return self.title 
    128129 
  • trunk/apps/doc/feeds.py

    r127 r162  
    2525from lahak.vertical.core.feeds import LahakFeed, LahakChangeLogFeed 
    2626from settings import DOC_ROOT 
     27from django.utils.translation import ugettext as _ 
    2728 
    2829class AllLatestUpdates(LahakChangeLogFeed): 
     
    3031 
    3132    link = '%smeta/changes' % DOC_ROOT 
    32     title = ( _('Documents updates at %s') % LahakFeed.site_name ).decode('utf-8') 
    33     description = ( _('Updates to all the documents at %s') % LahakFeed.site_name).decode('utf-8') 
     33    title = _('Documents updates at %s') % LahakFeed.site_name 
     34    description = _('Updates to all the documents at %s') % LahakFeed.site_name 
    3435 
    3536    title_template = 'doc/doc_all_title.html' 
     
    4243class NewDocuments(LahakChangeLogFeed): 
    4344 
    44     title = (_("New documents at %s") % LahakFeed.site_name).decode('utf-8') 
    45     description = (_("Newly created documents at %s") % LahakFeed.site_name).decode('utf-8') 
     45    title = _("New documents at %s") % LahakFeed.site_name 
     46    description = _("Newly created documents at %s") % LahakFeed.site_name 
    4647    link = DOC_ROOT 
    4748 
     
    5960 
    6061    def title(self, obj): 
    61         return (_('%s updates') % obj.title).decode('utf-8') 
     62        return _('%s updates') % obj.title 
    6263 
    6364    def description(self, obj): 
    6465        d = { 'title': obj.title, 'site':self.site_name } 
    65         return (_('Updates to document %(title)s at %(site)s') % d).decode('utf-8') 
     66        return _('Updates to document %(title)s at %(site)s') % d 
    6667 
    6768    def get_object(self, bits): 
  • trunk/apps/doc/models.py

    r149 r162  
    2020 
    2121from django.db import models 
    22 from django.utils.translation import gettext_lazy 
     22from django.utils.translation import ugettext_lazy as _ 
    2323from settings import DOC_ROOT, DOC_BREADCRUMB_ROOT 
    2424 
     
    6565        return crumbs 
    6666 
    67     def __str__(self): 
     67    def __unicode__(self): 
    6868        return self.title 
    6969 
  • trunk/apps/doc/templates/doc/doc_base.html

    r127 r162  
    1 {% load i18n lahak_comments %}{% extends "site_with_sidebar.html" %} 
     1{% load i18n lahak_comments lahak_general %}{% extends "site_with_sidebar.html" %} 
    22{% block extra_head %} 
    33    <link rel="alternate" type="application/rss+xml" title="{% trans "All documents" %}" href="/doc/meta/feeds/all/"/>     
     
    2323            <ul> 
    2424                <li><a href="{{ vertical_object.get_absolute_url}}edit/">{% trans "Edit" %}</a></li> 
     25                {% if user.is_superuser %} 
     26                    <li><a href="/objperms/edit/{% content_type_id vertical_object %}/{{ vertical_object.id}}/">{% trans "Permissions and locking" %}</a></li> 
     27                {% endif %} 
    2528            </ul> 
    2629        {% endif %} 
  • trunk/apps/doc/views.py

    r126 r162  
    2828from lahak.vertical.core.validators import DoesNotEqual 
    2929from lahak.vertical.history.models import ChangeLog 
    30  
     30from django.utils.translation import ugettext as _ 
    3131import urllib 
    3232 
     
    154154 
    155155def all_documents(request): 
    156     documents = [ (d.title.decode('utf-8'), d.get_absolute_url()) for d in Document.objects.order_by('title') ] 
     156    documents = [ (d.title, d.get_absolute_url()) for d in Document.objects.order_by('title') ] 
    157157 
    158158    context_dict = { 
     
    194194    if request.GET: 
    195195        for param in ('slug','title'): 
    196             context_dict[param] = request.GET.get(param, "") 
    197  
     196            context_dict[param] = request.GET.get(param, "").encode('utf-8') 
     197 
     198            print context_dict[param], type(context_dict[param]) 
    198199        # pass the create url to the template, we don't want to calculate it 
    199200        # there 
  • trunk/apps/forums/models.py

    r141 r162  
    2020 
    2121from django.db import models 
    22 from django.utils.translation import gettext_lazy 
     22from django.utils.translation import ugettext_lazy as _ 
    2323from lahak.vertical.core.validators import DoesNotEqual 
    2424from lahak.apps.forums.settings import FORUMS_ROOT, FORUMS_BREADCRUMB_ROOT 
     
    4141        return (FORUMS_BREADCRUMB_ROOT, (self.get_absolute_url() , self.title) ) 
    4242 
    43     def __str__(self): 
     43    def __unicode__(self): 
    4444        return self.title 
    4545 
     
    4848    slug = models.SlugField(unique=True) 
    4949    title = models.CharField(maxlength=255, unique=True) 
    50     content = models.TextField(gettext_lazy("Forum description"), blank=True, null=True) 
     50    content = models.TextField(_("Forum description"), blank=True, null=True) 
    5151    group = models.ForeignKey(ForumsGroup) 
    5252    position = models.PositiveIntegerField(default=0) 
     
    5555        return '%s%s/' % (self.group.get_absolute_url(), self.slug) 
    5656 
    57     def __str__(self): 
     57    def __unicode__(self): 
    5858        return self.title 
    5959 
  • trunk/apps/messages/models.py

    r141 r162  
    2020 
    2121from django.db import models 
    22 from django.utils.translation import gettext_lazy as _ 
     22from django.utils.translation import ugettext_lazy as _ 
    2323from django.contrib.auth.models import Group 
    2424 
     
    5151        search_fields = ('title', 'content') 
    5252 
    53     def __str__(self): 
     53    def __unicode__(self): 
    5454        from django.utils.text import truncate_words 
    5555        print truncate_words(self.content, 4) 
  • trunk/apps/pages/models.py

    r131 r162  
    2121from django.db import models 
    2222from django.core import validators 
     23from django.utils.translation import ugettext_lazy as _ 
    2324 
    2425class Page(models.Model): 
     
    3940        search_fields = ('url',) 
    4041 
    41     def __str__(self): 
     42    def __unicode__(self): 
    4243        return self.url 
    4344 
  • trunk/vertical/comments/exceptions.py

    r42 r162  
    1919# vim: set ts=4 sw=4 et: 
    2020 
     21from django.utils.translation import ugettext as _ 
     22 
    2123class ObjectNotFoundException(Exception): 
    2224    "Vertical object doesn't exist" 
     
    2527        self.msg = _("Object not found") 
    2628     
    27     def __str__(self): 
     29    def __unicode__(self): 
    2830        return repr(self.msg) 
    2931 
     
    3537        self.msg =  _("Comments not allowed for %s") % vertical_object._meta.verbose_name_plural 
    3638 
    37     def __str__(self): 
     39    def __unicode__(self): 
    3840        return repr(self.msg) 
    3941 
  • trunk/vertical/comments/models.py

    r144 r162  
    2424from django.contrib.auth.models import User 
    2525from lahak.vertical.comments.exceptions import * 
     26from django.utils.translation import ugettext_lazy as _ 
    2627 
    2728class CommentsRootManager(models.Manager): 
     
    129130        return _("Anonymous") 
    130131 
    131     def __str__(self): 
     132    def __unicode__(self): 
    132133        return self.title 
    133134 
  • trunk/vertical/core/media/css/style.css

    r148 r162  
    2727 
    2828.content_inner { padding: 5pt; border:1px solid #c0c0c0; margin: 5pt; background: #ffffff;min-height:350px; height: auto !important; height:300px;} 
    29  
     29.content_without_sidebar { margin-right: 50px; padding-top: 20px; min-height: 300px; } 
    3030input, textarea { border : 1px solid #6d99b6; } 
    3131input[type='checkbox'] { border: none;} 
  • trunk/vertical/core/protocols.py

    r149 r162  
    2525import re 
    2626 
    27 PROTOCOL_SYNTAX='|%s|%s|' 
     27PROTOCOL_SYNTAX=u'|%s|%s|' 
    2828 
    2929class Protocols(object): 
     
    4242                # do we have a name in the the protocol, if not, fallback to 
    4343                # verbose_name 
    44                 name = model.LahakMeta.protocol.get('name',None) or model._meta.verbose_name 
     44                name = model.LahakMeta.protocol.get('name',None) or unicode(model._meta.verbose_name) 
    4545                self.protocols[name] = model 
    46  
    47         protocol_expression = r'(\|(%s)\|\s*(.*?)\s*\|)' % '|'.join(self.protocols.keys() )  
    48         self.regexp = re.compile(protocol_expression) 
     46        protocol_expression = ur'(\|(%s)\|\s*(.*?)\s*\|)' % '|'.join(self.protocols.keys() )  
     47        self.regexp = re.compile(protocol_expression, re.UNICODE) 
    4948 
    5049    def get_protocols(self): 
     
    8887        label = get_protocol_display(obj) 
    8988 
    90         if type(label) is unicode: 
    91             label = label.encode('utf-8') 
    92  
    9389        return  PROTOCOL_SYNTAX % (name, label) 
  • trunk/vertical/core/validators.py

    r2 r162  
    1919# vim: set ts=4 sw=4 et: 
    2020 
    21 from django.utils.translation import gettext_lazy 
     21from django.utils.translation import ugettext_lazy 
    2222from django.core.validators import ValidationError 
    2323 
     
    3030    def __call__(self, field_data, all_data): 
    3131        if field_data == self.value: 
    32             raise ValidationError(gettext_lazy("This value can't be %s") % self.value) 
     32            raise ValidationError(ugettext_lazy("This value can't be %s") % self.value) 
  • trunk/vertical/history/models.py

    r144 r162  
    110110    change_type = models.CharField(maxlength=1, choices=CHANGE_TYPES, db_index=True) 
    111111    object = models.TextField() 
     112    object_dict = models.TextField() 
    112113    comment = models.CharField(maxlength=255, blank=True) 
    113114    stable = models.BooleanField(default=False) 
     
    129130        ) 
    130131 
    131         list_display = ('__str__', 'user', 'change_type','comment', 'content_type', 'change_time', ) 
     132        list_display = ('__unicode__', 'user', 'change_type','comment', 'content_type', 'change_time', ) 
    132133         
    133     def __str__(self): 
    134         return str(self.get_object()) 
     134    def __unicode__(self): 
     135        return unicode(self.get_object()) 
    135136 
    136137    def get_object(self): 
    137138        """ Returns unpickled object. """ 
    138         return Pickle.loads(self.object) 
     139        the_model = self.content_type.model_class() 
     140        return the_model(**Pickle.loads(str(self.object))) 
    139141 
    140142    def get_rev_num(self): 
     
    217219 
    218220    try:  
    219         log.object = Pickle.dumps(instance, protocol=0
     221        log.object = Pickle.dumps(instance.__dict__
    220222        log.user = get_current_user() 
    221223        log.address = get_remote_address() 
  • trunk/vertical/history/templatetags/lahak_history.py

    r72 r162  
    2323from lahak.vertical.history.models import ChangeLog 
    2424from difflib import HtmlDiff 
    25  
     25from django.utils.translation import ugettext as _ 
    2626register = template.Library() 
    2727 
  • trunk/vertical/reference/models.py

    r146 r162  
    2121from django.db import models 
    2222from django.dispatch import dispatcher 
    23 from django.utils.translation import gettext_lazy as _ 
     23from django.utils.translation import ugettext_lazy as _ 
    2424from django.contrib.contenttypes.models import ContentType 
    2525from django.contrib.contenttypes import generic 
  • trunk/vertical/rest/postprocessors.py

    r58 r162  
    2727    for tr in AdmonitionsPreProcessor.translations: 
    2828        content = content.replace( r'admonition-title">%s' % tr[1],  
    29             r'admonition-title">%s' % tr[0].decode('utf-8')
     29            r'admonition-title">%s' % tr[0]
    3030 
    3131    return content 
  • trunk/vertical/rest/preprocessors.py

    r144 r162  
    2424from django.db.models.base import ObjectDoesNotExist 
    2525import urllib, re 
     26from django.utils.translation import ugettext as _ 
    2627 
    2728class ProtocolsPreProcessor(object): 
     
    5051                new_path = the_model.LahakMeta.protocol.get('new_path', None) 
    5152                if new_path: 
    52                     content = content.replace(match[0], r"`%s <%s%s>`_" % ( match[2], new_path, urllib.quote_plus( match[2] )) ) 
     53                    content = content.replace(match[0], r"`%s <%s%s>`_" % ( match[2], new_path, urllib.quote_plus( match[2].encode('utf-8') )) ) 
    5354                else: 
    5455                    # we don't want to get stuck with the vertical bars, as 
     
    113114        # since image params are not translatable by reST, will subst them here 
    114115 
    115         # utf-8 in templates passed via filter might give us problems, so let's 
    116         # conver if needed 
    117         if type(content) is unicode: 
    118             for tr in self.translations: 
    119                 content = content.replace( ':%s:' % tr[0].decode('utf-8'), ':%s:' % tr[1]) 
    120         else: 
    121             for tr in self.translations: 
    122                 content = content.replace( ':%s:' % tr[0], ':%s:' % tr[1]) 
     116        for tr in self.translations: 
     117            content = content.replace( ':%s:' % tr[0], ':%s:' % tr[1]) 
    123118        return content 
    124119 
     
    137132     
    138133    def __call__(self, content): 
    139         # utf-8 in templates passed via filter might give us problems, so let's 
    140         # conver if needed 
    141         if type(content) is unicode: 
    142             for tr in self.translations: 
    143                 content = content.replace( ':%s:' % tr[0].decode('utf-8'), ':%s:' % tr[1]) 
    144         else: 
    145             for tr in self.translations: 
    146                 content = content.replace( '.. %s::' % tr[0], '.. admonition:: %s' % tr[1]) 
     134        for tr in self.translations: 
     135            content = content.replace( '.. %s::' % tr[0], '.. admonition:: %s' % tr[1]) 
    147136        return content 
    148137 
  • trunk/vertical/rest/templatetags/lahak_rest.py

    r158 r162  
    3232    """ Return the 1st n child elements of parse"document",  
    3333    used mainly for feeds """ 
     34 
     35    # problems with parseString and unicode, we need to encode 
     36    # it as utf-8 
    3437    processed = lahak_rest(value).encode('utf-8') 
    3538 
  • trunk/vertical/tags/models.py

    r144 r162  
    2626from settings import ROOT, BREADCRUMB_ROOT 
    2727from lahak.vertical.core.validators import DoesNotEqual 
     28from django.utils.translation import ugettext_lazy as _ 
    2829 
    2930class Tag(models.Model): 
     
    3940        return '/tags/%s/' % self.slug 
    4041 
    41     def __str__(self): 
    42         return '%s, %s' % (self.slug, self.name) 
     42    def __unicode__(self): 
     43        return u'%s, %s' % (self.slug, self.name) 
    4344 
    4445 
     
    8788    def get_tags_strings(self, item): 
    8889        "Get the tags names as a unicode string list. Usually used for feed categories" 
    89         return [tagged_item.tag.name.decode('utf8') for tagged_item in self.get_tags(item)] 
     90        return [tagged_item.tag.name for tagged_item in self.get_tags(item)] 
    9091 
    9192 
     
    101102        unique_together = ( ('tag', 'content_type', 'object_id'), ) 
    102103 
    103     def __str__(self): 
    104         return "%s, %s: %s" % (self.content_type.name, self.object_id, self.tag.slug) 
     104    def __unicode__(self): 
     105        return u"%s, %s: %s" % (self.content_type.name, self.object_id, self.tag.slug) 
    105106 
  • trunk/vertical/tags/views.py

    r157 r162  
    170170    object_tags = TaggedItem.objects.filter(content_type=ctype, object_id=int(object_id))    
    171171 
    172     current_tags = [ (tagged_item.tag.id, tagged_item.tag.slug, unicode(cgi.escape(tagged_item.tag.name),'utf-8'), urllib.quote(tagged_item.tag.get_absolute_url())) for tagged_item in object_tags ] 
     172    current_tags = [ (tagged_item.tag.id, tagged_item.tag.slug, tagged_item.tag.name, urllib.quote(tagged_item.tag.get_absolute_url())) for tagged_item in object_tags ] 
    173173 
    174174    if current_tags: 
     
    177177        query_set = Tag.objects.all() 
    178178 
    179     available_tags = [ (tag.id, tag.slug, unicode(cgi.escape(tag.name),'utf-8'), urllib.quote(tag.get_absolute_url()) ) for tag in query_set.order_by('name') ]  
     179    available_tags = [ (tag.id, tag.slug, tag.name, urllib.quote(tag.get_absolute_url()) ) for tag in query_set.order_by('name') ]  
    180180 
    181181    return HttpResponse(simplejson.dumps({'selected':current_tags, 'available':available_tags }, ensure_ascii=False)) 
  • trunk/vertical/uploads/models.py

    r144 r162  
    2222from django.contrib.contenttypes.models import ContentType 
    2323from django.contrib.contenttypes import generic 
    24 from lahak.vertical.core.db import AutoImageField 
     24from lahak.vertical.core.db import AutoImageField, AutoFileField 
    2525 
    2626class ImageManager(models.Manager): 
     
    3333 
    3434class Image(models.Model): 
    35     """Generic uploaded images module""" 
     35    """Generic uploaded images model""" 
    3636 
    3737    content_type = models.ForeignKey(ContentType) 
     
    4747    objects = ImageManager() 
    4848 
     49class Audio(models.Model): 
     50    """Generic uploaded audio model""" 
     51 
     52    content_type = models.ForeignKey(ContentType) 
     53    parent = generic.GenericForeignKey() 
     54    object_id = models.PositiveIntegerField(_('object ID')) 
     55     
     56    audio = AutoFileField( ) 
     57 
     58    comment = models.CharField(null=True,blank=True,maxlength=200)