File web_ui.py
has 1599 lines of code (exceeds 250 allowed). Consider refactoring. Open
# -*- coding: utf-8 -*-
#
# Copyright (C) 2003-2023 Edgewall Software
# Copyright (C) 2003-2005 Jonas Borgström <jonas@edgewall.com>
# All rights reserved.
Function get_timeline_events
has a Cognitive Complexity of 86 (exceeds 5 allowed). Consider refactoring. Open
def get_timeline_events(self, req, start, stop, filters):
ts_start = to_utimestamp(start)
ts_stop = to_utimestamp(stop)
status_map = {'new': ('newticket', 'created'),
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _process_ticket_request
has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring. Open
def _process_ticket_request(self, req):
id = req.args.getint('id')
version = req.args.getint('version', None)
if req.is_xhr and 'preview_comment' in req.args:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _prepare_fields
has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring. Open
def _prepare_fields(self, req, ticket, field_changes=None):
context = web_context(req, ticket.resource)
fields = TicketFieldList()
for field in ticket.fields:
name = field['name']
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _insert_ticket_data
has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring. Open
def _insert_ticket_data(self, req, ticket, data, author_id, field_changes):
"""Insert ticket data into the template `data`"""
replyto = req.args.get('replyto')
data['replyto'] = replyto
data['version'] = ticket.resource.version
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _render_diff
has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring. Open
def _render_diff(self, req, ticket, data, text_fields):
"""Show differences between two versions of a ticket description.
`text_fields` is optionally a list of fields of interest, that are
considered for jumping to the next change.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
TicketModule
has 47 functions (exceeds 20 allowed). Consider refactoring. Open
class TicketModule(Component):
implements(IContentConverter, INavigationContributor, IRequestHandler,
ISearchSource, ITemplateProvider, ITimelineEventProvider)
Function _render_property_diff
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
def _render_property_diff(self, req, ticket, field, old, new,
resource_new=None):
def render_list(elt_renderer, split_list, old, new):
if not elt_renderer:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _validate_ticket
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
def _validate_ticket(self, req, ticket, force_collision_check=False):
valid = True
resource = ticket.resource
# If the ticket has been changed, check the proper permissions
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _populate
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
def _populate(self, req, ticket, plain_fields=False):
if not plain_fields:
fields = {k[6:]: req.args.get(k) for k in req.args
if k.startswith('field_') and
'revert_' + k[6:] not in req.args}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function grouped_changelog_entries
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
def grouped_changelog_entries(self, ticket, when=None):
"""Iterate on changelog entries, consolidating related changes
in a `dict` object.
"""
field_labels = TicketSystem(self.env).get_ticket_field_labels()
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _export_rss
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def _export_rss(self, req, ticket):
changes = []
for change in self.rendered_changelog_entries(req, ticket):
changes.append(change)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _process_newticket_request
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def _process_newticket_request(self, req):
req.perm(self.realm).require('TICKET_CREATE')
ticket = model.Ticket(self.env)
plain_fields = True # support for /newticket?version=0.11 GETs
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _render_comment_diff
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def _render_comment_diff(self, req, ticket, data, cnum):
"""Show differences between two versions of a ticket comment."""
req.perm(ticket.resource).require('TICKET_VIEW')
new_version = req.args.getint('version', 1)
old_version = req.args.getint('old_version', new_version)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get_ticket_changes
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def get_ticket_changes(self, req, ticket, selected_action):
"""Returns a dictionary of field changes.
The field changes are represented as:
`{field: {'old': oldvalue, 'new': newvalue, 'by': what}, ...}`
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _toggle_cc
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def _toggle_cc(self, req, cc):
"""Return an (action, recipient) tuple corresponding to a change
of CC status for this user relative to the current `cc_list`."""
entry = None
if req.is_authenticated:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function rendered_changelog_entries
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def rendered_changelog_entries(self, req, ticket, when=None):
"""Iterate on changelog entries, consolidating related changes
in a `dict` object.
"""
attachment_realm = ticket.resource.child('attachment')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _query_link_words
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def _query_link_words(self, context, name, value, query=None):
"""Splits a list of words and makes a query link to each separately"""
from trac.ticket.query import QueryModule
if not (isinstance(value, str) and # None or other non-splitable
self.env.is_component_enabled(QueryModule)):
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function render_timeline_event
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def render_timeline_event(self, context, field, event):
kind = event[0]
if kind == 'batchmodify':
return self._render_batched_timeline_event(context, field, event)
ticket, verb, info, summary, status, resolution, type, \
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _render_diff
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _render_diff(self, req, ticket, data, text_fields):
"""Show differences between two versions of a ticket description.
`text_fields` is optionally a list of fields of interest, that are
considered for jumping to the next change.
Function _render_comment_diff
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _render_comment_diff(self, req, ticket, data, cnum):
"""Show differences between two versions of a ticket comment."""
req.perm(ticket.resource).require('TICKET_VIEW')
new_version = req.args.getint('version', 1)
old_version = req.args.getint('old_version', new_version)
Function _insert_ticket_data
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _insert_ticket_data(self, req, ticket, data, author_id, field_changes):
"""Insert ticket data into the template `data`"""
replyto = req.args.get('replyto')
data['replyto'] = replyto
data['version'] = ticket.resource.version
Function _process_ticket_request
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _process_ticket_request(self, req):
id = req.args.getint('id')
version = req.args.getint('version', None)
if req.is_xhr and 'preview_comment' in req.args:
Function check_permission
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def check_permission(self, action, username, resource, perm):
if action == 'TICKET_CHG_MILESTONE' and \
action not in PermissionSystem(self.env).actions and \
self._is_valid_resource(resource, 'milestone') and \
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _render_property_diff
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def _render_property_diff(self, req, ticket, field, old, new,
Avoid deeply nested control flow statements. Open
if prev_t == t:
ticket = ev[3][0]
batch_ev[3][0].append(ticket.id)
else:
yield batch_ev
Function _query_link
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def _query_link(self, req, name, value, text=None, class_=None, query=None):
Avoid deeply nested control flow statements. Open
if prev_ev:
yield prev_ev
prev_ev = ev
Avoid deeply nested control flow statements. Open
if not group['fields']:
continue
yield group
Avoid deeply nested control flow statements. Open
for prev_id, in db(
"SELECT max(id) FROM ticket WHERE id < %s",
(ticket.id,)):
add_ticket_link('prev', int(prev_id))
if ticket.id < max_id:
Avoid deeply nested control flow statements. Open
for next_id, in db(
"SELECT min(id) FROM ticket WHERE %s < id",
(ticket.id,)):
add_ticket_link('next', int(next_id))
break
Avoid deeply nested control flow statements. Open
for k, v in change['fields'].items():
values[k] = v['new']
if 'description' in change['fields']:
Avoid deeply nested control flow statements. Open
if ev:
yield ev
# Attachments
if 'ticket_details' in filters:
Avoid deeply nested control flow statements. Open
if k not in values:
values[k] = v['old']
skip = True
Function _insert_ticket_data
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _insert_ticket_data(self, req, ticket, data, author_id, field_changes):
Function _do_save
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _do_save(self, req, ticket, action):
# Save the action controllers we need to call side-effects for before
# we save the changes to the ticket.
controllers = list(self._get_action_controllers(req, ticket, action))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function export_csv
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def export_csv(self, req, ticket, sep=',', mimetype='text/plain'):
# FIXME: consider dumping history of changes here as well
# as one row of output doesn't seem to be terribly useful...
fields = [f for f in ticket.fields
if f['name'] not in ('time', 'changetime')]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _get_action_controls
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _get_action_controls(self, req, ticket):
# action_controls is an ordered list of "renders" tuples, where
# renders is a list of (action_key, label, widgets, hints)
# representing the user interface for each action
action_controls = []
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return 'ticket.html', data
Avoid too many return
statements within this function. Open
return 'ticket_preview.html', data