本文整理汇总了Python中django_tables2.RequestConfig.configure方法的典型用法代码示例。如果您正苦于以下问题:Python RequestConfig.configure方法的具体用法?Python RequestConfig.configure怎么用?Python RequestConfig.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_tables2.RequestConfig
的用法示例。
在下文中一共展示了RequestConfig.configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_settings
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def show_settings(request):
config = RequestConfig(request)
template = loader.get_template('settings.html')
taxtable = TaxTable(TaxRate.objects.all(), prefix="tax-")
billingcycleable = BillingCycleTable(CustomerBillingCycle.objects.all(), prefix="billingcycle-")
unittable = UnitTable(Unit.objects.all(), prefix="unit-")
customergrouptable = CustomerGroupTable(CustomerGroup.objects.all(), prefix="customergroup-")
productcategorytable = ProductCategoryTable(ProductCategory.objects.all(), prefix="productcategory-")
config.configure(taxtable)
config.configure(billingcycleable)
config.configure(unittable)
config.configure(customergrouptable)
config.configure(productcategorytable)
taxtable.paginate(page=request.GET.get('page', 1), per_page=5)
billingcycleable.paginate(page=request.GET.get('page', 1), per_page=5)
unittable.paginate(page=request.GET.get('page', 1), per_page=5)
customergrouptable.paginate(page=request.GET.get('page', 1), per_page=5)
productcategorytable.paginate(page=request.GET.get('page', 1), per_page=5)
context = RequestContext(request, {
'taxtable': taxtable,
'billingcycletable': billingcycleable,
'unittable': unittable,
'customergrouptable': customergrouptable,
'productcategorytable': productcategorytable
})
return HttpResponse(template.render(context))
示例2: prefs
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def prefs(req, user=None):
'''
Show the preference page of the specified user.
If requesting to show user that is not current session,
the superuser permission are required.
'''
if user==None: user=req.user.username
if user!=req.user.username and not req.user.is_superuser:
if req.user.username!=user: return HttpResponseForbidden('<h1>403-Forbidden</h1>')
user=getObj(get_user_model(), username=user)
if req.method=='POST':
newPwd=req.POST.get('newPwd', None)
if newPwd and newPwd==req.POST.get('rePwd', None):
user.set_password(newPwd)
user.save()
auth_logout(req)
return redirect('webframe:prefs', user=user)
params=dict()
params['preference']=PreferenceTable(Preference.objects.filter(owner=req.user, parent__isnull=True))
params['config']=PreferenceTable(Preference.objects.filter(owner__isnull=True, parent__isnull=True))
rc=RequestConfig(req)
rc.configure(params['preference'])
rc.configure(params['config'])
params['currentuser']=user
if req.user.has_perm('webframe.add_config') or req.user.has_perm('webframe.change.config'):
m=hashlib.md5()
m.update(user.username.encode('utf-8'))
m.update(CONFIG_KEY.encode('utf-8'))
params['config_key']=m.hexdigest()
return render(req, getattr(settings, 'TMPL_PREFERENCES', 'webframe/preferences.html'), params)
示例3: TableHelperMixin
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
class TableHelperMixin(object):
"""
provide a function add_table that you can call in a get_context_data to add and configure tables from querysets
"""
table_context_name_base = 'mtable'
mtables = 0
tconfig = None
def get_new_table_context_name(self):
return '{}{}'.format(self.table_context_name_base, self.mtables)
def add_table(self, context, qs, table_class=None, with_report=False, context_name=None, **kwargs):
"""
context = context from get_context_data (dict)
qs = the qs for the table
table_class = Table class to use, auto generated from model if not provided.
kwargs = will be used in the auto generation table class.
with_report = FIXME: not showing export buttons right now.
context_name = specify context name for the table
"""
if not self.mtables:
self.mtables = 0
if not self.tconfig:
self.config = RequestConfig(self.request)
convert_to_list = kwargs.get('convert_to_list')
if not table_class:
if with_report:
table_class = create_report_table(qs.model, **kwargs)
else:
table_class = create_model_table(qs.model, **kwargs)
if convert_to_list:
table_fields = kwargs.get('table_fields', [])
if table_fields:
qs_list = self.convert_qs_to_list(qs, table_fields)
else:
qs_list = qs.values()
qs_list = list(qs_list)
table = table_class(qs_list)
else:
table = table_class(qs)
self.config.configure(table)
self.mtables = self.mtables + 1
context[context_name or self.get_new_table_context_name()] = table
return table
def convert_qs_to_list(self, qs, table_fields):
qs_list = []
for obj in qs:
obj_dict = {}
for f in table_fields:
x = getattr(obj, f)
if hasattr(x, '__call__'):
x = x()
obj_dict[f] = x
qs_list.append(obj_dict)
return qs_list
示例4: get_context_data
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def get_context_data(self, **kwargs):
"""
Configures quest set filters and table information.
Returns a context dictionary.
"""
context = super(QuestMixin, self).get_context_data(**kwargs)
context['owner'] = Relation.objects.owned_by(self.request.user)
context['owned'] = Quest.objects.owned_by(self.request.user)
context['assigned'] = Quest.objects.assigned_to(self.request.user)
context['proposed'] = Quest.objects.proposed_by(self.request.user)
context['pending'] = Quest.objects.pending_for(self.request.user)
context['completed'] = Quest.objects.completed_for(self.request.user)
context['waiting'] = Quest.objects.waiting_for(self.request.user)
context['owned_table'] = OwnedQuestTable(context['owned'])
context['assigned_table'] = AssignedQuestTable(context['assigned'])
context['proposed_table'] = ProposedQuestTable(context['proposed'])
context['pending_table'] = PendingQuestTable(context['pending'])
context['completed_table'] = CompletedQuestTable(context['completed'])
context['waiting_table'] = WaitingQuestTable(context['waiting'])
requestConfig = RequestConfig(self.request, paginate={"per_page": 10,})
requestConfig.configure(context['owned_table'])
requestConfig.configure(context['assigned_table'])
requestConfig.configure(context['proposed_table'])
requestConfig.configure(context['pending_table'])
requestConfig.configure(context['completed_table'])
requestConfig.configure(context['waiting_table'])
return context
示例5: filters_list
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def filters_list(request):
public_view = PublicFiltersView(request, model=TestRunFilter, table_class=PublicFiltersTable)
prefix = "public_"
public_filters_table = PublicFiltersTable(public_view.get_table_data(prefix), prefix=prefix)
config = RequestConfig(request)
config.configure(public_filters_table)
search_data = public_filters_table.prepare_search_data(public_view)
discrete_data = public_filters_table.prepare_discrete_data(public_view)
terms_data = public_filters_table.prepare_terms_data(public_view)
times_data = public_filters_table.prepare_times_data(public_view)
user_filters_table = None
if request.user.is_authenticated():
user_view = UserFiltersView(request, model=TestRunFilter, table_class=UserFiltersTable)
prefix = "user_"
user_filters_table = UserFiltersTable(user_view.get_table_data(prefix), prefix=prefix)
config.configure(user_filters_table)
search_data.update(user_filters_table.prepare_search_data(user_view))
discrete_data.update(user_filters_table.prepare_discrete_data(user_view))
terms_data.update(user_filters_table.prepare_terms_data(user_view))
return render_to_response(
"dashboard_app/filters_list.html",
{
"user_filters_table": user_filters_table,
"public_filters_table": public_filters_table,
"terms_data": terms_data,
"search_data": search_data,
"times_data": times_data,
"discrete_data": discrete_data,
"bread_crumb_trail": BreadCrumbTrail.leading_to(filters_list),
},
RequestContext(request),
)
示例6: ondemand
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def ondemand(request):
"""provides on demand portion of site
"""
now = datetime.today()
channels_filtered=request.GET.getlist('channels')
type_filtered=request.GET.get('type')
#switch the value of type filtered to the other so that it can properly exclude the opposite value
if type_filtered=="Tv":
type_filtered="Movie"
elif type_filtered=="Movie":
type_filtered="Tv"
if channels_filtered:
#filters out any channel that was passed in the Get request as checkmarked
#channels_removed_obj_list = [obj for obj in Titles.objects.all() if any(name in obj.channel for name in channels_filtered)]
ob_list_channelsremoved = Ondemand_Titles.objects.exclude(reduce(lambda x, y: x | y, [Q(channel__contains=word) for word in channels_filtered]))
else:
ob_list_channelsremoved=Ondemand_Titles.objects.all()
config = RequestConfig(request,paginate={"per_page":40 })
table1= OndemandTable(ob_list_channelsremoved)
config.configure(table1)
return render(request, 'ondemand.html', {'table1':table1,'current_date':now,})
示例7: get
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
config = RequestConfig(request)
table = self.table_class(self.object_list)
config.configure(table)
table.paginate(page=request.GET.get('page', 1), per_page=self.table_pagination)
context[self.context_table_name] = table
return self.render_to_response(context)
示例8: coordinate
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def coordinate(request):
all = Interval.objects.all()
coordinates= CoordinateTable(all)
avg_counts = CoordinateTable(Read_alignment.objects.annotate(Avg('read_counts')))
config = RequestConfig(request)
config.configure(coordinates)
config.configure(avg_counts)
return render(request,"srb/coordinate.html",{'coordinates':coordinates,'avg_counts':avg_counts })
示例9: get_queryset
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def get_queryset(self):
queryset = super(SelectRelatedMixin, self).get_queryset()
config = RequestConfig(self.request)
user = User.objects.get(pk=self.request.user.id)
customer = HistoryTable(queryset.select_related(*self.select_related).filter(customer=user.customer))
config.configure(customer)
return customer
示例10: query_custom
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def query_custom(request):
try:
content_type = Query.get_content_type(request.GET.get("entity"))
except InvalidContentTypeError as e:
messages.error(request, e)
raise Http404()
if content_type.model_class() not in QueryCondition.RELATION_MAP:
messages.error(
request,
"Wrong table name in entity param. Please refer to query docs.")
raise Http404()
try:
conditions = Query.parse_conditions(content_type,
request.GET.get("conditions"))
except InvalidConditionsError as e:
messages.error(request, e)
raise Http404()
view = QueryCustomResultView(
content_type=content_type,
conditions=conditions,
request=request,
model=content_type.model_class(),
table_class=QUERY_CONTENT_TYPE_TABLE[content_type.model_class()]
)
try:
table = QUERY_CONTENT_TYPE_TABLE[content_type.model_class()](
None,
request.user,
view.get_table_data()
)
except (FieldDoesNotExist, FieldError) as e:
messages.error(request, e)
raise Http404()
config = RequestConfig(request, paginate={"per_page": table.length})
config.configure(table)
template = loader.get_template('lava_results_app/query_custom.html')
return HttpResponse(template.render(
{
'query_table': table,
'conditions': conditions,
'terms_data': table.prepare_terms_data(view),
'search_data': table.prepare_search_data(view),
'discrete_data': table.prepare_discrete_data(view),
'bread_crumb_trail': BreadCrumbTrail.leading_to(query_custom),
'context_help': ['lava-queries-charts'],
}, request=request)
)
示例11: equipments
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def equipments(request):
q = request.GET.get('q')
if ( q is None ) :
table = EquipmentTable(Equipment.objects.all())
q=''
else:
table = EquipmentTable(Equipment.objects.filter(Q(serial_number__exact=q) | Q(location_business_name__contains=q)))
config = RequestConfig(request, paginate={"per_page": 10})
config.configure(table)
return render(request, "ems/equipment_table.html", {"table": table, 'search_var':q})
示例12: inventoryOrderReportsView
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def inventoryOrderReportsView(request, pk=None):
permissions = get_object_or_404(UserPermissions, user=request.user)
order = get_object_or_404(InventoryOrder, pk=pk)
order_reports = InventoryRoomReportTable(InventoryRoomReport.objects.filter(order=order), prefix='rr-')
done_rooms = InventoryRoomReport.objects.filter(order=order).values_list('room__id', flat=True)
remaining_rooms = RoomTableNoEdit(Room.objects.exclude(id__in=done_rooms), prefix='r-')
config = RequestConfig(request)
config.configure(order_reports)
config.configure(remaining_rooms)
return render(request, 'inventoryOrderReports.html', { 'permissions' : permissions , 'order_reports' : order_reports , 'remaining_rooms' : remaining_rooms , 'order' : order , 'finish' : Room.objects.exclude(id__in=done_rooms).exists() })
示例13: addressDetailView
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def addressDetailView(request, pk=None):
if pk:
address = get_object_or_404(Address, id=pk)
permissions = get_object_or_404(UserPermissions, user=request.user)
if permissions.is_admin:
rooms = RoomTable(Room.objects.filter(address=address), prefix='r-')
else:
rooms = RoomTableNoEdit(Room.objects.filter(address=address), prefix='r-')
entries = EntryTable(Entry.objects.filter(room__address=address), prefix='e-')
config = RequestConfig(request)
config.configure(rooms)
config.configure(entries)
return render(request, 'addressDetails.html', { 'address' : address , 'rooms' : rooms , 'entries' : entries })
return HttpResponseRedirect(reverse('address'))
示例14: result
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def result(request, task_id=None):
# read from celery the results
# save CSV file
task_results = celery_app.AsyncResult(task_id).get()
scoring_df = pd.read_csv(StringIO(task_results))
scoring_df = scoring_df.fillna('')
scoring_results_table = ScoringTable(scoring_df.to_dict('records'))
config = RequestConfig(request)
config.paginate = False
config.configure(scoring_results_table)
return render_to_response('review_scoring/result.html',
{"scoring_results": scoring_results_table,
"task_id": task_id,
"scoring_plot": create_html_plot_tooltip(scoring_df)},
context_instance=RequestContext(request))
示例15: query_display
# 需要导入模块: from django_tables2 import RequestConfig [as 别名]
# 或者: from django_tables2.RequestConfig import configure [as 别名]
def query_display(request, username, name):
query = get_object_or_404(Query, owner__username=username, name=name)
if not request.user.is_superuser:
if not query.is_published and query.owner != request.user:
raise PermissionDenied
view = QueryResultView(
query=query,
request=request,
model=query.content_type.model_class(),
table_class=QUERY_CONTENT_TYPE_TABLE[query.content_type.model_class()]
)
table = QUERY_CONTENT_TYPE_TABLE[query.content_type.model_class()](
query,
request.user,
view.get_table_data()
)
try:
config = RequestConfig(request, paginate={"per_page": table.length})
config.configure(table)
except ProgrammingError:
raise QueryViewDoesNotExistError(
"Query view does not exist. Please contact query owner or system "
"administrator.")
omitted = [result.content_object for result in QueryOmitResult.objects.filter(query=query)]
template = loader.get_template('lava_results_app/query_display.html')
return HttpResponse(template.render(
{
'query': query,
'entity': query.content_type.model,
'conditions': Query.serialize_conditions(
query.querycondition_set.all()),
'omitted': omitted,
'query_table': table,
'terms_data': table.prepare_terms_data(view),
'search_data': table.prepare_search_data(view),
'discrete_data': table.prepare_discrete_data(view),
'bread_crumb_trail': BreadCrumbTrail.leading_to(
query_display, username=username, name=name),
'context_help': ['lava-queries-charts'],
}, request=request)
)