PEP8 cleanups.

This commit is contained in:
Roberto Rosario
2015-07-27 23:53:14 -04:00
parent 0b923a7a1c
commit 1e746c700a
101 changed files with 3244 additions and 892 deletions
+37 -6
View File
@@ -41,10 +41,41 @@ class LinkingApp(MayanAppConfig):
)
)
menu_facet.bind_links(links=[link_smart_link_instances_for_document], sources=[Document])
menu_object.bind_links(links=[link_smart_link_condition_edit, link_smart_link_condition_delete], sources=[SmartLinkCondition])
menu_object.bind_links(links=[link_smart_link_edit, link_smart_link_document_types, link_smart_link_condition_list, link_acl_list, link_smart_link_delete], sources=[SmartLink])
menu_object.bind_links(links=[link_smart_link_instance_view], sources=[ResolvedSmartLink])
menu_secondary.bind_links(links=[link_smart_link_list, link_smart_link_create], sources=[SmartLink, 'linking:smart_link_list', 'linking:smart_link_create'])
menu_facet.bind_links(
links=[link_smart_link_instances_for_document],
sources=[Document]
)
menu_object.bind_links(
links=[
link_smart_link_condition_edit,
link_smart_link_condition_delete
], sources=[SmartLinkCondition]
)
menu_object.bind_links(
links=[
link_smart_link_edit, link_smart_link_document_types,
link_smart_link_condition_list, link_acl_list,
link_smart_link_delete
], sources=[SmartLink]
)
menu_object.bind_links(
links=[link_smart_link_instance_view],
sources=[ResolvedSmartLink]
)
menu_secondary.bind_links(
links=[link_smart_link_list, link_smart_link_create],
sources=[
SmartLink, 'linking:smart_link_list',
'linking:smart_link_create'
]
)
menu_setup.bind_links(links=[link_smart_link_setup])
menu_sidebar.bind_links(links=[link_smart_link_condition_create], sources=['linking:smart_link_condition_list', 'linking:smart_link_condition_create', 'linking:smart_link_condition_edit', 'linking:smart_link_condition_delete'])
menu_sidebar.bind_links(
links=[link_smart_link_condition_create],
sources=[
'linking:smart_link_condition_list',
'linking:smart_link_condition_create',
'linking:smart_link_condition_edit',
'linking:smart_link_condition_delete'
]
)
+21 -3
View File
@@ -12,7 +12,14 @@ from .models import SmartLink, SmartLinkCondition
class SmartLinkForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(SmartLinkForm, self).__init__(*args, **kwargs)
self.fields['dynamic_label'].help_text = ' '.join([unicode(self.fields['dynamic_label'].help_text), ModelAttribute.help_text_for(Document, type_names=['field', 'related', 'property'])])
self.fields['dynamic_label'].help_text = ' '.join(
[
unicode(self.fields['dynamic_label'].help_text),
ModelAttribute.help_text_for(
Document, type_names=['field', 'related', 'property']
)
]
)
class Meta:
fields = ('label', 'dynamic_label', 'enabled')
@@ -22,8 +29,19 @@ class SmartLinkForm(forms.ModelForm):
class SmartLinkConditionForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(SmartLinkConditionForm, self).__init__(*args, **kwargs)
self.fields['foreign_document_data'] = forms.ChoiceField(choices=ModelAttribute.get_choices_for(Document, type_names=['field', 'query']), label=_('Foreign document attribute'))
self.fields['expression'].help_text = ' '.join([unicode(self.fields['expression'].help_text), ModelAttribute.help_text_for(Document, type_names=['field', 'related', 'property'])])
self.fields['foreign_document_data'] = forms.ChoiceField(
choices=ModelAttribute.get_choices_for(
Document, type_names=['field', 'query']
), label=_('Foreign document attribute')
)
self.fields['expression'].help_text = ' '.join(
[
unicode(self.fields['expression'].help_text),
ModelAttribute.help_text_for(
Document, type_names=['field', 'related', 'property']
)
]
)
class Meta:
model = SmartLinkCondition
+51 -12
View File
@@ -10,15 +10,54 @@ from .permissions import (
permission_smart_link_edit, permission_smart_link_view
)
link_smart_link_condition_create = Link(permissions=[permission_smart_link_edit], text=_('Create condition'), view='linking:smart_link_condition_create', args='object.pk')
link_smart_link_condition_delete = Link(permissions=[permission_smart_link_edit], tags='dangerous', text=_('Delete'), view='linking:smart_link_condition_delete', args='resolved_object.pk')
link_smart_link_condition_edit = Link(permissions=[permission_smart_link_edit], text=_('Edit'), view='linking:smart_link_condition_edit', args='resolved_object.pk')
link_smart_link_condition_list = Link(permissions=[permission_smart_link_edit], text=_('Conditions'), view='linking:smart_link_condition_list', args='object.pk')
link_smart_link_create = Link(permissions=[permission_smart_link_create], text=_('Create new smart link'), view='linking:smart_link_create')
link_smart_link_delete = Link(permissions=[permission_smart_link_delete], tags='dangerous', text=_('Delete'), view='linking:smart_link_delete', args='object.pk')
link_smart_link_document_types = Link(permissions=[permission_smart_link_edit], text=_('Document types'), view='linking:smart_link_document_types', args='object.pk')
link_smart_link_edit = Link(permissions=[permission_smart_link_edit], text=_('Edit'), view='linking:smart_link_edit', args='object.pk')
link_smart_link_instance_view = Link(permissions=[permission_smart_link_view], text=_('Documents'), view='linking:smart_link_instance_view', args=['document.pk', 'object.pk'])
link_smart_link_instances_for_document = Link(permissions=[permission_document_view], text=_('Smart links'), view='linking:smart_link_instances_for_document', args='object.pk')
link_smart_link_list = Link(permissions=[permission_smart_link_create], text=_('Smart links'), view='linking:smart_link_list')
link_smart_link_setup = Link(icon='fa fa-link', permissions=[permission_smart_link_create], text=_('Smart links'), view='linking:smart_link_list')
link_smart_link_condition_create = Link(
permissions=[permission_smart_link_edit], text=_('Create condition'),
view='linking:smart_link_condition_create', args='object.pk'
)
link_smart_link_condition_delete = Link(
permissions=[permission_smart_link_edit], tags='dangerous',
text=_('Delete'), view='linking:smart_link_condition_delete',
args='resolved_object.pk'
)
link_smart_link_condition_edit = Link(
permissions=[permission_smart_link_edit], text=_('Edit'),
view='linking:smart_link_condition_edit', args='resolved_object.pk'
)
link_smart_link_condition_list = Link(
permissions=[permission_smart_link_edit], text=_('Conditions'),
view='linking:smart_link_condition_list', args='object.pk'
)
link_smart_link_create = Link(
permissions=[permission_smart_link_create],
text=_('Create new smart link'), view='linking:smart_link_create'
)
link_smart_link_delete = Link(
permissions=[permission_smart_link_delete], tags='dangerous',
text=_('Delete'), view='linking:smart_link_delete', args='object.pk'
)
link_smart_link_document_types = Link(
permissions=[permission_smart_link_edit], text=_('Document types'),
view='linking:smart_link_document_types', args='object.pk'
)
link_smart_link_edit = Link(
permissions=[permission_smart_link_edit], text=_('Edit'),
view='linking:smart_link_edit', args='object.pk'
)
link_smart_link_instance_view = Link(
permissions=[permission_smart_link_view], text=_('Documents'),
view='linking:smart_link_instance_view', args=[
'document.pk', 'object.pk'
]
)
link_smart_link_instances_for_document = Link(
permissions=[permission_document_view], text=_('Smart links'),
view='linking:smart_link_instances_for_document', args='object.pk'
)
link_smart_link_list = Link(
permissions=[permission_smart_link_create], text=_('Smart links'),
view='linking:smart_link_list'
)
link_smart_link_setup = Link(
icon='fa fa-link', permissions=[permission_smart_link_create],
text=_('Smart links'), view='linking:smart_link_list'
)
+52 -12
View File
@@ -15,9 +15,16 @@ from .literals import (
@python_2_unicode_compatible
class SmartLink(models.Model):
label = models.CharField(max_length=96, verbose_name=_('Label'))
dynamic_label = models.CharField(blank=True, max_length=96, help_text=_('This expression will be evaluated against the current selected document.'), verbose_name=_('Dynamic label'))
dynamic_label = models.CharField(
blank=True, max_length=96, help_text=_(
'This expression will be evaluated against the current selected '
'document.'
), verbose_name=_('Dynamic label')
)
enabled = models.BooleanField(default=True, verbose_name=_('Enabled'))
document_types = models.ManyToManyField(DocumentType, verbose_name=_('Document types'))
document_types = models.ManyToManyField(
DocumentType, verbose_name=_('Document types')
)
def __str__(self):
return self.label
@@ -27,19 +34,30 @@ class SmartLink(models.Model):
try:
return eval(self.dynamic_label, {'document': document})
except Exception as exception:
return Exception(_('Error generating dynamic label; %s' % unicode(exception)))
return Exception(
_(
'Error generating dynamic label; %s' % unicode(exception)
)
)
else:
return self.label
def get_linked_document_for(self, document):
if document.document_type.pk not in self.document_types.values_list('pk', flat=True):
raise Exception(_('This smart link is not allowed for the selected document\'s type.'))
raise Exception(
_(
'This smart link is not allowed for the selected '
'document\'s type.'
)
)
smart_link_query = Q()
for condition in self.conditions.filter(enabled=True):
condition_query = Q(**{
'%s__%s' % (condition.foreign_document_data, condition.operator): eval(condition.expression, {'document': document})
'%s__%s' % (
condition.foreign_document_data, condition.operator
): eval(condition.expression, {'document': document})
})
if condition.negated:
condition_query = ~condition_query
@@ -55,7 +73,9 @@ class SmartLink(models.Model):
return Document.objects.none()
def resolve_for(self, document):
return ResolvedSmartLink(smart_link=self, queryset=self.get_linked_document_for(document))
return ResolvedSmartLink(
smart_link=self, queryset=self.get_linked_document_for(document)
)
class Meta:
verbose_name = _('Smart link')
@@ -69,16 +89,36 @@ class ResolvedSmartLink(SmartLink):
@python_2_unicode_compatible
class SmartLinkCondition(models.Model):
smart_link = models.ForeignKey(SmartLink, related_name='conditions', verbose_name=_('Smart link'))
inclusion = models.CharField(choices=INCLUSION_CHOICES, default=INCLUSION_AND, help_text=_('The inclusion is ignored for the first item.'), max_length=16)
foreign_document_data = models.CharField(help_text=_('This represents the metadata of all other documents.'), max_length=128, verbose_name=_('Foreign document attribute'))
smart_link = models.ForeignKey(
SmartLink, related_name='conditions', verbose_name=_('Smart link')
)
inclusion = models.CharField(
choices=INCLUSION_CHOICES, default=INCLUSION_AND,
help_text=_('The inclusion is ignored for the first item.'),
max_length=16
)
foreign_document_data = models.CharField(
help_text=_('This represents the metadata of all other documents.'),
max_length=128, verbose_name=_('Foreign document attribute')
)
operator = models.CharField(choices=OPERATOR_CHOICES, max_length=16)
expression = models.TextField(help_text=_('This expression will be evaluated against the current document.'), verbose_name=_('Expression'))
negated = models.BooleanField(default=False, help_text=_('Inverts the logic of the operator.'), verbose_name=_('Negated'))
expression = models.TextField(
help_text=_(
'This expression will be evaluated against the current document.'
), verbose_name=_('Expression')
)
negated = models.BooleanField(
default=False, help_text=_('Inverts the logic of the operator.'),
verbose_name=_('Negated')
)
enabled = models.BooleanField(default=True, verbose_name=_('Enabled'))
def __str__(self):
return '%s foreign %s %s %s %s' % (self.get_inclusion_display(), self.foreign_document_data, _('not') if self.negated else '', self.get_operator_display(), self.expression)
return '%s foreign %s %s %s %s' % (
self.get_inclusion_display(),
self.foreign_document_data, _('not') if self.negated else '',
self.get_operator_display(), self.expression
)
class Meta:
verbose_name = _('Link condition')
+12 -4
View File
@@ -6,7 +6,15 @@ from permissions import PermissionNamespace
namespace = PermissionNamespace('linking', _('Smart links'))
permission_smart_link_view = namespace.add_permission(name='smart_link_view', label=_('View existing smart links'))
permission_smart_link_create = namespace.add_permission(name='smart_link_create', label=_('Create new smart links'))
permission_smart_link_delete = namespace.add_permission(name='smart_link_delete', label=_('Delete smart links'))
permission_smart_link_edit = namespace.add_permission(name='smart_link_edit', label=_('Edit smart links'))
permission_smart_link_view = namespace.add_permission(
name='smart_link_view', label=_('View existing smart links')
)
permission_smart_link_create = namespace.add_permission(
name='smart_link_create', label=_('Create new smart links')
)
permission_smart_link_delete = namespace.add_permission(
name='smart_link_delete', label=_('Delete smart links')
)
permission_smart_link_edit = namespace.add_permission(
name='smart_link_edit', label=_('Edit smart links')
)
+40 -10
View File
@@ -9,17 +9,47 @@ from .views import (
urlpatterns = patterns(
'linking.views',
url(r'^document/(?P<pk>\d+)/list/$', DocumentSmartLinkListView.as_view(), name='smart_link_instances_for_document'),
url(r'^document/(?P<document_pk>\d+)/(?P<smart_link_pk>\d+)/$', ResolvedSmartLinkView.as_view(), name='smart_link_instance_view'),
url(
r'^document/(?P<pk>\d+)/list/$', DocumentSmartLinkListView.as_view(),
name='smart_link_instances_for_document'
),
url(
r'^document/(?P<document_pk>\d+)/(?P<smart_link_pk>\d+)/$',
ResolvedSmartLinkView.as_view(), name='smart_link_instance_view'
),
url(r'^setup/list/$', SmartLinkListView.as_view(), name='smart_link_list'),
url(
r'^setup/list/$', SmartLinkListView.as_view(), name='smart_link_list'
),
url(r'^setup/create/$', 'smart_link_create', name='smart_link_create'),
url(r'^setup/(?P<smart_link_pk>\d+)/delete/$', 'smart_link_delete', name='smart_link_delete'),
url(r'^setup/(?P<smart_link_pk>\d+)/edit/$', 'smart_link_edit', name='smart_link_edit'),
url(r'^setup/(?P<pk>\d+)/document_types/$', SetupSmartLinkDocumentTypesView.as_view(), name='smart_link_document_types'),
url(
r'^setup/(?P<smart_link_pk>\d+)/delete/$', 'smart_link_delete',
name='smart_link_delete'
),
url(
r'^setup/(?P<smart_link_pk>\d+)/edit/$', 'smart_link_edit',
name='smart_link_edit'
),
url(
r'^setup/(?P<pk>\d+)/document_types/$',
SetupSmartLinkDocumentTypesView.as_view(),
name='smart_link_document_types'
),
url(r'^setup/(?P<smart_link_pk>\d+)/condition/list/$', 'smart_link_condition_list', name='smart_link_condition_list'),
url(r'^setup/(?P<smart_link_pk>\d+)/condition/create/$', 'smart_link_condition_create', name='smart_link_condition_create'),
url(r'^setup/smart_link/condition/(?P<smart_link_condition_pk>\d+)/edit/$', 'smart_link_condition_edit', name='smart_link_condition_edit'),
url(r'^setup/smart_link/condition/(?P<smart_link_condition_pk>\d+)/delete/$', 'smart_link_condition_delete', name='smart_link_condition_delete'),
url(
r'^setup/(?P<smart_link_pk>\d+)/condition/list/$',
'smart_link_condition_list', name='smart_link_condition_list'
),
url(
r'^setup/(?P<smart_link_pk>\d+)/condition/create/$',
'smart_link_condition_create', name='smart_link_condition_create'
),
url(
r'^setup/smart_link/condition/(?P<smart_link_condition_pk>\d+)/edit/$',
'smart_link_condition_edit', name='smart_link_condition_edit'
),
url(
r'^setup/smart_link/condition/(?P<smart_link_condition_pk>\d+)/delete/$',
'smart_link_condition_delete', name='smart_link_condition_delete'
),
)
+178 -52
View File
@@ -43,19 +43,29 @@ class SetupSmartLinkDocumentTypesView(AssignRemoveView):
return get_object_or_404(SmartLink, pk=self.kwargs['pk'])
def left_list(self):
return AssignRemoveView.generate_choices(DocumentType.objects.exclude(pk__in=self.get_object().document_types.all()))
return AssignRemoveView.generate_choices(
DocumentType.objects.exclude(
pk__in=self.get_object().document_types.all()
)
)
def right_list(self):
return AssignRemoveView.generate_choices(self.get_object().document_types.all())
return AssignRemoveView.generate_choices(
self.get_object().document_types.all()
)
def remove(self, item):
self.get_object().document_types.remove(item)
def get_context_data(self, **kwargs):
data = super(SetupSmartLinkDocumentTypesView, self).get_context_data(**kwargs)
data = super(
SetupSmartLinkDocumentTypesView, self
).get_context_data(**kwargs)
data.update({
'object': self.get_object(),
'title': _('Document type for which to enable smart link: %s') % self.get_object(),
'title': _(
'Document type for which to enable smart link: %s'
) % self.get_object(),
})
return data
@@ -63,20 +73,34 @@ class SetupSmartLinkDocumentTypesView(AssignRemoveView):
class ResolvedSmartLinkView(DocumentListView):
def dispatch(self, request, *args, **kwargs):
self.document = get_object_or_404(Document, pk=self.kwargs['document_pk'])
self.smart_link = get_object_or_404(SmartLink, pk=self.kwargs['smart_link_pk'])
self.document = get_object_or_404(
Document, pk=self.kwargs['document_pk']
)
self.smart_link = get_object_or_404(
SmartLink, pk=self.kwargs['smart_link_pk']
)
try:
Permission.check_permissions(request.user, [permission_document_view])
Permission.check_permissions(
request.user, [permission_document_view]
)
except PermissionDenied:
AccessControlList.objects.check_access(permission_document_view, request.user, self.document)
AccessControlList.objects.check_access(
permission_document_view, request.user, self.document
)
try:
Permission.check_permissions(request.user, [permission_smart_link_view])
Permission.check_permissions(
request.user, [permission_smart_link_view]
)
except PermissionDenied:
AccessControlList.objects.check_access(permission_smart_link_view, request.user, self.smart_link)
AccessControlList.objects.check_access(
permission_smart_link_view, request.user, self.smart_link
)
return super(ResolvedSmartLinkView, self).dispatch(request, *args, **kwargs)
return super(
ResolvedSmartLinkView, self
).dispatch(request, *args, **kwargs)
def get_document_queryset(self):
try:
@@ -85,7 +109,9 @@ class ResolvedSmartLinkView(DocumentListView):
queryset = Document.objects.none()
if self.request.user.is_staff or self.request.user.is_superuser:
messages.error(self.request, _('Smart link query error: %s' % exception))
messages.error(
self.request, _('Smart link query error: %s' % exception)
)
return queryset
@@ -93,7 +119,10 @@ class ResolvedSmartLinkView(DocumentListView):
return {
'hide_links': True,
'object': self.document,
'title': _('Documents in smart link "%(smart_link)s" as relation to "%(document)s"') % {
'title': _(
'Documents in smart link "%(smart_link)s" as relation to '
'"%(document)s"'
) % {
'document': self.document,
'smart_link': self.smart_link.get_dynamic_label(self.document),
}
@@ -114,7 +143,11 @@ class SmartLinkListView(SingleObjectListView):
return {
'extra_columns': [
{'name': _('Dynamic label'), 'attribute': 'dynamic_label'},
{'name': _('Enabled'), 'attribute': encapsulate(lambda instance: two_state_template(instance.enabled))},
{
'name': _('Enabled'), 'attribute': encapsulate(
lambda instance: two_state_template(instance.enabled)
)
},
],
'hide_link': True,
'title': _('Smart links'),
@@ -126,20 +159,34 @@ class DocumentSmartLinkListView(SmartLinkListView):
self.document = get_object_or_404(Document, pk=self.kwargs['pk'])
try:
Permission.check_permissions(request.user, (permission_document_view,))
Permission.check_permissions(
request.user, (permission_document_view,)
)
except PermissionDenied:
AccessControlList.objects.check_permissions(permission_document_view, request.user, self.document)
AccessControlList.objects.check_permissions(
permission_document_view, request.user, self.document
)
return super(DocumentSmartLinkListView, self).dispatch(request, *args, **kwargs)
return super(
DocumentSmartLinkListView, self
).dispatch(request, *args, **kwargs)
def get_smart_link_queryset(self):
return ResolvedSmartLink.objects.filter(document_types=self.document.document_type, enabled=True)
return ResolvedSmartLink.objects.filter(
document_types=self.document.document_type, enabled=True
)
def get_extra_context(self):
return {
'document': self.document,
'extra_columns': (
{'name': _('Label'), 'attribute': encapsulate(lambda smart_link: smart_link.get_dynamic_label(self.document))},
{
'name': _('Label'), 'attribute': encapsulate(
lambda smart_link: smart_link.get_dynamic_label(
self.document
)
)
},
),
'hide_object': True,
'hide_link': True,
@@ -149,13 +196,19 @@ class DocumentSmartLinkListView(SmartLinkListView):
def smart_link_create(request):
Permission.check_permissions(request.user, [permission_smart_link_create])
Permission.check_permissions(
request.user, [permission_smart_link_create]
)
if request.method == 'POST':
form = SmartLinkForm(request.POST)
if form.is_valid():
document_group = form.save()
messages.success(request, _('Smart link: %s created successfully.') % document_group)
messages.success(
request, _(
'Smart link: %s created successfully.'
) % document_group
)
return HttpResponseRedirect(reverse('linking:smart_link_list'))
else:
form = SmartLinkForm()
@@ -170,15 +223,23 @@ def smart_link_edit(request, smart_link_pk):
smart_link = get_object_or_404(SmartLink, pk=smart_link_pk)
try:
Permission.check_permissions(request.user, [permission_smart_link_edit])
Permission.check_permissions(
request.user, [permission_smart_link_edit]
)
except PermissionDenied:
AccessControlList.objects.check_access(permission_smart_link_edit, request.user, smart_link)
AccessControlList.objects.check_access(
permission_smart_link_edit, request.user, smart_link
)
if request.method == 'POST':
form = SmartLinkForm(request.POST, instance=smart_link)
if form.is_valid():
smart_link = form.save()
messages.success(request, _('Smart link: %s edited successfully.') % smart_link)
messages.success(
request, _(
'Smart link: %s edited successfully.'
) % smart_link
)
return HttpResponseRedirect(reverse('linking:smart_link_list'))
else:
form = SmartLinkForm(instance=smart_link)
@@ -194,22 +255,39 @@ def smart_link_delete(request, smart_link_pk):
smart_link = get_object_or_404(SmartLink, pk=smart_link_pk)
try:
Permission.check_permissions(request.user, [permission_smart_link_delete])
Permission.check_permissions(
request.user, [permission_smart_link_delete]
)
except PermissionDenied:
AccessControlList.objects.check_access(permission_smart_link_delete, request.user, smart_link)
AccessControlList.objects.check_access(
permission_smart_link_delete, request.user, smart_link
)
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
next = request.POST.get(
'next', request.GET.get('next', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL)))
)
previous = request.POST.get(
'previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL)))
)
if request.method == 'POST':
try:
smart_link.delete()
messages.success(request, _('Smart link: %s deleted successfully.') % smart_link)
messages.success(
request, _(
'Smart link: %s deleted successfully.'
) % smart_link
)
except Exception as exception:
messages.error(request, _('Error deleting smart link: %(smart_link)s; %(exception)s.') % {
'smart_link': smart_link,
'exception': exception
})
messages.error(
request, _(
'Error deleting smart link: %(smart_link)s; '
'%(exception)s.'
) % {
'smart_link': smart_link,
'exception': exception
}
)
return HttpResponseRedirect(next)
return render_to_response('appearance/generic_confirm.html', {
@@ -225,15 +303,24 @@ def smart_link_condition_list(request, smart_link_pk):
smart_link = get_object_or_404(SmartLink, pk=smart_link_pk)
try:
Permission.check_permissions(request.user, [permission_smart_link_edit])
Permission.check_permissions(
request.user, [permission_smart_link_edit]
)
except PermissionDenied:
AccessControlList.objects.check_access([permission_smart_link_edit], request.user, smart_link)
AccessControlList.objects.check_access(
[permission_smart_link_edit], request.user, smart_link
)
return render_to_response('appearance/generic_list.html', {
'title': _('Conditions for smart link: %s') % smart_link,
'object_list': smart_link.conditions.all(),
'extra_columns': [
{'name': _('Enabled'), 'attribute': encapsulate(lambda x: two_state_template(x.enabled))},
{
'name': _('Enabled'),
'attribute': encapsulate(
lambda x: two_state_template(x.enabled)
)
},
],
'hide_link': True,
'object': smart_link,
@@ -244,9 +331,13 @@ def smart_link_condition_create(request, smart_link_pk):
smart_link = get_object_or_404(SmartLink, pk=smart_link_pk)
try:
Permission.check_permissions(request.user, [permission_smart_link_edit])
Permission.check_permissions(
request.user, [permission_smart_link_edit]
)
except PermissionDenied:
AccessControlList.objects.check_access([permission_smart_link_edit], request.user, smart_link)
AccessControlList.objects.check_access(
[permission_smart_link_edit], request.user, smart_link
)
if request.method == 'POST':
form = SmartLinkConditionForm(data=request.POST)
@@ -254,8 +345,16 @@ def smart_link_condition_create(request, smart_link_pk):
new_smart_link_condition = form.save(commit=False)
new_smart_link_condition.smart_link = smart_link
new_smart_link_condition.save()
messages.success(request, _('Smart link condition: "%s" created successfully.') % new_smart_link_condition)
return HttpResponseRedirect(reverse('linking:smart_link_condition_list', args=[smart_link.pk]))
messages.success(
request, _(
'Smart link condition: "%s" created successfully.'
) % new_smart_link_condition
)
return HttpResponseRedirect(
reverse(
'linking:smart_link_condition_list', args=[smart_link.pk]
)
)
else:
form = SmartLinkConditionForm()
@@ -267,21 +366,34 @@ def smart_link_condition_create(request, smart_link_pk):
def smart_link_condition_edit(request, smart_link_condition_pk):
smart_link_condition = get_object_or_404(SmartLinkCondition, pk=smart_link_condition_pk)
smart_link_condition = get_object_or_404(
SmartLinkCondition, pk=smart_link_condition_pk
)
try:
Permission.check_permissions(request.user, [permission_smart_link_edit])
Permission.check_permissions(
request.user, [permission_smart_link_edit]
)
except PermissionDenied:
AccessControlList.objects.check_access([permission_smart_link_edit], request.user, smart_link_condition.smart_link)
AccessControlList.objects.check_access(
[permission_smart_link_edit], request.user,
smart_link_condition.smart_link
)
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
if request.method == 'POST':
form = SmartLinkConditionForm(request.POST, instance=smart_link_condition)
form = SmartLinkConditionForm(
request.POST, instance=smart_link_condition
)
if form.is_valid():
smart_link_condition = form.save()
messages.success(request, _('Smart link condition: "%s" edited successfully.') % smart_link_condition)
messages.success(
request, _(
'Smart link condition: "%s" edited successfully.'
) % smart_link_condition
)
return HttpResponseRedirect(next)
else:
form = SmartLinkConditionForm(instance=smart_link_condition)
@@ -298,12 +410,17 @@ def smart_link_condition_edit(request, smart_link_condition_pk):
def smart_link_condition_delete(request, smart_link_condition_pk):
smart_link_condition = get_object_or_404(SmartLinkCondition, pk=smart_link_condition_pk)
smart_link_condition = get_object_or_404(
SmartLinkCondition, pk=smart_link_condition_pk
)
try:
Permission.check_permissions(request.user, [permission_smart_link_edit])
except PermissionDenied:
AccessControlList.objects.check_access([permission_smart_link_edit], request.user, smart_link_condition.smart_link)
AccessControlList.objects.check_access(
[permission_smart_link_edit], request.user,
smart_link_condition.smart_link
)
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL))))
@@ -311,12 +428,21 @@ def smart_link_condition_delete(request, smart_link_condition_pk):
if request.method == 'POST':
try:
smart_link_condition.delete()
messages.success(request, _('Smart link condition: "%s" deleted successfully.') % smart_link_condition)
messages.success(
request, _(
'Smart link condition: "%s" deleted successfully.'
) % smart_link_condition
)
except Exception as exception:
messages.error(request, _('Error deleting smart link condition: %(smart_link_condition)s; %(exception)s.') % {
'smart_link_condition': smart_link_condition,
'exception': exception
})
messages.error(
request, _(
'Error deleting smart link condition: '
'%(smart_link_condition)s; %(exception)s.'
) % {
'smart_link_condition': smart_link_condition,
'exception': exception
}
)
return HttpResponseRedirect(next)
return render_to_response('appearance/generic_confirm.html', {