Commit 2d242e83 authored by Sandrine Ribeau's avatar Sandrine Ribeau
Browse files

initial backport

parents
include *.py
recursive-include data external_resources *.gif
recursive-include i18n *.pot *.po
recursive-include migration *.py
"""package __init__"""
# pylint: disable-msg=W0622
"""erudi-basket packaging information"""
distname = "erudi-basket"
numversion = (1, 0, 3)
version = '.'.join(str(num) for num in numversion)
license = 'LCL'
copyright = '''Copyright (c) 2003-2008 LOGILAB S.A. (Paris, FRANCE).
http://www.logilab.fr/ -- mailto:contact@logilab.fr'''
author = "Logilab"
author_email = "contact@logilab.fr"
web = ''
short_desc = "Basket support for the Erudi framework"
long_desc = """Erudi is a entities / relations bases knowledge management system
developped at Logilab.
.
This package provides baskets as a way to select content in erudi applications.
.
"""
from os import listdir
from os.path import join
TEMPLATES_DIR = join('share', 'erudi', 'templates')
try:
data_files = [
[join(TEMPLATES_DIR, 'basket'),
[fname for fname in listdir('.')
if fname.endswith('.py') and fname != 'setup.py']],
[join(TEMPLATES_DIR, 'basket', 'data'),
[join('data', fname) for fname in listdir('data')]],
[join(TEMPLATES_DIR, 'basket', 'i18n'),
[join('i18n', fname) for fname in listdir('i18n')]],
[join(TEMPLATES_DIR, 'basket', 'migration'),
[join('migration', fname) for fname in listdir('migration')]],
]
except OSError, ex:
# we are in an installed directory
pass
template_eid = 20279
# used packages
__use__ = ()
# erudi-basket i18n catalog
# Copyright 2003-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# Logilab <contact@logilab.fr>
msgid ""
msgstr ""
"Project-Id-Version: erudi-basket 0.1.0\n"
"PO-Revision-Date: 2008-02-15 10:35+0100\n"
"Last-Translator: Logilab Team <contact@logilab.fr>\n"
"Language-Team: en <contact@logilab.fr>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
# #-#-#-#-# schema.pot #-#-#-#-#
# schema pot file, generated on 2007-09-28 17:10:17
#
# singular and plural forms for each entity type
msgid "Basket"
msgstr ""
#, python-format
msgid "Basket %s emptied"
msgstr ""
msgid "Basket_plural"
msgstr "Baskets"
msgid "New Basket"
msgstr "New basket"
msgid "This Basket"
msgstr "This basket"
msgid "a basket contains a set of other entities"
msgstr ""
msgid "actions_select_basket_content"
msgstr "select basket content"
# add related box generated message
msgid "actions_select_basket_content_description"
msgstr ""
msgid "add a Basket"
msgstr ""
msgid "add to basket"
msgstr ""
msgid "basket"
msgstr ""
msgid "boxes_basket_box"
msgstr "basket box"
msgid "boxes_basket_box_description"
msgstr "box to handle baskets"
msgid "create basket"
msgstr ""
# subject and object forms for each relation type
# (no object form for final relation types)
msgid "in_basket"
msgstr "in basket"
msgid "in_basket_object"
msgstr "contains"
msgid "items in this basket"
msgstr ""
msgid "nothing in basket"
msgstr ""
msgid "remove this Basket"
msgstr ""
msgid "reset basket"
msgstr ""
msgid "selection added to basket"
msgstr ""
msgid "view basket"
msgstr ""
# erudi-basket i18n catalog
# Copyright 2003-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# Logilab <contact@logilab.fr>
msgid ""
msgstr ""
"Project-Id-Version: erudi-basket 0.1.0\n"
"PO-Revision-Date: 2008-02-15 10:34+0100\n"
"Last-Translator: Logilab Team <contact@logilab.fr>\n"
"Language-Team: fr <contact@logilab.fr>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
# #-#-#-#-# schema.pot #-#-#-#-#
# schema pot file, generated on 2007-09-28 17:10:17
#
# singular and plural forms for each entity type
msgid "Basket"
msgstr "Panier"
#, python-format
msgid "Basket %s emptied"
msgstr "panier %s vidé"
msgid "Basket_plural"
msgstr "Paniers"
msgid "New Basket"
msgstr "Nouveau panier"
msgid "This Basket"
msgstr "Ce panier"
msgid "a basket contains a set of other entities"
msgstr "un panier contient un ensemble d'entités"
msgid "actions_select_basket_content"
msgstr "séléctionner le contenu du panier"
# add related box generated message
msgid "actions_select_basket_content_description"
msgstr ""
msgid "add a Basket"
msgstr "ajouter un panier"
msgid "add to basket"
msgstr "ajouter au panier"
msgid "basket"
msgstr "panier"
msgid "boxes_basket_box"
msgstr "boîte panier"
msgid "boxes_basket_box_description"
msgstr "boîte de gestion de paniers"
msgid "create basket"
msgstr "créer un panier"
# subject and object forms for each relation type
# (no object form for final relation types)
msgid "in_basket"
msgstr "dans le panier"
msgid "in_basket_object"
msgstr "contenu par"
msgid "items in this basket"
msgstr "entités dans ce panier"
msgid "nothing in basket"
msgstr "panier vide"
msgid "remove this Basket"
msgstr "supprimer ce panier"
msgid "reset basket"
msgstr "vider le panier"
msgid "selection added to basket"
msgstr "séléction ajoutée au panier"
msgid "view basket"
msgstr "voir le panier"
# postcreate script. You could setup a workflow here for example
from ginco.common.schema import format_constraint
class Basket(MetaUserEntityType):
"""a basket contains a set of other entities"""
permissions = {
'read': ('managers', ERQLExpression('X owned_by U'),),
'add': ('managers', 'users',),
'delete': ('managers', 'owners',),
'update': ('managers', 'owners',),
}
name = String(required=True, indexed=True, internationalizable=True,
maxsize=128)
description_format = String(meta=True, internationalizable=True, maxsize=50,
default='text/rest', constraints=[format_constraint])
description = String(fulltextindexed=True)
in_basket = ObjectRelation('*')
class in_basket(MetaUserRelationType):
pass
# is_in has been renamed into in_basket
#//* is_in Basket
#* in_basket Basket
#!/usr/bin/env python
# pylint: disable-msg=W0404,W0622,W0704,W0613,W0152
# Copyright (c) 2003-2004 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" Generic Setup script, takes package info from __pkginfo__.py file """
import os
import sys
import shutil
from distutils.core import setup
from distutils import command
from distutils.command import install_lib
from os.path import isdir, exists, join, walk
# import required features
from __pkginfo__ import distname, version, license, short_desc, long_desc, \
web, author, author_email
# import optional features
try:
from __pkginfo__ import distname
except ImportError:
distname = distname
try:
from __pkginfo__ import scripts
except ImportError:
scripts = []
try:
from __pkginfo__ import data_files
except ImportError:
data_files = None
try:
from __pkginfo__ import include_dirs
except ImportError:
include_dirs = []
BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog')
IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc')
def ensure_scripts(linux_scripts):
"""creates the proper script names required for each platform
(taken from 4Suite)
"""
from distutils import util
if util.get_platform()[:3] == 'win':
scripts_ = [script + '.bat' for script in linux_scripts]
else:
scripts_ = linux_scripts
return scripts_
def install(**kwargs):
"""setup entry point"""
#kwargs['distname'] = modname
return setup(name=distname,
version=version,
license =license,
description=short_desc,
long_description=long_desc,
author=author,
author_email=author_email,
url=web,
scripts=ensure_scripts(scripts),
data_files=data_files,
**kwargs)
if __name__ == '__main__' :
install()
from logilab.common.testlib import TestCase, unittest_main
class EBasketTC(TestCase):
def test_something(self):
self.skip('this component has no test')
if __name__ == '__main__':
unittest_main()
"""Specific views for baskets
:organization: Logilab
:copyright: 2003-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"
_ = unicode
from logilab.mtconverter import html_escape
from ginco import Unauthorized
from ginco.web.htmlwidgets import BoxWidget
from ginco.web.box import UserRQLBoxTemplate
from ginco.web.action import EntityAction
from ginco.web.views import baseviews
class BasketPrimaryView(baseviews.PrimaryView):
accepts = ('Basket',)
entity_name = 'Basket'
nothing_msg = _('nothing in basket')
content_msg = _('items in this basket')
def display_title(self, entity):
self.w(u"<span class='title'><b>%s : %s</b></span>" % (
self.req._(self.entity_name), html_escape(entity.name)))
def display_content(self, entity):
rset = self.req.execute('Any I WHERE I in_basket B, B eid %(x)s',
{'x': entity.eid}, 'x')
self.w('<h5>%s</h5>' % self.req._(self.content_msg))
if rset:
self.wview('list', rset)
else:
self.w(self.req._(self.nothing_msg))
def cell_call(self, row, col):
entity = self.complete_entity(row, col)
self.w(u'&nbsp;')
self.display_title(entity)
if entity.description:
self.w(u'<div class="contentBox">%s</div>' %
entity.printable_value('description'))
self.display_content(entity)
def insert_eids(actions, eids):
""" insert into the __linkto values of actions all the eids
this processing also filters out all the actions which don't have a linkto action
"""
processed_actions = []
for action_id, action_label, action_dict in actions:
if isinstance(action_dict, str):
continue
if action_dict.get('__linkto', None):
r_type, old_eids, target = action_dict['__linkto'].split(':')
action_dict['__linkto'] = '%s:%s:%s' % (r_type,
'_'.join([str(x) for x in eids]),
target)
processed_actions.append((action_id, action_label, action_dict))
return processed_actions
class BasketBox(UserRQLBoxTemplate):
"""display a box containing all user's basketitems"""
id = 'basket_box'
visible = False # disabled by default
order = 30
title = _('basket')
rql = 'Any B,N where B is Basket,B owned_by U, U eid %(x)s, B name N'
etype = 'Basket'
rtype = 'in_basket'
def selected_eids(self):
selectedeids = ()
if self.rset:
# something is being displayed. If the first column contains eids,
# fetch them so we can propose to add the selection to the basket
etype = iter(self.rset.column_types(0)).next()
if not self.schema.eschema(etype).is_final():
selectedeids = set(row[0] for row in self.rset.rows)
return selectedeids
def build_inbasket_link(self, box, basket):
rset = basket.related('in_basket', 'object')
title = u'%s <span class="basketName">%s</span> (%s)' % (
_('view basket'), html_escape(basket.name), len(rset))
box.append(self.mk_action(title, basket.absolute_url(),
escape=False))
return rset, [row[0] for row in rset]
def build_add_link(self, box, basket, addable, rql, vid):
title = u'%s <span class="basketName">%s</span>' % (
_('add to basket'), html_escape(basket.name))
linkto = u'in_basket:%s:object' % '_'.join(addable)
msg = _('selection added to basket')
url = self.build_url('edit', eid=basket.eid, rql=rql,
__linkto=linkto, __message=msg,
__redirectrql=rql, __redirect_vid=vid)
box.append(self.mk_action(title, url, category='manage',
escape=False))
def build_delete_link(self, box, basket, inbasketeids, rql, vid):
title = '%s <span class="basketName">%s</span>' % (
_('reset basket'), html_escape(basket.name))
delete = '%s:in_basket:%s' % ('_'.join(str(eid) for eid in inbasketeids),
basket.eid)
msg = _('Basket %s emptied') % basket.name
url = self.build_url('edit', rql=rql, __delete=delete,
__message=msg, __redirectrql=rql,
__redirect_vid=vid)
box.append(self.mk_action(title, url, category='manage'))
def call(self, **kwargs):
try:
baskets = self.req.execute(*self.to_display_rql())
except Unauthorized:
# can't access to something in the query, forget this box
return
_ = self.req._
req = self.req
box = BoxWidget(_(self.title), self.id)
rschema = self.schema.rschema(self.rtype)
actions = []
rql = req.form.get('rql') or kwargs.get('rql') or ''
vid = req.form.get('vid', '')
selectedeids = self.selected_eids()
itemsrql = 'Any X WHERE X in_basket B, B eid %(x)s'
for basket in baskets.entities():
rset, inbasketeids = self.build_inbasket_link(box, basket)
if selectedeids and rschema.has_perm(req, 'add'):
addable = [str(eid) for eid in selectedeids if not eid in inbasketeids]
if addable:
self.build_add_link(box, basket, addable, rql, vid)
if not rset:
continue
if rschema.has_perm(req, 'delete'):
self.build_delete_link(box, basket, inbasketeids, rql, vid)
eschema = self.schema.eschema(self.etype)
if eschema.has_perm(req, 'add'):
actions.append(self.mk_action(_('create basket'),
self.create_url(self.etype),
category='manage'))
if not box.is_empty():
box.render(self.w)
# displayed by the above box
baseviews.PRIMARY_SKIP_RELS.add('in_basket')
class SelectBasketContentAction(EntityAction):
category = 'mainactions'
accepts = ('Basket',)
id = 'select_basket_content'
title = _('actions_select_basket_content')
def url(self):
rql = u'Any X WHERE X in_basket B, B eid %s' % self.rset[self.row or 0][self.col or 0]
return self.build_url(rql=rql)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment