comparison MoinMoin/themes/__init__.py @ 2651:2003e3685733

Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
author Ajitesh Gupta <ajgupta93@gmail.com>
date Thu, 26 Jun 2014 04:09:07 +0530
parents 92a9c6ef1ec7
children 2a50e6628a16 7798855349f6
comparison
equal deleted inserted replaced
2650:4385775cf3a1 2651:2003e3685733
21 logging = log.getLogger(__name__) 21 logging = log.getLogger(__name__)
22 22
23 from MoinMoin.i18n import _, L_, N_ 23 from MoinMoin.i18n import _, L_, N_
24 from MoinMoin import wikiutil, user 24 from MoinMoin import wikiutil, user
25 from MoinMoin.constants.keys import USERID, ADDRESS, HOSTNAME, REVID, ITEMID, NAME_EXACT 25 from MoinMoin.constants.keys import USERID, ADDRESS, HOSTNAME, REVID, ITEMID, NAME_EXACT
26 from MoinMoin.constants.contenttypes import CONTENTTYPES_MAP
26 from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT, NAMESPACE_USERPROFILES, NAMESPACE_ALL 27 from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT, NAMESPACE_USERPROFILES, NAMESPACE_ALL
27 from MoinMoin.search import SearchForm 28 from MoinMoin.search import SearchForm
28 from MoinMoin.util.interwiki import split_interwiki, getInterwikiHome, is_local_wiki, is_known_wiki, url_for_item, CompositeName, split_fqname 29 from MoinMoin.util.interwiki import split_interwiki, getInterwikiHome, is_local_wiki, is_known_wiki, url_for_item, CompositeName, split_fqname, get_fqname
29 from MoinMoin.util.crypto import cache_key 30 from MoinMoin.util.crypto import cache_key
30 from MoinMoin.util.forms import make_generator 31 from MoinMoin.util.forms import make_generator
31 from MoinMoin.util.clock import timed 32 from MoinMoin.util.clock import timed
32 from MoinMoin.util.mime import Type 33 from MoinMoin.util.mime import Type
33 34
571 CONTENTTYPE_SHORTEN = { 572 CONTENTTYPE_SHORTEN = {
572 'text/x.moin.wiki': 'MoinWiki', 573 'text/x.moin.wiki': 'MoinWiki',
573 } 574 }
574 575
575 576
576 # TODO: Update dictionary with more content-types
577 def shorten_content_type(contenttype):
578 """
579 Shorten content-types
580
581 Shortens the content-type to terms that normal users understand.
582
583 :param name: contenttype, unicode
584 :rtype: unicode
585 :returns: shortened version of contenttype
586 """
587 ctype = contenttype.split(';')[0]
588 if ctype in CONTENTTYPE_SHORTEN:
589 return CONTENTTYPE_SHORTEN[ctype]
590 else:
591 return "Unknown"
592
593
594 def shorten_id(name, length=7): 577 def shorten_id(name, length=7):
595 """ 578 """
596 Shorten IDs to specified length 579 Shorten IDs to specified length
597 580
598 Shorten long IDs into just the first <length> characters. There's 581 Shorten long IDs into just the first <length> characters. There's
637 """ 620 """
638 from calendar import timegm 621 from calendar import timegm
639 return timegm(dt.timetuple()) 622 return timegm(dt.timetuple())
640 623
641 624
625 def shorten_ctype(contenttype):
626 """
627 Returns user understandable terms for contenttype.
628
629 :param contenttype: contains the long form of the contenttype
630 :rtype: unicode
631 :returns: user understandable version of contenttype
632 """
633 return CONTENTTYPES_MAP.get(contenttype, "Unknown")
634
635
642 def setup_jinja_env(): 636 def setup_jinja_env():
643 app.jinja_env.filters['shorten_fqname'] = shorten_fqname 637 app.jinja_env.filters['shorten_fqname'] = shorten_fqname
644 app.jinja_env.filters['shorten_item_name'] = shorten_item_name 638 app.jinja_env.filters['shorten_item_name'] = shorten_item_name
645 app.jinja_env.filters['shorten_id'] = shorten_id 639 app.jinja_env.filters['shorten_id'] = shorten_id
646 app.jinja_env.filters['contenttype_to_class'] = contenttype_to_class 640 app.jinja_env.filters['contenttype_to_class'] = contenttype_to_class
647 app.jinja_env.filters['json_dumps'] = dumps 641 app.jinja_env.filters['json_dumps'] = dumps
648 app.jinja_env.filters['shorten_ctype'] = shorten_content_type 642 app.jinja_env.filters['shorten_ctype'] = shorten_ctype
649 # please note that these filters are installed by flask-babel: 643 # please note that these filters are installed by flask-babel:
650 # datetimeformat, dateformat, timeformat, timedeltaformat 644 # datetimeformat, dateformat, timeformat, timedeltaformat
651 645
652 app.jinja_env.globals.update({ 646 app.jinja_env.globals.update({
653 # please note that flask-babel/jinja2.ext installs: 647 # please note that flask-babel/jinja2.ext installs:
662 'storage': flaskg.storage, 656 'storage': flaskg.storage,
663 'clock': flaskg.clock, 657 'clock': flaskg.clock,
664 'cfg': app.cfg, 658 'cfg': app.cfg,
665 'item_name': u'@NONAMEGIVEN', # XXX can we just use u'' ? 659 'item_name': u'@NONAMEGIVEN', # XXX can we just use u'' ?
666 'url_for_item': url_for_item, 660 'url_for_item': url_for_item,
661 'get_fqname': get_fqname,
667 'get_editor_info': lambda meta: get_editor_info(meta), 662 'get_editor_info': lambda meta: get_editor_info(meta),
668 'utctimestamp': lambda dt: utctimestamp(dt), 663 'utctimestamp': lambda dt: utctimestamp(dt),
669 'gen': make_generator(), 664 'gen': make_generator(),
670 'search_form': SearchForm.from_defaults(), 665 'search_form': SearchForm.from_defaults(),
671 }) 666 })