本文整理匯總了Python中django_tables2.Column方法的典型用法代碼示例。如果您正苦於以下問題:Python django_tables2.Column方法的具體用法?Python django_tables2.Column怎麽用?Python django_tables2.Column使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django_tables2
的用法示例。
在下文中一共展示了django_tables2.Column方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_table_qsdata
# 需要導入模塊: import django_tables2 [as 別名]
# 或者: from django_tables2 import Column [as 別名]
def _create_table_qsdata(
action_id: int,
qs,
dt_page: DataTablesServerSidePaging,
columns: List[models.Column],
key_idx: int,
) -> List:
"""Select the subset of the qs to be sent as qs data to the JSON request.
:param action_id: Action id being processed
:param qs: Query set from where to extract the data
:param dt_page: Object with DataTable parameters to process the page
:param columns: List of column
:param key_idx: Index of the key column
:return: Query set to return to DataTable JavaScript
"""
final_qs = []
item_count = 0
for row in qs[dt_page.start:dt_page.start + dt_page.length]:
item_count += 1
# Render the first element (the key) as the link to the page to update
# the content.
row = list(row)
row[key_idx] = _create_link_to_survey_row(
action_id,
columns[key_idx].name,
row[key_idx],
)
# Add the row for rendering
final_qs.append(row)
if item_count == dt_page.length:
# We reached the number or requested elements, abandon loop
break
return final_qs
示例2: update_luser_email_column
# 需要導入模塊: import django_tables2 [as 別名]
# 或者: from django_tables2 import Column [as 別名]
def update_luser_email_column(
user,
pk: int,
workflow: models.Workflow,
column: models.Column,
):
"""Update the field luser_email in the workflow.
:param user: User making the request
:param pk: Column ID to obtain the user id
:param workflow: Workflow being manipulated.
:param column: Column being used to update the luser field.
:return:
"""
if not pk:
# Empty pk, means reset the field.
workflow.luser_email_column = None
workflow.luser_email_column_md5 = ''
workflow.lusers.set([])
workflow.save(update_fields=[
'luser_email_column',
'luser_email_column_md5'])
return
table_name = workflow.get_data_frame_table_name()
# Get the column content
emails = sql.get_rows(table_name, column_names=[column.name])
# Verify that the column as a valid set of emails
incorrect_email = get_incorrect_email([row[column.name] for row in emails])
if incorrect_email:
raise services.OnTaskWorkflowEmailError(
message=_('Incorrect email addresses "{0}".').format(
incorrect_email))
# Update the column
workflow.luser_email_column = column
workflow.save(update_fields=['luser_email_column'])
# Calculate the MD5 value
md5_hash = sql.get_text_column_hash(table_name, column.name)
if workflow.luser_email_column_md5 == md5_hash:
return
# Change detected, run the update in batch mode
workflow.luser_email_column_md5 = md5_hash
workflow.save(update_fields=['luser_email_column_md5'])
# Log the event with the status "preparing updating"
log_item = workflow.log(user, models.Log.WORKFLOW_UPDATE_LUSERS)
# Push the update of lusers to batch processing
tasks.execute_operation.delay(
operation_type=models.Log.WORKFLOW_UPDATE_LUSERS,
user_id=user.id,
workflow_id=workflow.id,
log_id=log_item.id)
示例3: _create_rubric_table
# 需要導入模塊: import django_tables2 [as 別名]
# 或者: from django_tables2 import Column [as 別名]
def _create_rubric_table(
action: models.Action,
criteria: List[models.ActionColumnConditionTuple],
context: Dict
):
"""Create the table showing the rubric content."""
if not criteria:
return
# Create the extra columns in the table with the categories
extra_columns = []
loas = criteria[0].column.categories
# Get the extra columns for the rubric
for idx, loa in enumerate(loas):
extra_columns.append((
'loa_{0}'.format(idx),
tables.Column(verbose_name=loa)
))
# Create the table data
table_data = []
cell_ctx = {'action_id': action.id}
for criterion in criteria:
cell_ctx['column_id'] = criterion.column.id
rubric_row = OrderedDict([(
'criterion',
render_to_string(
'workflow/includes/partial_criterion_cell.html',
context={'criterion': criterion, 'action': action}))])
cels = models.RubricCell.objects.filter(
action=action,
column=criterion.column)
for idx in range(len(loas)):
cell = cels.filter(loa_position=idx).first()
loa_str = 'loa_{0}'.format(idx)
cell_ctx['loa_idx'] = idx
if cell:
cell_ctx['description_text'] = cell.description_text
cell_ctx['feedback_text'] = cell.feedback_text
else:
cell_ctx['description_text'] = ''
cell_ctx['feedback_text'] = ''
rubric_row[loa_str] = render_to_string(
'action/includes/partial_rubriccell.html',
cell_ctx
)
table_data.append(rubric_row)
context['rubric_table'] = RubricTable(
table_data,
orderable=False,
extra_columns=extra_columns)