def get_metadata_files(draft): data = draft.registration_metadata for q, question in get_file_questions('prereg-prize.json'): if not isinstance(data[q]['value'], dict): for i, file_info in enumerate(data[q]['extra']): provider = file_info['data']['provider'] if provider != 'osfstorage': raise Http404( 'File does not exist in OSFStorage ({}: {})'.format( q, question )) file_guid = file_info.get('fileId') if not file_guid: node = Node.load(file_info.get('nodeId')) path = file_info['data'].get('path') item = FileNode.resolve_class( provider, FileNode.FILE ).get_or_create(node, path) file_guid = item.get_guid(create=True)._id data[q]['extra'][i]['fileId'] = file_guid draft.update_metadata(data) draft.save() else: item = FileNode.load(file_info['data']['path'].replace('/', '')) if item is None: raise Http404( 'File with guid "{}" in "{}" does not exist'.format( file_guid, question )) yield item continue for i, file_info in enumerate(data[q]['value']['uploader']['extra']): provider = file_info['data']['provider'] if provider != 'osfstorage': raise Http404( 'File does not exist in OSFStorage ({}: {})'.format( q, question )) file_guid = file_info.get('fileId') if not file_guid: node = Node.load(file_info.get('nodeId')) path = file_info['data'].get('path') item = FileNode.resolve_class( provider, FileNode.FILE ).get_or_create(node, path) file_guid = item.get_guid(create=True)._id data[q]['value']['uploader']['extra'][i]['fileId'] = file_guid draft.update_metadata(data) draft.save() else: item = FileNode.load(file_info['data']['path'].replace('/', '')) if item is None: raise Http404( 'File with guid "{}" in "{}" does not exist'.format( file_guid, question )) yield item
def delete(self, request, *args, **kwargs): if (('spam_confirm' in list(request.POST.keys()) and not request.user.has_perm('osf.mark_spam')) or ('ham_confirm' in list(request.POST.keys()) and not request.user.has_perm('osf.mark_ham'))): raise PermissionDenied( 'You do not have permission to update a node flagged as spam.') node_ids = [ nid for nid in list(request.POST.keys()) if nid not in ('csrfmiddlewaretoken', 'spam_confirm', 'ham_confirm') ] for nid in node_ids: node = Node.load(nid) osf_admin_change_status_identifier(node) if ('spam_confirm' in list(request.POST.keys())): node.confirm_spam(save=True) update_admin_log(user_id=self.request.user.id, object_id=nid, object_repr='Node', message='Confirmed SPAM: {}'.format(nid), action_flag=CONFIRM_SPAM) elif ('ham_confirm' in list(request.POST.keys())): node.confirm_ham(save=True) update_admin_log(user_id=self.request.user.id, object_id=nid, object_repr='Node', message='Confirmed HAM: {}'.format(nid), action_flag=CONFIRM_HAM) return redirect('nodes:flagged-spam')
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) node = Node.load(self.kwargs.get('guid')) or Registration.load( self.kwargs.get('guid')) context['id'] = node._id context['public_cap'] = round( node.custom_storage_usage_limit_public or STORAGE_LIMIT_PUBLIC, 1) context['private_cap'] = round( node.custom_storage_usage_limit_private or STORAGE_LIMIT_PRIVATE, 1) return context
def get_claim_links(self, user): links = [] for guid, value in user.unclaimed_records.items(): node = Node.load(guid) url = '{base_url}user/{uid}/{project_id}/claim/?token={token}'.format( base_url=DOMAIN, uid=user._id, project_id=guid, token=value['token'] ) links.append('Claim URL for node {}: {}'.format(node._id, url)) return links or ['User currently has no active unclaimed records for any nodes.']
def get_claim_links(self, user): links = [] for guid, value in user.unclaimed_records.iteritems(): node = Node.load(guid) url = '{base_url}user/{uid}/{project_id}/claim/?token={token}'.format( base_url=DOMAIN, uid=user._id, project_id=guid, token=value['token'] ) links.append('Claim URL for node {}: {}'.format(node._id, url)) return links or ['User currently has no active unclaimed records for any nodes.']
def post(self, request, *args, **kwargs): node = Node.load(self.kwargs.get('guid')) or Registration.load( self.kwargs.get('guid')) new_private_cap = request.POST.get('private-cap-input') new_public_cap = request.POST.get('public-cap-input') if float(new_private_cap) != (node.custom_storage_usage_limit_private or STORAGE_LIMIT_PRIVATE): node.custom_storage_usage_limit_private = new_private_cap if float(new_public_cap) != (node.custom_storage_usage_limit_public or STORAGE_LIMIT_PUBLIC): node.custom_storage_usage_limit_public = new_public_cap node.save() return redirect(reverse_node(self.kwargs.get('guid')))
def delete(self, request, *args, **kwargs): if not request.user.has_perm('auth.mark_spam'): raise PermissionDenied( 'You do not have permission to update a node flagged as spam.') node_ids = [ nid for nid in request.POST.keys() if nid != 'csrfmiddlewaretoken' ] for nid in node_ids: node = Node.load(nid) node.confirm_spam(save=True) update_admin_log(user_id=self.request.user.id, object_id=nid, object_repr='Node', message='Confirmed SPAM: {}'.format(nid), action_flag=CONFIRM_SPAM) return redirect('nodes:flagged-spam')
def delete(self, request, *args, **kwargs): if not request.user.has_perm('auth.mark_spam'): raise PermissionDenied('You do not have permission to update a node flagged as spam.') node_ids = [ nid for nid in request.POST.keys() if nid != 'csrfmiddlewaretoken' ] for nid in node_ids: node = Node.load(nid) osf_admin_change_status_identifier(node, 'unavailable | spam') node.confirm_spam(save=True) update_admin_log( user_id=self.request.user.id, object_id=nid, object_repr='Node', message='Confirmed SPAM: {}'.format(nid), action_flag=CONFIRM_SPAM ) return redirect('nodes:flagged-spam')
def get_object(self, queryset=None): return Node.load(self.kwargs.get('guid')) or Registration.load( self.kwargs.get('guid'))
def get_object(self, queryset=None): guid = self.kwargs.get('guid') node = Node.load(guid) or Registration.load(guid) return serialize_node(node)
def get_object(self, queryset=None): return (Node.load(self.kwargs.get('guid')), OSFUser.load(self.kwargs.get('user_id')))
def get_object(self, queryset=None): return Node.load(self.kwargs.get('guid')) or Registration.load(self.kwargs.get('guid'))
def get_object(self, queryset=None): guid = self.kwargs.get('guid') node = Node.load(guid) or Registration.load(guid) return serialize_node(node)
def get_object(self, queryset=None): return (Node.load(self.kwargs.get('node_id')), OSFUser.load(self.kwargs.get('user_id')))