Commits

Audrius Kažukauskas committed 2675d2b

Sort tags in case insensitive order

Comments (0)

Files changed (6)

beancounter/model.py

     date = Column(Date, nullable=False)
     note = Column(Unicode(255))
     tags = relationship('Tag', secondary=entries_tags_table,
-                        order_by='Tag.name', backref='entries')
+                        order_by=lambda: func.lower(Tag.name),
+                        backref='entries')
 
     def __repr__(self):     # pragma: no cover
         return '<Entry(%r, %r, %r)>' % (self.id, self.amount, self.date)

beancounter/static/js/entries.js

     },
 
     renderTags: function () {
-        var tags = this.model.get('tags').map(function (id) {
+        var tags = _.chain(this.model.get('tags')).map(function (id) {
             return B.tags.get(id).get('name');
-        }).sort();
+        }).sortBy(function (item) {
+            return item.toLowerCase();
+        }).value();
         this.$('td.tags div')
             .text(tags.join(', '))
             // Firefox ignores line ends in title attribute.
                 _.include(entry.tags, tag.id)
             ];
         }).sortBy(function (item) {
-            return item[1];
+            return item[1].toLowerCase();
         }).value();
         this.$('div.multiselect-tags').multiselect(tags, {
             notSelectedText:  '(no tags selected)',
         var tags = B.tags.chain().map(function (tag) {
             return [tag.id, tag.get('name')];
         }).sortBy(function (item) {
-            return item[1];
+            return item[1].toLowerCase();
         }).value();
         this.$('div.multiselect-tags').multiselect('update', tags);
     }

beancounter/static/js/lib.js

         this.$('tbody td').filter(function () {
             return $(this).index() === thIndex;
         }).sortElements(function (a, b) {
-            return $.text([a]) > $.text([b]) ? 1 : -1;
+            return $.text([a]).toLowerCase() > $.text([b]).toLowerCase()
+                ? 1 : -1;
         }, function () {
             return this.parentNode;
         });

beancounter/views/charts.py

     ).outerjoin(Entry.tags).filter(
         (extract('year', Entry.date) == d.year) &
         (extract('month', Entry.date) == d.month)
-    ).group_by(Tag.name).order_by(Tag.name)
+    ).group_by(Tag.name).order_by(func.lower(Tag.name))
     series = [(t or '(no tag)', '%.2f' % s) for t, s in query]
     return jsonify(series=series)
 

beancounter/views/main.py

 from datetime import date
 
 from flask import Blueprint, render_template, abort
+from sqlalchemy import func
 
 from beancounter.model import Entry, Tag
 
             abort(400)
     entries = [e.to_json() for e in Entry.query_month(d)]
     total = '%.2f' % (Entry.month_total(d) or 0)
-    tags = [t.to_json() for t in Tag.query.order_by(Tag.name)]
+    tags = [t.to_json() for t in Tag.query.order_by(func.lower(Tag.name))]
     return render_template('main.jinja',
                            date=str(d),
                            entries=entries,

beancounter/views/tags.py

 # This file is part of BeanCounter and is released under
 # the ISC license, see LICENSE for more details.
 
-from sqlalchemy import exists
+from sqlalchemy import exists, func
 from sqlalchemy.exc import IntegrityError
 from sqlalchemy.orm.exc import NoResultFound
 from colander import Invalid
 class TagView(MethodView):
     def get(self):
         """Return a list of tags."""
-        tags = [t.to_json() for t in Tag.query.order_by(Tag.name)]
+        tags = [t.to_json() for t in Tag.query.order_by(func.lower(Tag.name))]
         return jsonify(tags=tags)
 
     def post(self):