web/views/__init__.py
author Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
Thu, 26 Nov 2015 11:30:54 +0100
changeset 10935 049209b9e9d6
parent 10688 fa29f3628a1b
permissions -rw-r--r--
[qunit] stop dealing with filesystem paths qunit tests need a few things served by cubicweb: - qunit itself, which is now handled by CWDevtoolsStaticController (serving files in cubicweb/devtools/data) - standard cubicweb or cubes data files, handled by the DataController - the tests themselves and their dependencies. These can live in <apphome>/data or <apphome>/static and be served by one of the STATIC_CONTROLLERS This avoids having to guess in CWSoftwareRootStaticController where to serve things from (some files may be installed, others are in the source tree), and should hopefully make it possible to have these tests pass when using tox, and to write qunit tests for cubes, outside of cubicweb itself. This requires modifying the tests to only declare URL paths instead of filesystem paths, and moving support files below test/data/static.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7806
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
     1
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6377
3bb415310d4f [schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6276
diff changeset
    18
"""Views, forms, actions... for the CubicWeb web client"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 631
diff changeset
    21
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 631
diff changeset
    22
import os
3122
0e49d2679c5c fix open call to make cw happy /win32
Aurelien Campeas
parents: 2491
diff changeset
    23
import sys
2446
440cb4ea7e5c [refactor] #342855: replace uses of (deprecated) mktemp
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2230
diff changeset
    24
import tempfile
7806
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
    25
10688
fa29f3628a1b [py3k] use six.add_metaclass
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10582
diff changeset
    26
from six import add_metaclass
fa29f3628a1b [py3k] use six.add_metaclass
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10582
diff changeset
    27
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
from rql import nodes
7806
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
    29
from logilab.mtconverter import xml_escape
9383
7b3fa5a7a5a3 [views/dot] use an inlined svg for schema and workflow graphs
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7806
diff changeset
    30
from logilab.common.deprecation import class_deprecated
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 631
diff changeset
    32
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
def need_table_view(rset, schema):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
    """return True if we think that a table view is more appropriate than a
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    list or primary view to display the given result set
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
    rqlst = rset.syntax_tree()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
    if len(rqlst.children) > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
        # UNION query, use a table
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
        return True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
    selected = rqlst.children[0].selection
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
    try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
        mainvar = selected[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
    except AttributeError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
        # not a variable ref, using table view is probably a good option
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
        return True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
    if not (isinstance(mainvar, nodes.VariableRef) or
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
            (isinstance(mainvar, nodes.Constant) and mainvar.uid)):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
        return True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
    for i, etype in enumerate(rset.description[0][1:]):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
        # etype may be None on outer join
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
        if etype is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
            return True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        # check the selected index node is a VariableRef (else we
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
        # won't detect aggregate function
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
        if not isinstance(selected[i+1], nodes.VariableRef):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
            return True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
        # if this is not a final entity
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3145
diff changeset
    59
        if not schema.eschema(etype).final:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
            return True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
        # if this is a final entity not linked to the main variable
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        var = selected[i+1].variable
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
        for vref in var.references():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
            rel = vref.relation()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
            if rel is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
            if mainvar.is_equivalent(rel.children[0]):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
                break
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
            return True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
    return False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
2193
667b6340bfd4 [views] comment the naive content-negotiation algorithm, it breaks FF2 navigation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
    73
# FIXME: VID_BY_MIMETYPE is unfortunately a bit too naive since
667b6340bfd4 [views] comment the naive content-negotiation algorithm, it breaks FF2 navigation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
    74
#        some browsers (e.g. FF2) send a bunch of mimetypes in
667b6340bfd4 [views] comment the naive content-negotiation algorithm, it breaks FF2 navigation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
    75
#        the Accept header, for instance:
667b6340bfd4 [views] comment the naive content-negotiation algorithm, it breaks FF2 navigation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
    76
#          text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,
667b6340bfd4 [views] comment the naive content-negotiation algorithm, it breaks FF2 navigation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
    77
#          text/plain;q=0.8,image/png,*/*;q=0.5
667b6340bfd4 [views] comment the naive content-negotiation algorithm, it breaks FF2 navigation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
    78
VID_BY_MIMETYPE = {
667b6340bfd4 [views] comment the naive content-negotiation algorithm, it breaks FF2 navigation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
    79
    #'text/xml': 'xml',
667b6340bfd4 [views] comment the naive content-negotiation algorithm, it breaks FF2 navigation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
    80
    # XXX rss, owl...
667b6340bfd4 [views] comment the naive content-negotiation algorithm, it breaks FF2 navigation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
    81
}
10582
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9700
diff changeset
    82
def vid_from_rset(req, rset, schema, check_table=True):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
    """given a result set, return a view id"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    if rset is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
        return 'index'
1716
b12d9e22bac3 basic support for http Accept header (untested)
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
    86
    for mimetype in req.parse_accept_header('Accept'):
1719
bf26f32c8a72 wrong variable name
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1716
diff changeset
    87
        if mimetype in VID_BY_MIMETYPE:
bf26f32c8a72 wrong variable name
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1716
diff changeset
    88
            return VID_BY_MIMETYPE[mimetype]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
    nb_rows = len(rset)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
    # empty resultset
6276
cb4a48b2250e cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    91
    if nb_rows == 0:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
        return 'noresult'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
    # entity result set
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3145
diff changeset
    94
    if not schema.eschema(rset.description[0][0]).final:
10582
bc2f6f0d7433 [urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9700
diff changeset
    95
        if check_table and need_table_view(rset, schema):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
            return 'table'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
        if nb_rows == 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
            if req.search_state[0] == 'normal':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
                return 'primary'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
            return 'outofcontext-search'
2491
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2487
diff changeset
   101
        if len(rset.column_types(0)) == 1:
4494
ccb7fce7297b AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   102
            return 'sameetypelist'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        return 'list'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
    return 'table'
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   105
1716
b12d9e22bac3 basic support for http Accept header (untested)
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
   106
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
def linksearch_select_url(req, rset):
9700
da7d341cca76 an URL -> a URL
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9383
diff changeset
   108
    """when searching an entity to create a relation, return a URL to select
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
    entities in the given rset
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
    req.add_js( ('cubicweb.ajax.js', 'cubicweb.edition.js') )
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   112
    target, eid, r_type, searchedtype = req.search_state[1]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
    if target == 'subject':
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   114
        id_fmt = '%s:%s:%%s' % (eid, r_type)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
    else:
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   116
        id_fmt = '%%s:%s:%s' % (r_type, eid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
    triplets = '-'.join(id_fmt % row[0] for row in rset.rows)
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   118
    return "javascript: selectForAssociation('%s', '%s');" % (triplets, eid)
1716
b12d9e22bac3 basic support for http Accept header (untested)
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
   119
b12d9e22bac3 basic support for http Accept header (untested)
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
   120
7806
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   121
def add_etype_button(req, etype, csscls='addButton right', **urlkwargs):
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   122
    vreg = req.vreg
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   123
    eschema = vreg.schema.eschema(etype)
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   124
    if eschema.has_perm(req, 'add'):
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   125
        url = vreg['etypes'].etype_class(etype).cw_create_url(req, **urlkwargs)
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   126
        return u'<a href="%s" class="%s">%s</a>' % (
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   127
            xml_escape(url), csscls, req.__('New %s' % etype))
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   128
    return u''
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   129
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   130
9383
7b3fa5a7a5a3 [views/dot] use an inlined svg for schema and workflow graphs
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7806
diff changeset
   131
10688
fa29f3628a1b [py3k] use six.add_metaclass
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10582
diff changeset
   132
@add_metaclass(class_deprecated)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   133
class TmpFileViewMixin(object):
9383
7b3fa5a7a5a3 [views/dot] use an inlined svg for schema and workflow graphs
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7806
diff changeset
   134
    __deprecation_warning__ = '[3.18] %(cls)s is deprecated'
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   135
    binary = True
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   136
    content_type = 'application/octet-stream'
1716
b12d9e22bac3 basic support for http Accept header (untested)
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
   137
    cache_max_age = 60*60*2 # stay in http cache for 2 hours by default
b12d9e22bac3 basic support for http Accept header (untested)
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
   138
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   139
    def call(self):
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   140
        self.cell_call()
1716
b12d9e22bac3 basic support for http Accept header (untested)
sylvain.thenault@logilab.fr
parents: 1091
diff changeset
   141
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 631
diff changeset
   142
    def cell_call(self, row=0, col=0):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3145
diff changeset
   143
        self.cw_row, self.cw_col = row, col # in case one needs it
3145
9b28545de60d avoid open file handler leak
Aurelien Campeas
parents: 3122
diff changeset
   144
        fd, tmpfile = tempfile.mkstemp('.png')
9b28545de60d avoid open file handler leak
Aurelien Campeas
parents: 3122
diff changeset
   145
        os.close(fd)
9b28545de60d avoid open file handler leak
Aurelien Campeas
parents: 3122
diff changeset
   146
        self._generate(tmpfile)
9b28545de60d avoid open file handler leak
Aurelien Campeas
parents: 3122
diff changeset
   147
        self.w(open(tmpfile, 'rb').read())
9b28545de60d avoid open file handler leak
Aurelien Campeas
parents: 3122
diff changeset
   148
        os.unlink(tmpfile)