• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SEED-platform / seed / #6522

pending completion
#6522

push

coveralls-python

web-flow
Update derived column migration to prevent conflicting column names and prevent duplicate column names (#3728)

* update derived column migration to create unique names for derived columns

* prevent derived column names that are duplicated with column names

* disable create/save on error

* update and add test

15680 of 22591 relevant lines covered (69.41%)

0.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.58
/seed/templatetags/breadcrumbs.py
1
# !/usr/bin/env python
2
# encoding: utf-8
3
"""
1✔
4
:copyright (c) 2014 - 2022, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Department of Energy) and contributors. All rights reserved.
5
:author
6
"""
7
"""
8
breadcrumbs.py
9

10
https://bitbucket.org/Mathiasdm/django-simple-breadcrumbs/
11
"""
12

13
import logging
1✔
14

15
from django import template
1✔
16
from django.template import Node, Variable, VariableDoesNotExist
17
from django.template.defaulttags import url
18
from django.utils.translation import gettext as _
19

20
_log = logging.getLogger(__name__)
1✔
21

22
register = template.Library()
1✔
23

24

25
def create_crumb(title, url=None):
1✔
26
    """
27
    Helper function
28
    """
29

30
    if url:
×
31
        crumb = '<span class="breadcrumb-separator">/</span><a class="breadcrumb-item" href="%s">%s</a>' % (url, title)
×
32
    else:
33
        crumb = '<span class="breadcrumb-separator">/</span><span class="breadcrumb-item">%s</span>' % (title, )
×
34

35
    return crumb
×
36

37

38
def create_crumb_first(title, url=None):
1✔
39
    """
40
    Helper function
41
    """
42

43
    if url:
×
44
        crumb = '<a class="breadcrumb-item root" href="%s">%s</a>' % (url, title)
×
45
    else:
46
        crumb = '<span class="breadcrumb-item root">%s</span>' % (title, )
×
47

48
    return crumb
×
49

50

51
@register.tag
1✔
52
def breadcrumb(parser, token):
1✔
53
    """
54
    .. sectionauthor:: Andriy Drozdyuk
55

56
    Renders the breadcrumb.
57

58
    Example::
59

60
        {% breadcrumb "Title of breadcrumb" url_var %}
61
        {% breadcrumb context_var  url_var %}
62
        {% breadcrumb "Just the title" %}
63
        {% breadcrumb just_context_var %}
64

65
    Parameters::
66

67
        First parameter is the title of the crumb
68
        Second (optional) parameter is the url variable to link to, produced by url tag, i.e.:
69
            {% url "person_detail" object.id as person_url %}
70
            then:
71
            {% breadcrumb person.name person_url %}
72
    """
73
    return BreadcrumbNode(token.split_contents()[1:])
×
74

75

76
@register.tag
1✔
77
def breadcrumb_root(parser, token):
1✔
78
    """
79
    .. sectionauthor:: Andriy Drozdyuk
80

81
    Renders the breadcrumb.
82

83
    Examples::
84

85
        {% breadcrumb "Title of breadcrumb" url_var %}
86
        {% breadcrumb context_var  url_var %}
87
        {% breadcrumb "Just the title" %}
88
        {% breadcrumb just_context_var %}
89

90
    Parameters::
91

92
        First parameter is the title of the crumb,
93
        Second (optional) parameter is the url variable to link to, produced by url tag, i.e.:
94
            {% url "person_detail/" object.id as person_url %}
95
            then:
96
            {% breadcrumb person.name person_url %}
97
    """
98
    return BreadcrumbNode(token.split_contents()[1:], create_crumb_first)
×
99

100

101
@register.tag
1✔
102
def breadcrumb_url(parser, token):
1✔
103
    """
104
    Same as breadcrumb but instead of url context variable takes in all the
105
    arguments URL tag takes.
106

107
    .. code-block:: python
108

109
        {% breadcrumb "Title of breadcrumb" person_detail person.id %}
110
        {% breadcrumb person.name person_detail person.id %}
111
    """
112

113
    bits = token.split_contents()
×
114
    if len(bits) == 2:
×
115
        return breadcrumb(parser, token)
×
116

117
    # Extract our extra title parameter
118
    title = bits.pop(1)
×
119
    token.contents = ' '.join(bits)
×
120

121
    url_node = url(parser, token)
×
122

123
    return UrlBreadcrumbNode(title, url_node)
×
124

125

126
@register.tag
1✔
127
def breadcrumb_url_root(parser, token):
1✔
128
    """
129
    Same as breadcrumb but instead of url context variable takes in all the
130
    arguments URL tag takes.
131

132
    .. code-block:: python
133

134
        {% breadcrumb "Title of breadcrumb" person_detail person.id %}
135
        {% breadcrumb person.name person_detail person.id %}
136
    """
137

138
    bits = token.split_contents()
×
139
    if len(bits) == 2:
×
140
        return breadcrumb(parser, token)
×
141

142
    # Extract our extra title parameter
143
    title = bits.pop(1)
×
144
    token.contents = ' '.join(bits)
×
145

146
    url_node = url(parser, token)
×
147

148
    return UrlBreadcrumbNode(title, url_node, create_crumb_first)
×
149

150

151
class BreadcrumbNode(Node):
1✔
152

153
    def __init__(self, vars, render_func=create_crumb):
1✔
154
        """
155
        First var is title, second var is url context variable
156
        """
157
        self.vars = map(Variable, vars)
×
158
        self.render_func = render_func
×
159

160
    def render(self, context):
1✔
161
        title = self.vars[0].var
×
162

163
        if title.find("'") == -1 and title.find('"') == -1:
×
164
            try:
×
165
                val = self.vars[0]
×
166
                title = val.resolve(context)
×
167
            except BaseException:
×
168
                title = ''
×
169

170
        else:
171
            title = title.strip("'").strip('"')
×
172

173
        url = None
×
174

175
        if len(self.vars) > 1:
×
176
            val = self.vars[1]
×
177
            try:
×
178
                url = val.resolve(context)
×
179
            except VariableDoesNotExist:
×
180
                _log.error('URL does not exist: {}'.format(val))
×
181
                url = None
×
182

183
        # add gettext function for title i18n translation
184
        title = _(title)
×
185
        return self.render_func(title, url)
×
186

187

188
class UrlBreadcrumbNode(Node):
1✔
189

190
    def __init__(self, title, url_node, render_func=create_crumb):
1✔
191
        self.title = Variable(title)
×
192
        self.url_node = url_node
×
193
        self.render_func = render_func
×
194

195
    def render(self, context):
1✔
196
        title = self.title.var
×
197

198
        if title.find("'") == -1 and title.find('"') == -1:
×
199
            try:
×
200
                val = self.title
×
201
                title = val.resolve(context)
×
202
            except BaseException:
×
203
                title = ''
×
204
        else:
205
            title = title.strip("'").strip('"')
×
206

207
        url = self.url_node.render(context)
×
208
        # add gettext function for title translation i18n
209
        title = _(title)
×
210
        return self.render_func(title, url)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc