Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_batch_edit(self):
Model = Document
view = 'document_batch_metadata'
resources = Model.objects.all()[:3]
ids = ','.join([str(element.pk) for element in resources])
# test non-admin access
self.client.login(username="bobby", password="bob")
response = self.client.get(reverse(view, args=(ids,)))
self.assertEquals(response.status_code, 401)
# test group change
group = Group.objects.first()
self.client.login(username='admin', password='admin')
response = self.client.post(
reverse(view, args=(ids,)),
data={'group': group.pk},
)
self.assertEquals(response.status_code, 302)
resources = Model.objects.filter(id__in=[r.pk for r in resources])
def dump_models(path=None):
result = serialize("json", sum([list(x) for x in
[get_user_model().objects.all(),
Profile.objects.all(),
Layer.objects.all(),
Map.objects.all(),
Document.objects.all(),
Tag.objects.all(),
TaggedItem.objects.all(),
]], []), indent=2, use_natural_keys=True)
if path is None:
parent, _ = os.path.split(__file__)
path = os.path.join(parent, 'fixtures', 'search_testdata.json')
with open(path, 'w') as f:
f.write(result)
owner=user,
bbox_x0=bbox_x0,
bbox_x1=bbox_x1,
bbox_y0=bbox_y0,
bbox_y1=bbox_y1,
category=category,
)
m.save()
for kw in kws:
m.keywords.add(kw)
m.save()
if not type or type == 'document':
for dd, user in zip(document_data, cycle(users)):
title, abstract, kws, (bbox_x0, bbox_x1, bbox_y0, bbox_y1), category = dd
m = Document(title=title,
abstract=abstract,
owner=user,
bbox_x0=bbox_x0,
bbox_x1=bbox_x1,
bbox_y0=bbox_y0,
bbox_y1=bbox_y1,
category=category,
doc_file=f)
m.save()
for kw in kws:
m.keywords.add(kw)
m.save()
if not type or type == 'layer':
for ld, owner, storeType in zip(layer_data, cycle(users), cycle(('coverageStore', 'dataStore'))):
title, abstract, name, typename, (bbox_x0, bbox_x1, bbox_y0, bbox_y1), dt, kws, category = ld
document_upload_url = reverse('document_upload')
self.client.login(username=self.user, password=self.passwd)
input_path = self._get_input_path()
with open(input_path, 'rb') as f:
data = {'title': 'document title',
'doc_file': f,
'doc_url': '',
'resource': '',
'permissions': '{}',
}
resp = self.client.post(document_upload_url, data=data)
self.assertEqual(resp.status_code, 302)
dname = 'document title'
_l = Document.objects.get(title=dname)
self.assertTrue(_l.is_published)
_l.delete()
with self.settings(ADMIN_MODERATE_UPLOADS=True):
document_upload_url = reverse('document_upload')
self.client.login(username=self.user, password=self.passwd)
input_path = self._get_input_path()
with open(input_path, 'rb') as f:
data = {'title': 'document title',
'doc_file': f,
'doc_url': '',
'resource': '',
'permissions': '{}',
from modeltranslation.translator import translator, TranslationOptions
from geonode.documents.models import Document
class DocumentTranslationOptions(TranslationOptions):
fields = (
'title',
'abstract',
'purpose',
'constraints_other',
'supplemental_information',
'data_quality_statement',
)
translator.register(Document, DocumentTranslationOptions)
contact = self.o
user = contact.user
try:
doc['thumb'] = user.avatar_set.all()[0].avatar_url(80)
except IndexError:
doc['thumb'] = _default_avatar_url
doc['id'] = user.username
doc['title'] = user.get_full_name() or user.username
doc['organization'] = contact.organization
doc['abstract'] = contact.profile
modified = self.last_modified()
doc['last_modified'] = extension.date_fmt(modified) if modified else ''
doc['detail'] = contact.get_absolute_url()
doc['layer_cnt'] = Layer.objects.filter(owner = user).count()
doc['map_cnt'] = Map.objects.filter(owner = user).count()
doc['doc_cnt'] = Document.objects.filter(owner = user).count()
doc['_type'] = 'owner'
doc['_display_type'] = extension.USER_DISPLAY
return doc
document_query = lambda q: Document.objects.filter()
def favorite(req, subject, id):
"""
create favorite and put favorite_info object in response.
method is idempotent, Favorite's create_favorite method
only creates if does not already exist.
"""
if subject == 'document':
obj = get_object_or_404(Document, pk=id)
elif subject == 'map':
obj = get_object_or_404(Map, pk=id)
elif subject == 'mapstory':
obj = get_object_or_404(MapStory, pk=id)
elif subject == 'layer':
obj = get_object_or_404(Layer, pk=id)
elif subject == 'user':
obj = get_object_or_404(settings.AUTH_USER_MODEL, pk=id)
favorite = models.Favorite.objects.create_favorite(obj, req.user)
delete_url = reverse("delete_favorite", args=[favorite.pk])
response = {"has_favorite": "true", "delete_url": delete_url}
return HttpResponse(json.dumps(response), content_type="application/json", status=200)
'group',
'is_approved',
'is_published',
'metadata_completeness')
list_display_links = ('id',)
list_editable = ('title', 'category', 'group', 'is_approved', 'is_published')
list_filter = ('date', 'date_type', 'restriction_code_type', 'category',
'group', 'is_approved', 'is_published',)
search_fields = ('title', 'abstract', 'purpose',
'is_approved', 'is_published',)
date_hierarchy = 'date'
form = DocumentAdminForm
actions = [metadata_batch_edit]
admin.site.register(Document, DocumentAdmin)
def get_related_documents(resource):
if isinstance(resource, Layer) or isinstance(resource, Map):
content_type = ContentType.objects.get_for_model(resource)
return Document.objects.filter(links__content_type=content_type,
links__object_id=resource.pk)
else:
return None