Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if len(author_form.cleaned_data['profile']) == 0:
# FIXME use form.add_error in django > 1.7
errors = author_form._errors.setdefault(
'profile', ErrorList())
errors.append(
_('You must set an author for this resource'))
metadata_author = None
if author_form.has_changed and author_form.is_valid():
new_author = author_form.save()
if new_poc is not None and new_author is not None:
the_appinstance = appinstance_form.save()
the_appinstance.poc = new_poc
the_appinstance.metadata_author = new_author
the_appinstance.keywords.add(*new_keywords)
AppInstance.objects.filter(id=the_appinstance.id).update(
category=new_category)
return HttpResponseRedirect(
reverse('appinstance_detail', args=(appinstance.id,)))
else:
the_appinstance = appinstance_form.save()
if new_poc is None:
the_appinstance.poc = appinstance.owner
if new_author is None:
the_appinstance.metadata_author = appinstance.owner
the_appinstance.keywords.add(*new_keywords)
AppInstance.objects.filter(id=the_appinstance.id).update(
category=new_category)
return HttpResponseRedirect(
reverse('appinstance_detail', args=(appinstance.id,)))
documents = Document.objects.filter(title__icontains=title_filter)
if settings.RESOURCE_PUBLISHING:
documents = documents.filter(is_published=True)
if not settings.SKIP_PERMS_FILTER:
documents = documents.filter(id__in=authorized)
counts = documents.values('doc_type').annotate(count=Count('doc_type'))
facets = dict([(count['doc_type'], count['count']) for count in counts])
return facets
elif facet_type =='appinstances':
appinstances= AppInstance.objects.filter(title__icontains=title_filter)
if settings.RESOURCE_PUBLISHING:
appinstances = appinstances.filter(is_published=True)
if not settings.SKIP_PERMS_FILTER:
appinstances = appinstances.filter(id__in=authorized)
counts = appinstances.values('app__title').annotate(count=Count('app__name'))
facets = dict([(count['app__title'], count['count']) for count in counts])
return facets
else:
layers = Layer.objects.filter(title__icontains=title_filter)
if settings.RESOURCE_PUBLISHING:
layers = layers.filter(is_published=True)
the_appinstance.poc = new_poc
the_appinstance.metadata_author = new_author
the_appinstance.keywords.add(*new_keywords)
AppInstance.objects.filter(id=the_appinstance.id).update(
category=new_category)
return HttpResponseRedirect(
reverse('appinstance_detail', args=(appinstance.id,)))
else:
the_appinstance = appinstance_form.save()
if new_poc is None:
the_appinstance.poc = appinstance.owner
if new_author is None:
the_appinstance.metadata_author = appinstance.owner
the_appinstance.keywords.add(*new_keywords)
AppInstance.objects.filter(id=the_appinstance.id).update(
category=new_category)
return HttpResponseRedirect(
reverse('appinstance_detail', args=(appinstance.id,)))
if poc is not None:
appinstance_form.fields['poc'].initial = poc.id
poc_form = ProfileForm(prefix="poc")
poc_form.hidden = True
else:
poc_form = ProfileForm(prefix="poc")
poc_form.hidden = True
if metadata_author is not None:
appinstance_form.fields[
'metadata_author'].initial = metadata_author.id
author_form = ProfileForm(prefix="author")
def workspace(request):
owner = request.user
apps = AppInstance.objects.filter(owner=owner)
created_apps = AppInstance.objects.all()
layers = Layer.objects.filter(owner=owner)
maps = Map.objects.filter(owner=owner)
maps_count = Map.objects.all().count()
layers_count = Layer.objects.all().count()
documents = Document.objects.filter(owner=owner)
documents_count = Document.objects.all().count()
groups = owner.group_list_all()
groups_count = GroupProfile.objects.all().count()
return render(
request,
template_name='workspace/workspace.html',
context={
'my_apps': apps,
'my_layers': layers,
'created_apps': created_apps,