Browse Source

- Reorganised date formats
- Included custom date and reldate filters
- Refractored way Misago follows ignored and followed users

Ralfp 12 years ago
parent
commit
62477cf71f

+ 0 - 21
misago/context_processors.py

@@ -1,30 +1,9 @@
 from django.conf import settings
-from django.utils.importlib import import_module
 from misago import get_version
 
-# Get formats
-try:
-    locale_formats = import_module('django.conf.locale.%s.formats' % settings.LANGUAGE_CODE)
-    formats = {
-               'DATE_FORMAT': locale_formats.DATE_FORMAT,
-               'TIME_FORMAT': locale_formats.TIME_FORMAT,
-               'DATETIME_FORMAT': locale_formats.DATETIME_FORMAT,
-               'SHORT_DATE_FORMAT': locale_formats.SHORT_DATE_FORMAT,
-               'SHORT_DATETIME_FORMAT': locale_formats.SHORT_DATETIME_FORMAT,
-               }
-except (ImportError, AttributeError):
-    formats = {
-               'DATE_FORMAT': settings.DATE_FORMAT,
-               'TIME_FORMAT': settings.TIME_FORMAT,
-               'DATETIME_FORMAT': settings.DATETIME_FORMAT,
-               'SHORT_DATE_FORMAT': settings.SHORT_DATE_FORMAT,
-               'SHORT_DATETIME_FORMAT': settings.SHORT_DATETIME_FORMAT,
-               }
-
 # Register context processors
 def core(request):
     return {
         'board_address': settings.BOARD_ADDRESS,
         'version': get_version(),
-        'f': formats
     }

+ 0 - 5
misago/settings_base.py

@@ -66,10 +66,6 @@ JINJA2_EXTENSIONS = (
 
 # List of application middlewares
 MIDDLEWARE_CLASSES = (
-    # Uncomment the next line for simple stopwatch
-    # Measured times will be logged in "stopwatch.txt"
-    # file located in directory containing settings.py
-    # 'misago.stopwatch.middleware.StopwatchMiddleware',
     'debug_toolbar.middleware.DebugToolbarMiddleware',
     'misago.cookie_jar.middleware.CookieJarMiddleware',
     'misago.settings.middleware.SettingsMiddleware',
@@ -95,7 +91,6 @@ INSTALLED_APPS = (
     # Applications that have no dependencies first!
     'south',
     'coffin',
-    'django.contrib.contenttypes',
     'django.contrib.staticfiles',
     'django.contrib.humanize',
     'mptt', # Modified Pre-order Tree Transversal - allows us to nest forums 

+ 52 - 6
misago/template/templatetags/django2jinja.py

@@ -1,6 +1,10 @@
+from datetime import date, datetime, timedelta
 import math
 import urllib
 from coffin.template import Library
+from django.utils.timezone import is_aware, utc
+from django.utils.translation import pgettext, ungettext, ugettext as _
+
 register = Library()
 
 @register.object(name='widthratio')
@@ -20,11 +24,53 @@ def parse_markdown(value, format="html5"):
     return markdown.markdown(value, safe_mode='escape', output_format=format)
 
 
-@register.filter(name='reldate')
-def reldate(value, format=""):
-    return 'TODO: fancydate'
+@register.filter(name='low')
+def low(value):
+    if not value:
+        return u''
+    try:
+        rest = value[1:]
+    except IndexError:
+        rest = ''
+    return '%s%s' % (unicode(value[0]).lower(), rest)
+
 
+@register.filter(name='date')
+def date(date, arg=""):
+    from django.utils.dateformat import format, time_format
+    from misago.utils import formats
+    
+    if not arg:
+        arg = formats['DATE_FORMAT']
+    elif arg in formats:
+        arg = formats[arg]
+        
+    return format(date, arg)
 
-@register.filter(name='timesince')
-def timesince(value, format=""):
-    return 'TODO: timesince'
+
+@register.filter(name='reldate')
+def reldate(date, arg=""):
+    from django.utils.dateformat import format, time_format
+    from misago.utils import formats
+    
+    now = datetime.now(utc if is_aware(date) else None)
+    diff = now - date
+    print diff
+    
+    # Common situations
+    if diff.days == 0:
+        return _("Today, %(hour)s") % {'hour': time_format(date, formats['TIME_FORMAT'])}
+    if diff.days == 1:
+        return _("Yesterday, %(hour)s") % {'hour': time_format(date, formats['TIME_FORMAT'])}
+    if diff.days == -1:
+        return _("Tomorrow, %(hour)s") % {'hour': time_format(date, formats['TIME_FORMAT'])}
+    if diff.days > -7 or diff.days < 7:
+        return _("%(day)s, %(hour)s") % {'day': format(date, 'l'), 'hour': time_format(date, formats['TIME_FORMAT'])}
+    
+    # Custom
+    if not arg:
+        arg = formats['DATE_FORMAT']
+    elif arg in formats:
+        arg = formats[arg]
+        
+    return format(date, arg)

+ 3 - 20
misago/users/models.py

@@ -133,6 +133,8 @@ class User(models.Model):
     karma_delta = models.IntegerField(default=0)
     followers = models.PositiveIntegerField(default=0)
     followers_delta = models.IntegerField(default=0)
+    follows = models.ManyToManyField('self',related_name='follows_set',symmetrical=False)
+    ignores = models.ManyToManyField('self',related_name='ignores_set',symmetrical=False)
     score = models.IntegerField(default=0,db_index=True)
     rank = models.ForeignKey('Rank',null=True,blank=True,db_index=True,on_delete=models.SET_NULL)
     title = models.CharField(max_length=255,null=True,blank=True)
@@ -501,23 +503,4 @@ class Rank(models.Model):
             except Exception as e:
                 print 'Error updating users ranking: %s' % e
             transaction.commit_unless_managed()
-        return True
-    
-    
-class Follower(models.Model):
-    """
-    Misago Users follow model
-    """
-    user = models.ForeignKey('User',related_name='+')
-    target = models.ForeignKey('User')
-    since = models.DateTimeField()
-    
-    
-class Foe(models.Model):
-    """
-    Misago Users foes model
-    """
-    user = models.ForeignKey('User')
-    target = models.ForeignKey('User',related_name='+')
-    since = models.DateTimeField()
-    
+        return True

+ 36 - 1
misago/utils/__init__.py

@@ -2,6 +2,7 @@
 Smart slugify
 """
 import django.template.defaultfilters
+
 use_unidecode = True
 try:
     from unidecode import unidecode
@@ -13,10 +14,12 @@ def slugify(string):
         string = unidecode(string)
     return django.template.defaultfilters.slugify(string)
 
+
 """
 Lazy translate that allows us to access original message
 """
 from django.utils import translation
+
 def ugettext_lazy(str):
     t = translation.ugettext_lazy(str)
     t.message = str
@@ -25,4 +28,36 @@ def get_msgid(gettext):
     try:
         return gettext.message
     except AttributeError:
-        return None
+        return None
+
+
+"""
+Date formats
+"""    
+from django.conf import settings
+from django.utils.importlib import import_module
+from misago import get_version
+
+try:
+    locale_formats = import_module('django.conf.locale.%s.formats' % settings.LANGUAGE_CODE)
+    formats = {
+               'DATE_FORMAT': locale_formats.DATE_FORMAT,
+               'TIME_FORMAT': locale_formats.TIME_FORMAT,
+               'DATETIME_FORMAT': locale_formats.DATETIME_FORMAT,
+               'SHORT_DATE_FORMAT': locale_formats.SHORT_DATE_FORMAT,
+               'SHORT_DATETIME_FORMAT': locale_formats.SHORT_DATETIME_FORMAT,
+               }
+except (ImportError, AttributeError):
+    formats = {
+               'DATE_FORMAT': settings.DATE_FORMAT,
+               'TIME_FORMAT': settings.TIME_FORMAT,
+               'DATETIME_FORMAT': settings.DATETIME_FORMAT,
+               'SHORT_DATE_FORMAT': settings.SHORT_DATE_FORMAT,
+               'SHORT_DATETIME_FORMAT': settings.SHORT_DATETIME_FORMAT,
+               }
+
+formats['DATE_FORMAT'] = unicode(formats['DATE_FORMAT'].replace('P', 'g:i a'))
+formats['TIME_FORMAT'] = unicode(formats['TIME_FORMAT'].replace('P', 'g:i a'))
+formats['DATETIME_FORMAT'] = unicode(formats['DATETIME_FORMAT'].replace('P', 'g:i a'))
+formats['SHORT_DATE_FORMAT'] = unicode(formats['SHORT_DATE_FORMAT'].replace('P', 'g:i a'))
+formats['SHORT_DATETIME_FORMAT'] = unicode(formats['SHORT_DATETIME_FORMAT'].replace('P', 'g:i a'))

+ 1 - 1
static/sora/css/sora.css

@@ -895,7 +895,7 @@ th.table-sort.sort-desc a:hover{border-bottom:3px solid #eca09a;padding-bottom:5
 .page-header h2 .avatar{width:40px;height:40px;}
 .page-header h3 .avatar{width:28px;height:28px;}
 .page-header h4 .avatar{width:22px;height:22px;}
-.header-tabbed{border-bottom:none;padding-bottom:0px;margin-bottom:0px;}.header-tabbed .nav-tabs li a:link,.header-tabbed .nav-tabs li a:active,.header-tabbed .nav-tabs li a:visited{opacity:0.6;filter:alpha(opacity=60);color:#333333;font-weight:bold;}
+.header-tabbed{border-bottom:none;padding-bottom:0px;margin-bottom:0px;}.header-tabbed .nav-tabs li a:link,.header-tabbed .nav-tabs li a:active,.header-tabbed .nav-tabs li a:visited{font-weight:bold;}
 .header-tabbed .nav-tabs li i{margin-right:4px;}
 .header-tabbed .nav-tabs li.active a:link,.header-tabbed .nav-tabs li.active a:active,.header-tabbed .nav-tabs li.active a:visited,.header-tabbed .nav-tabs li.active a:hover{background-color:#fcfcfc;}.header-tabbed .nav-tabs li.active a:link i,.header-tabbed .nav-tabs li.active a:active i,.header-tabbed .nav-tabs li.active a:visited i,.header-tabbed .nav-tabs li.active a:hover i{background-image:url("../img/glyphicons-halflings.png");}
 .header-tabbed .nav-tabs li.active a:link,.header-tabbed .nav-tabs li.active a:active,.header-tabbed .nav-tabs li.active a:visited,.header-tabbed .nav-tabs li.active a:hover,.header-tabbed .nav-tabs li a:hover{opacity:1;filter:alpha(opacity=100);}

+ 0 - 3
static/sora/css/sora/navs.less

@@ -7,9 +7,6 @@
 
   .nav-tabs li {
     a:link, a:active, a:visited {
-      .opacity(60);
-      
-      color: @textColor;
       font-weight: bold;
     }
     

+ 1 - 1
templates/admin/banning/list.html

@@ -12,6 +12,6 @@
   	{%- endif %}</span>
   </td>
   <td>
-  	{% if item.expires %}{{ item.expires|date(f.DATE_FORMAT) }}{% else %}<em>{% trans %}Permanent ban{% endtrans %}</em>{% endif %}
+  	{% if item.expires %}{{ item.expires|date }}{% else %}<em>{% trans %}Permanent ban{% endtrans %}</em>{% endif %}
   </td>
 {% endblock%}

+ 2 - 2
templates/admin/sessions/list.html

@@ -19,9 +19,9 @@
   	<div class="muted"><strong>{{ item.ip }}</strong>; {{ item.agent }}</div>
   </td>
   <td>
-  	{{ item.start|date(f.DATETIME_FORMAT) }}
+  	{{ item.start|date("DATETIME_FORMAT") }}
   </td>
   <td>
-  	{{ item.last|date(f.TIME_FORMAT) }}
+  	{{ item.last|date("TIME_FORMAT") }}
   </td>
 {% endblock %}

+ 1 - 1
templates/sora/error403_banned.html

@@ -27,7 +27,7 @@
     {% endif %}
     {% endif %}
     {% if ban.expires %}
-    <p>{% trans ban_expires=ban.expires|date(f.DATE_FORMAT) %}Your ban will expire on {{ ban_expires }}{% endtrans %}</p>
+    <p>{% trans ban_expires=ban.expires|date %}Your ban will expire on {{ ban_expires }}{% endtrans %}</p>
     {% endif %}
     <ul class="unstyled">
       <li><i class="icon-home"></i> <a href="{% url 'index' %}">{% trans %}Return to board index{% endtrans %}</a></li>

+ 1 - 1
templates/sora/signin.html

@@ -19,7 +19,7 @@
 	    <p class="protip"><a href="{% url 'forgot_password' %}">{% trans %}Click here if you forgot your sign in credentials.{% endtrans %}</a></p>{% endif %}{% if not_active %}
 	    <p class="protip"><a href="{% url 'send_activation' %}">{% trans %}Click here if you didn't receive activation e-mail.{% endtrans %}</a></p>{% endif %}{% if banned_account.reason_user %}
 	    {{ banned_account.reason_user|markdown|safe }}{% endif %}{% if banned_account.expires %}
-        <p class="protip">{% trans ban_expires=banned_account.expires|date(f.DATE_FORMAT) %}Your ban will expire on {{ ban_expires }}{% endtrans %}</p>{% endif %}
+        <p class="protip">{% trans ban_expires=banned_account.expires|date %}Your ban will expire on {{ ban_expires }}{% endtrans %}</p>{% endif %}
 	  </div>{% endif %}
 	  <form class="form-horizontal" action="{% url 'sign_in' %}" method="post">
 	    <div class="form-container">

+ 2 - 2
templates/sora/users/profile.html

@@ -12,8 +12,8 @@
   <div class="avatar-height">
     <img src="{{ profile.get_avatar() }}" class="avatar pull-left" alt="{% trans %}Member Avatar{% endtrans %}" title="{% trans %}Member Avatar{% endtrans %}">
     <div class="pull-left">
-      <h1>{{ profile.username }} <small>{% trans last_visit=profile.last_date|naturaltime %}Last seen {{ last_visit }}{% endtrans %}</small></h1>
-      <p class="lead">{% if profile.title %}{{ _(profile.title) }}{% elif profile.rank.title %}{{ _(profile.rank.title) }}{% endif %}, <span class="muted">{% trans joined=profile.join_date|date(f.DATE_FORMAT) %}Member since {{ joined }}{% endtrans %}</span></p>
+      <h1>{{ profile.username }} <small>{% trans last_visit=profile.last_date|reldate|low %}Last seen {{ last_visit }}{% endtrans %}</small></h1>
+      <p class="lead">{% if profile.title or profile.rank.title %}{% if profile.title %}{{ _(profile.title) }}{% elif profile.rank.title %}{{ _(profile.rank.title) }}{% endif %}; {% endif %}<span class="muted">{% trans joined=profile.join_date|reldate|low %}Member since {{ joined }}{% endtrans %}</span></p>
     </div>
   </div>	
   <ul class="nav nav-tabs">

+ 1 - 0
templates/sora/users/usercp/options.html

@@ -1,6 +1,7 @@
 {% extends "sora/users/usercp/usercp.html" %}
 {% load i18n %}
 {% load url from future %}
+{% import "_forms.html" as form_theme %}
 {% import "sora/macros.html" as macros with context %}
 
 {% block title %}{{ macros.page_title(title=_('Change Forum Options')) }}{% endblock %}