Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/v1.0.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
ja573 committed May 9, 2019
2 parents 8694865 + e34988f commit 5ebe870
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ The following methods are allowed:
| `GET` | `/translate` | Takes a `uri` as parameter and returns all identifiers associated with it. |
| `GET` | `/works` | Return information about stored publications. |
| `POST` | `/works` | Store a publication and associated URIs in the database. |
| `DELETE` | `/works` | Delete a publicatin and associated URIs from the database. |
| `DELETE` | `/works` | Delete a publication from the database. |
| `POST` | `/titles` | Add a new title to an existing publication. |
| `DELETE` | `/titles` | Remove a title from its publication. |
| `POST` | `/uris` | Add a new URI to an existing publication. |
Expand Down Expand Up @@ -239,6 +239,13 @@ In this example we use a fictional parent UUID, which could be one of a book ser
}
```

#### `DELETE /works` data

| Attribute | Type | Description |
| --------- | ------ | ---------------------------------- |
| UUID | string | The work_id of the work to delete. |


### More
Check some more [example queries][6].

Expand Down
8 changes: 6 additions & 2 deletions src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def get_type(self):
options = dict(uuid=self.UUID)
result = db.select('work', options,
what="work_type", where="work_id = $uuid")
return result.first()["work_type"]
return result.first()["work_type"] if result else None

def get_titles(self):
options = dict(uuid=self.UUID)
titles = db.select('work_title', options,
what="title", where="work_id = $uuid")
return [(x["title"]) for x in titles]
return [(x["title"]) for x in titles] if titles else []

def get_identifiers(self):
options = dict(uuid=self.UUID)
Expand Down Expand Up @@ -144,6 +144,10 @@ def delete_titles(self):
except BaseException:
pass

def delete(self):
q = '''DELETE FROM work WHERE work_id = $work_id'''
db.query(q, dict(work_id=self.UUID))

@staticmethod
def generate_uuid():
return str(uuid.uuid4())
Expand Down
21 changes: 20 additions & 1 deletion src/worksctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,26 @@ def PUT(self, name):
@check_token
def DELETE(self, name):
"""Delete a work"""
raise Error(NOTALLOWED)
logger.debug("Data: %s" % (web.input()))

work_id = web.input().get('UUID') or web.input().get('uuid')

try:
if not work_id:
raise AssertionError
except AssertionError as error:
logger.debug(error)
raise Error(BADPARAMS, msg="You must provide a (work) UUID")

try:
work = Work(work_id)
if not work.exists():
raise AssertionError
except AssertionError:
raise Error(BADPARAMS, msg="Unknown work '%s'" % (work_id))

work.delete()
return []

@json_response
def OPTIONS(self, name):
Expand Down

0 comments on commit 5ebe870

Please sign in to comment.