New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added delete_tileset
manage command and tileset
API route
#79
Changes from all commits
e0bce30
7dc5683
04dd014
08a86d9
a00ff43
e622c42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
clodius==0.7.2 | ||
clodius==0.9.3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Cython==0.25.2 | ||
-e git+https://github.com/mirnylab/cooler.git@master#egg=cooler | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's in the master branch that isn't in v0.7.10? |
||
pybbi==0.2.0 | ||
bumpversion==0.5.3 | ||
pyBigWig==0.3.2 | ||
Cython==0.27.2 | ||
CacheControl==0.12.4 | ||
cooler==0.7.10 | ||
django-cors-headers | ||
django-guardian | ||
django-rest-swagger | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
from django.conf import settings | ||
import tilesets.models as tm | ||
import os | ||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('--uuid', type=str, required=True) | ||
|
||
def handle(self, *args, **options): | ||
uuid = options.get('uuid') | ||
|
||
# search for Django object, remove associated file and record | ||
instance = tm.Tileset.objects.get(uuid=uuid) | ||
if not instance: | ||
raise CommandError('Instance for specified uuid [%s] was not found' % (uuid)) | ||
else: | ||
filename = instance.datafile.name | ||
filepath = os.path.join(settings.MEDIA_ROOT, filename) | ||
if not os.path.isfile(filepath): | ||
raise CommandError('File does not exist under media root') | ||
try: | ||
os.remove(filepath) | ||
except OSError: | ||
raise CommandError('File under media root could not be removed') | ||
try: | ||
instance.delete() | ||
except ProtectedError: | ||
raise CommandError('Instance for specified uuid [%s] could not be deleted' % (uuid)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
from django.conf import settings | ||
import tilesets.models as tm | ||
import os | ||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('--uuid', type=str, required=True) | ||
parser.add_argument('--name', type=str) | ||
|
||
def handle(self, *args, **options): | ||
uuid = options.get('uuid') | ||
name = options.get('name') | ||
|
||
# search for Django object, modify associated record | ||
instance = tm.Tileset.objects.get(uuid=uuid) | ||
if not instance: | ||
raise CommandError('Instance for specified uuid [%s] was not found' % (uuid)) | ||
else: | ||
try: | ||
instance_modified = False | ||
|
||
# only change tileset name if specified, and if it is | ||
# different from the current instance name | ||
if name and name != instance.name: | ||
instance.name = name | ||
instance_modified = True | ||
|
||
# if any changes were applied, persist them | ||
if instance_modified: | ||
instance.save() | ||
except ProtectedError: | ||
raise CommandError('Instance for specified uuid [%s] could not be renamed' % (uuid)) |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -37,6 +37,7 @@ | |||
import tilesets.serializers as tss | ||||
import tilesets.suggestions as tsu | ||||
|
||||
import os | ||||
import os.path as op | ||||
|
||||
import rest_framework.exceptions as rfe | ||||
|
@@ -58,8 +59,9 @@ | |||
from django.views.decorators.gzip import gzip_page | ||||
from rest_framework import generics | ||||
from rest_framework import viewsets | ||||
from rest_framework.decorators import api_view, authentication_classes | ||||
from rest_framework.decorators import api_view, authentication_classes, permission_classes | ||||
from rest_framework.authentication import BasicAuthentication | ||||
from rest_framework.permissions import IsAuthenticated | ||||
from fragments.drf_disable_csrf import CsrfExemptSessionAuthentication | ||||
|
||||
from higlass_server.utils import getRdb | ||||
|
@@ -492,6 +494,95 @@ def tiles(request): | |||
) | ||||
|
||||
return JsonResponse(tiles_to_return, safe=False) | ||||
|
||||
|
||||
@api_view(['POST', 'DELETE']) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you check if the higlass-server/tilesets/views.py Line 683 in dc4d380
I know the POST endpoint works because I've been using it to upload datasets to higlass.io. Take a look here: http://docs-dev.higlass.io/data_preparation.html#importing-into-higlass If possible, I'd prefer to avoid duplicating API endpoints. |
||||
@authentication_classes((CsrfExemptSessionAuthentication, BasicAuthentication)) | ||||
@permission_classes((IsAuthenticated,)) | ||||
def tileset(request): | ||||
''' | ||||
Delete or modify tileset with given uuid. | ||||
|
||||
Args: | ||||
POST | ||||
request (django.http.HTTPRequest): The request object | ||||
containing the uuid (uuid=abcd1234) that identifies the | ||||
tileset, with additional (optional) parameters that update | ||||
the identified object (name, at this time). | ||||
|
||||
DELETE | ||||
request (django.http.HTTPRequest): The request object | ||||
containing the uuid (d=abcd1234) that identifies the | ||||
tileset. | ||||
|
||||
Return: | ||||
django.http.JsonResponse: A JSON object containing | ||||
the tileset uuid or an error message detailing | ||||
what step of the deletion or modification failed. | ||||
''' | ||||
|
||||
if request.method == 'POST': | ||||
tileset_wrapper = json.loads(request.body.decode('utf-8')) | ||||
tileset_uuid = tileset_wrapper.get('uuid') | ||||
tileset_name = tileset_wrapper.get('name') | ||||
if not tileset_uuid: | ||||
return JsonResponse({ | ||||
'error': 'Tileset uuid not specified' | ||||
}, status=400) | ||||
instance = tm.Tileset.objects.get(uuid=tileset_uuid) | ||||
if not instance: | ||||
return JsonResponse({ | ||||
'error': 'Tileset instance for uuid {} does not exist'.format(tileset_uuid) | ||||
}, status=400) | ||||
try: | ||||
instance_modified = False | ||||
|
||||
# only change tileset name if specified, and if it is | ||||
# different from the current instance name | ||||
if tileset_name and tileset_name != instance.name: | ||||
instance.name = tileset_name | ||||
instance_modified = True | ||||
|
||||
# if any changes were applied, persist them | ||||
if instance_modified: | ||||
instance.save() | ||||
except ProtectedError: | ||||
return JsonResponse({ | ||||
'error': 'Tileset instance for uuid {} could not be modified'.format(tileset_uuid) | ||||
}, status=400) | ||||
return JsonResponse({'uuid': tileset_uuid}) | ||||
|
||||
elif request.method == 'DELETE': | ||||
if 'd' not in request.GET: | ||||
return JsonResponse({ | ||||
'error': 'Tileset uuid not specified' | ||||
}, status=400) | ||||
tileset_uuid = request.GET['d'] | ||||
instance = tm.Tileset.objects.get(uuid=tileset_uuid) | ||||
if not instance: | ||||
return JsonResponse({ | ||||
'error': 'Tileset instance for uuid {} does not exist'.format(tileset_uuid) | ||||
}, status=400) | ||||
filename = instance.datafile.name | ||||
filepath = op.join(hss.MEDIA_ROOT, filename) | ||||
if not op.isfile(filepath): | ||||
return JsonResponse({ | ||||
'error': 'Tileset instance for uuid {} does not have file at path {}'.format(tileset_uuid, filepath) | ||||
}, status=404) | ||||
try: | ||||
os.remove(filepath) | ||||
except OSError: | ||||
return JsonResponse({ | ||||
'error': 'Tileset instance for uuid {} could not have file removed at path {}'.format(tileset_uuid, filepath) | ||||
}, status=400) | ||||
try: | ||||
instance.delete() | ||||
except ProtectedError: | ||||
return JsonResponse({ | ||||
'error': 'Tileset instance for uuid {} could not be deleted'.format(tileset_uuid) | ||||
}, status=400) | ||||
return JsonResponse({'uuid': tileset_uuid}) | ||||
|
||||
|
||||
|
||||
@api_view(['GET']) | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the datatype specific documentation is in the main documentation repository: http://docs-dev.higlass.io/data_preparation.html
The code for that can be found here: https://github.com/higlass/higlass/tree/develop/docs