Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_absolute_url(self):
return change_url(self)
def get_instance_url(operation):
try:
url = change_url(operation.instance)
except NoReverseMatch:
alt_repr = '%s-%s' % (operation.content_type, operation.object_id)
return _("Deleted {0}").format(operation.instance_repr or alt_repr)
return orchestra_settings.ORCHESTRA_SITE_URL + url
def display_forwards(self, mailbox):
forwards = []
for addr in mailbox.get_forwards():
url = change_url(addr)
forwards.append('<a href="%s">%s</a>' % (url, addr.email))
return '<br>'.join(forwards)
display_forwards.short_description = _("Forward from")
def display_webapps(self, website):
webapps = []
for content in website.content_set.all():
webapp = content.webapp
url = change_url(webapp)
name = "%s on %s" % (webapp.get_type_display(), content.path or '/')
webapps.append('<a href="%s">%s</a>' % (url, name))
return '<br>'.join(webapps)
display_webapps.allow_tags = True
if request.POST.get('post') == 'generic_confirmation':
formset = SelectSourceFormSet(request.POST, request.FILES, queryset=queryset)
if formset.is_valid():
transactions = []
for form in formset.forms:
source = form.cleaned_data['source']
transaction = form.instance.close(payment=source)
if transaction:
transactions.append(transaction)
for bill in queryset:
modeladmin.log_change(request, bill, 'Closed')
messages.success(request, _("Selected bills have been closed"))
if transactions:
num = len(transactions)
if num == 1:
url = change_url(transactions[0])
else:
url = reverse('admin:payments_transaction_changelist')
url += 'id__in=%s' % ','.join([str(t.id) for t in transactions])
context = {
'url': url,
'num': num,
}
message = ungettext(
_('<a href="%(url)s">One related transaction</a> has been created') % context,
_('<a href="%(url)s">%(num)i related transactions</a> have been created') % context,
num)
messages.success(request, mark_safe(message))
return
opts = modeladmin.model._meta
context = {
'title': _("Are you sure about closing the following bills?"),
def selected_related_choices(queryset):
for order in queryset:
verbose = '<a href="{order_url}">{description}</a> '
verbose += '<a href="{account_url}" class="account">{account}</a>'
if order.ignore:
verbose += ' (ignored)'
verbose = verbose.format(
order_url=change_url(order), description=order.description,
account_url=change_url(order.account), account=str(order.account)
)
yield (order.pk, mark_safe(verbose))
def display_databases(self, user):
links = []
for db in user.databases.all():
link = '<a href="%s">%s</a>' % (change_url(db), db.name)
links.append(link)
return '<br>'.join(links)
display_databases.short_description = _("Databases")
def confirmation(self, request):
form = BillSelectConfirmationForm(initial=self.options)
if int(request.POST.get('step')) >= 3:
bills = self.queryset.bill(commit=True, **self.options)
for order in self.queryset:
self.modeladmin.log_change(request, order, _("Billed"))
if not bills:
msg = _("Selected orders do not have pending billing")
self.modeladmin.message_user(request, msg, messages.WARNING)
else:
num = len(bills)
if num == 1:
url = change_url(bills[0])
else:
url = reverse('admin:bills_bill_changelist')
ids = ','.join([str(b.id) for b in bills])
url += '?id__in=%s' % ids
msg = ungettext(
'<a href="{url}">One bill</a> has been created.',
'<a href="{url}">{num} bills</a> have been created.',
num).format(url=url, num=num)
msg = mark_safe(msg)
self.modeladmin.message_user(request, msg, messages.INFO)
return
bills = self.queryset.bill(commit=False, **self.options)
bills_with_total = []
for account, lines in bills:
total = 0
for line in lines:
def __init__(self, *args, **kwargs):
super(SaaSBaseForm, self).__init__(*args, **kwargs)
self.is_change = bool(self.instance and self.instance.pk)
if self.is_change:
site_domain = self.instance.get_site_domain()
if self.instance.custom_url:
try:
website = self.instance.service_instance.get_website()
except ObjectDoesNotExist:
link = ('<br><span style="color:red"><b>Warning:</b> '
'Related website directive does not exist for %s URL !</span>' %
self.instance.custom_url)
else:
url = change_url(website)
link = '<br>Related website: <a href="%s">%s</a>' % (url, website.name)
self.fields['custom_url'].help_text += link
else:
site_domain = self.plugin.site_domain
context = {
'site_name': '<site_name>',
'name': '<site_name>',
}
site_domain = site_domain % context
if '<site_name>' in site_domain:
site_link = site_domain
else:
site_link = '<a href="http://%s">%s</a>' % (site_domain, site_domain)
self.fields['site_url'].widget.display = site_link
self.fields['name'].label = _("Site name") if '%(' in self.plugin.site_domain else _("Username")
def display_url(self, saas):
site_domain = saas.get_site_domain()
site_link = '<a href="http://%s">%s</a>' % (site_domain, site_domain)
links = [site_link]
if saas.custom_url and isinstalled('orchestra.contrib.websites'):
try:
website = saas.service_instance.get_website()
except ObjectDoesNotExist:
warning = _("Related website directive does not exist for this custom URL.")
link = '<span title="%s" style="color:red">%s</span>' % (warning, saas.custom_url)
else:
website_link = get_on_site_link(saas.custom_url)
admin_url = change_url(website)
link = '<a href="%s" title="Edit website">%s %s</a>' % (
admin_url, saas.custom_url, website_link
)
links.append(link)
return '<br>'.join(links)
display_url.short_description = _("URL")