本文整理汇总了Python中mkt.site.utils.render函数的典型用法代码示例。如果您正苦于以下问题:Python render函数的具体用法?Python render怎么用?Python render使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: payments
def payments(request, addon_id, addon, webapp=False):
premium_form = forms_payments.PremiumForm(
request.POST or None, request=request, addon=addon,
user=request.user)
region_form = forms.RegionForm(
request.POST or None, product=addon, request=request)
if request.method == 'POST':
if region_form.is_valid() and premium_form.is_valid():
region_form.save()
premium_form.save()
messages.success(request, _('Changes successfully saved.'))
return redirect(addon.get_dev_url('payments'))
return render(request, 'developers/payments/premium.html',
{'addon': addon, 'webapp': webapp,
'region_form': region_form,
'is_paid': (addon.premium_type in mkt.ADDON_PREMIUMS or
addon.premium_type == mkt.ADDON_FREE_INAPP),
'form': premium_form,
'is_fxos': DEVICE_GAIA.id in (
addon.addondevicetype_set.values_list('device_type',
flat=True)),
'PLATFORMS_NAMES': PLATFORMS_NAMES})
示例2: moderatelog_detail
def moderatelog_detail(request, eventlog_id):
log = get_object_or_404(
ActivityLog.objects.editor_events(), pk=eventlog_id)
review = None
if len(log.arguments) > 1 and isinstance(log.arguments[1], Review):
review = log.arguments[1]
form = ModerateLogDetailForm(request.POST or None)
is_admin = acl.action_allowed(request, 'ReviewerAdminTools', 'View')
can_undelete = review and review.deleted and (
is_admin or request.user.pk == log.user.pk)
if (request.method == 'POST' and form.is_valid() and
form.cleaned_data['action'] == 'undelete'):
if not can_undelete:
if not review:
raise RuntimeError('Review doesn`t exist.')
elif not review.deleted:
raise RuntimeError('Review isn`t deleted.')
else:
raise PermissionDenied
ReviewerScore.award_moderation_points(
log.user, review.addon, review.id, undo=True)
review.undelete()
return redirect('reviewers.apps.moderatelog.detail', eventlog_id)
data = context(request, log=log, form=form, review=review,
can_undelete=can_undelete)
return render(request, 'reviewers/moderatelog_detail.html', data)
示例3: website_abuse
def website_abuse(request, website):
reports = AbuseReport.objects.filter(website=website).order_by('-created')
total = reports.count()
reports = paginate(request, reports, count=total)
return render(request, 'reviewers/abuse.html',
context(request, item=website, reports=reports,
total=total))
示例4: logs
def logs(request):
data = request.GET.copy()
if not data.get('start') and not data.get('end'):
today = datetime.date.today()
data['start'] = today - datetime.timedelta(days=30)
form = forms.ReviewLogForm(data)
approvals = ActivityLog.objects.review_queue(webapp=True)
if form.is_valid():
data = form.cleaned_data
if data.get('start'):
approvals = approvals.filter(created__gte=data['start'])
if data.get('end'):
approvals = approvals.filter(created__lt=data['end'])
if data.get('search'):
term = data['search']
approvals = approvals.filter(
Q(commentlog__comments__icontains=term) |
Q(applog__addon__name__localized_string__icontains=term) |
Q(applog__addon__app_slug__icontains=term) |
Q(user__display_name__icontains=term) |
Q(user__email__icontains=term)).distinct()
pager = paginate(request, approvals, 50)
data = context(request, form=form, pager=pager, ACTION_DICT=mkt.LOG_BY_ID,
tab='logs')
return render(request, 'reviewers/logs.html', data)
示例5: user_summary
def user_summary(request, user_id):
user = get_object_or_404(UserProfile, pk=user_id)
is_admin = acl.action_allowed(request, 'Users', 'Edit')
app_summary = _app_summary(user.pk)
# All refunds that this user has requested (probably as a consumer).
req = Refund.objects.filter(contribution__user=user)
# All instantly-approved refunds that this user has requested.
appr = req.filter(status=mkt.REFUND_APPROVED_INSTANT)
refund_summary = {'approved': appr.count(),
'requested': req.count()}
user_addons = user.addons.order_by('-created')
user_addons = paginate(request, user_addons, per_page=15)
payment_data = (AddonPaymentData.objects.filter(addon__authors=user)
.values(*AddonPaymentData.address_fields())
.distinct())
# If the user is deleted, get the log detailing the delete.
try:
delete_log = ActivityLog.objects.for_user(user).filter(
action=mkt.LOG.DELETE_USER_LOOKUP.id)[0]
except IndexError:
delete_log = None
group_membership_formset = APIGroupMembershipFormSet()
provider_portals = get_payment_provider_portals(user=user)
return render(request, 'lookup/user_summary.html',
{'account': user, 'app_summary': app_summary,
'delete_form': DeleteUserForm(), 'delete_log': delete_log,
'is_admin': is_admin, 'refund_summary': refund_summary,
'user_addons': user_addons, 'payment_data': payment_data,
'provider_portals': provider_portals,
'group_membership_formset': group_membership_formset})
示例6: app_abuse
def app_abuse(request, addon):
reports = AbuseReport.objects.filter(addon=addon).order_by('-created')
total = reports.count()
reports = paginate(request, reports, count=total)
return render(request, 'reviewers/abuse.html',
context(request, item=addon, reports=reports,
total=total))
示例7: api
def api(request):
roles = request.user.groups.filter(name='Admins').exists()
form = APIConsumerForm()
if roles:
messages.error(request,
_('Users with the admin role cannot use the API.'))
elif request.method == 'POST':
if 'delete' in request.POST:
try:
consumer = Access.objects.get(pk=request.POST.get('consumer'),
user=request.user)
consumer.delete()
except Access.DoesNotExist:
messages.error(request, _('No such API key.'))
else:
access = Access.create_for_user(request.user)
form = APIConsumerForm(request.POST, instance=access)
if form.is_valid():
form.save()
messages.success(request, _('New API key generated.'))
else:
access.delete()
consumers = list(Access.objects.filter(user=request.user))
return render(request, 'developers/api.html',
{'consumers': consumers, 'roles': roles, 'form': form,
'domain': settings.DOMAIN, 'site_url': settings.SITE_URL})
示例8: browse
def browse(request, viewer, key=None, type_='file'):
form = forms.FileCompareForm(request.POST or None, addon=viewer.addon,
initial={'left': viewer.file})
response = check_compare_form(request, form)
if response:
return response
data = setup_viewer(request, viewer.file)
data['viewer'] = viewer
data['poll_url'] = reverse('mkt.files.poll', args=[viewer.file.id])
data['form'] = form
if not viewer.is_extracted():
extract_file(viewer.file.id)
if viewer.is_extracted():
data.update({'status': True, 'files': viewer.get_files()})
key = viewer.get_default(key)
if key not in data['files']:
raise http.Http404
viewer.select(key)
data['key'] = key
binary = viewer.is_binary()
if (not viewer.is_directory() and
(not binary or binary != 'image')):
data['content'] = viewer.read_file()
else:
extract_file.delay(viewer.file.id)
tmpl = 'content' if type_ == 'fragment' else 'viewer'
return render(request, 'fileviewer/%s.html' % tmpl, data)
示例9: authorize
def authorize(request):
if request.method == 'GET' and 'oauth_token' in request.GET:
try:
t = Token.objects.get(token_type=REQUEST_TOKEN,
key=request.GET['oauth_token'])
except Token.DoesNotExist:
log.error('Invalid OAuth request for obtaining user authorization')
return HttpResponse(status=401)
return render(request, 'developers/oauth_authorize.html',
{'app_name': t.creds.app_name,
'oauth_token': request.GET['oauth_token']})
elif request.method == 'POST':
token = request.POST.get('oauth_token')
try:
t = Token.objects.get(token_type=REQUEST_TOKEN,
key=token)
except Token.DoesNotExist:
return HttpResponse(status=401)
if 'grant' in request.POST:
t.user = request.user
t.save()
return HttpResponseRedirect(
urlparams(t.creds.redirect_uri, oauth_token=token,
oauth_verifier=t.verifier))
elif 'deny' in request.POST:
t.delete()
return HttpResponse(status=200)
else:
log.error('Invalid OAuth request for user access authorization')
return HttpResponse(status=401)
示例10: file_validation
def file_validation(request, addon_id, addon, file_id):
file = get_object_or_404(File, id=file_id)
v = addon.get_dev_url('json_file_validation', args=[file.id])
return render(request, 'developers/validation.html',
dict(validate_url=v, filename=file.filename,
timestamp=file.created, addon=addon))
示例11: monitor
def monitor(request, format=None):
# For each check, a boolean pass/fail status to show in the template
status_summary = {}
results = {}
checks = ['memcache', 'libraries', 'elastic', 'package_signer', 'path',
'receipt_signer', 'settings_check', 'solitude']
for check in checks:
with statsd.timer('monitor.%s' % check) as timer:
status, result = getattr(monitors, check)()
# state is a string. If it is empty, that means everything is fine.
status_summary[check] = {'state': not status,
'status': status}
results['%s_results' % check] = result
results['%s_timer' % check] = timer.ms
# If anything broke, send HTTP 500.
status_code = 200 if all(a['state']
for a in status_summary.values()) else 500
if format == '.json':
return HttpResponse(json.dumps(status_summary), status=status_code)
ctx = {}
ctx.update(results)
ctx['status_summary'] = status_summary
return render(request, 'services/monitor.html', ctx, status=status_code)
示例12: api
def api(request):
roles = request.user.groups.filter(name="Admins").exists()
form = APIConsumerForm()
if roles:
messages.error(request, _("Users with the admin role cannot use the API."))
elif request.method == "POST":
if "delete" in request.POST:
try:
consumer = Access.objects.get(pk=request.POST.get("consumer"), user=request.user)
consumer.delete()
except Access.DoesNotExist:
messages.error(request, _("No such API key."))
else:
access = Access.create_for_user(request.user)
form = APIConsumerForm(request.POST, instance=access)
if form.is_valid():
form.save()
messages.success(request, _("New API key generated."))
else:
access.delete()
consumers = list(Access.objects.filter(user=request.user))
return render(
request,
"developers/api.html",
{
"consumers": consumers,
"roles": roles,
"form": form,
"domain": settings.DOMAIN,
"site_url": settings.SITE_URL,
},
)
示例13: validate_app
def validate_app(request):
return render(request, 'developers/validate_app.html', {
'upload_hosted_url':
reverse('mkt.developers.standalone_hosted_upload'),
'upload_packaged_url':
reverse('mkt.developers.standalone_packaged_upload'),
})
示例14: transaction_search
def transaction_search(request):
tx_form = TransactionSearchForm(request.GET)
if tx_form.is_valid():
return redirect(reverse('lookup.transaction_summary',
args=[tx_form.cleaned_data['q']]))
else:
return render(request, 'lookup/home.html', {'tx_form': tx_form})
示例15: in_app_products
def in_app_products(request, addon_id, addon, webapp=True, account=None):
owner = acl.check_addon_ownership(request, addon)
products = addon.inappproduct_set.all()
new_product = InAppProduct(webapp=addon)
form = InAppProductForm()
if addon.origin:
inapp_origin = addon.origin
elif addon.guid:
# Derive a marketplace specific origin out of the GUID.
# This is for apps that do not specify a custom origin.
inapp_origin = 'marketplace:{}'.format(addon.guid)
else:
# Theoretically this is highly unlikely. A hosted app will
# always have a domain and a packaged app will always have
# a generated GUID.
raise TypeError(
'Cannot derive origin: no declared origin, no GUID')
list_url = _fix_origin_link(reverse('in-app-products-list',
kwargs={'origin': inapp_origin}))
detail_url = _fix_origin_link(reverse('in-app-products-detail',
# {guid} is replaced in JS.
kwargs={'origin': inapp_origin,
'guid': "{guid}"}))
return render(request, 'developers/payments/in-app-products.html',
{'addon': addon, 'form': form, 'new_product': new_product,
'owner': owner, 'products': products, 'form': form,
'list_url': list_url, 'detail_url': detail_url,
'active_lang': request.LANG.lower()})