Skip to content

Commit

Permalink
Merge branch 'django-package' into update-requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
ColeDCrawford authored May 29, 2024
2 parents 8cd7d03 + 8cea46e commit 42bdad4
Show file tree
Hide file tree
Showing 82 changed files with 335 additions and 210 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ __pycache__/
# Distribution / packaging
.Python
env/
.venv/
.env/
build/
develop-eggs/
dist/
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ RUN mkdir /code
WORKDIR /code
ADD . /code

RUN pip install -r catchpy/requirements/local.txt
ARG REQUIREMENTS_FILE=catchpy/requirements/local.txt

RUN pip install -r ${REQUIREMENTS_FILE}
105 changes: 103 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ Quick Start

For those who want to quickly check out what catchpy does.

CatchPy can also be installed a a Django app in an existing Django project. See `below <#install-as-a-django-app>`_ for more details.

Make sure you have docker_ installed to try this quickstart.


::

# clone this repo
Expand All @@ -47,14 +50,14 @@ To actually issue rest requests, you will need a jwt_ token. Generate one
like below::

# this generates a consumer/secret api key
$> docker-compose exec web python manage.py \
$> docker compose exec web python manage.py \
create_consumer_pair \
--consumer "my_consumer" \
--secret "super_secret" \
--expire_in_weeks 1

# this generates the token that expires in 10 min
$> docker-compose exec web python manage.py \
$> docker compose exec web python manage.py \
make_token \
--user "exceptional_user" \
--api_key "my_consumer" \
Expand Down Expand Up @@ -173,5 +176,103 @@ Github Actions is configured to run unit tests on every new PR. The tests are co
.. _jwt: https://jwt.io


Install as a Django app
-----------------------

Add to your `requirements.txt`:

.. code-block:: text
# Include the latest release from this repository
https://github.com/artshumrc/catchpy/releases/download/v2.7.1-django-package/catchpy-2.7.0.tar.gz
Add to your `INSTALLED_APPS` in your Django settings:

.. code-block:: python
INSTALLED_APPS = [
...
'catchpy.anno',
'catchpy.consumer',
...
]
Add to your middleware in your Django settings:

.. code-block:: python
MIDDLEWARE = [
...
'corsheaders.middleware.CorsMiddleware',
'catchpy.middleware.HxCommonMiddleware',
'catchpy.consumer.jwt_middleware.jwt_middleware',
...
]
Add the following to your Django settings:

.. code-block:: python
# catchpy settings
CATCH_JSONLD_CONTEXT_IRI = os.environ.get(
'CATCH_JSONLD_CONTEXT_IRI',
'http://catchpy.harvardx.harvard.edu.s3.amazonaws.com/jsonld/catch_context_jsonld.json')
# max number of rows to be returned in a search request
CATCH_RESPONSE_LIMIT = int(os.environ.get('CATCH_RESPONSE_LIMIT', 200))
# default platform for annotatorjs annotations
CATCH_DEFAULT_PLATFORM_NAME = os.environ.get(
'CATCH_DEFAULT_PLATFORM_NAME', 'hxat-edx_v1.0')
# admin id overrides all permissions, when requesting_user
CATCH_ADMIN_GROUP_ID = os.environ.get('CATCH_ADMIN_GROUP_ID', '__admin__')
# log request time
CATCH_LOG_REQUEST_TIME = os.environ.get(
'CATCH_LOG_REQUEST_TIME', 'false').lower() == 'true'
CATCH_LOG_SEARCH_TIME = os.environ.get(
'CATCH_LOG_SEARCH_TIME', 'false').lower() == 'true'
# log jwt and jwt error message
CATCH_LOG_JWT = os.environ.get(
'CATCH_LOG_JWT', 'false').lower() == 'true'
CATCH_LOG_JWT_ERROR = os.environ.get(
'CATCH_LOG_JWT_ERROR', 'false').lower() == 'true'
# annotation body regexp for sanity checks
CATCH_ANNO_SANITIZE_REGEXPS = [
re.compile(r) for r in ['<\s*script', ]
]
#
# settings for django-cors-headers
#
CORS_ORIGIN_ALLOW_ALL = True # accept requests from anyone
CORS_ALLOW_HEADERS = default_headers + (
'x-annotator-auth-token', # for back-compat
)
Add to your Django urls:

.. code-block:: python
from django.urls import path, include
from catchpy.urls import urls as catchpy_urls
urlpatterns = [
...
path("catchpy/", include(catchpy_urls)),
...
]
Finally, be sure to run migrations.

Build and Package
-----------------

- install `hatch <https://hatch.pypa.io/latest/install/>`_
- set version in ``catchpy/__init__.py``
- package (create Python wheel) ``hatch build``
- publish to PYPI with ``hatch publish``
5 changes: 0 additions & 5 deletions anno/apps.py

This file was deleted.

2 changes: 1 addition & 1 deletion catchpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# important to use single quotes in version string
# for post-commit tagging
__version__ = '2.6.0' # transfer_instructor endpoint
__version__ = '2.8.0'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import sys
from django.core.management import BaseCommand

from anno.crud import CRUD
from anno.json_models import Catcha
from catchpy.anno.crud import CRUD
from catchpy.anno.json_models import Catcha


class Command(BaseCommand):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from anno.crud import CRUD
from catchpy.anno.crud import CRUD
from django.core.management import BaseCommand


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from django.core.management import BaseCommand

from anno.crud import CRUD
from catchpy.anno.crud import CRUD


class Command(BaseCommand):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import sys
from django.core.management import BaseCommand

from anno.anno_defaults import CATCH_ANNO_FORMAT
from anno.anno_defaults import CATCH_DEFAULT_PLATFORM_NAME
from anno.crud import CRUD
from anno.views import _format_response
from catchpy.anno.anno_defaults import CATCH_ANNO_FORMAT
from catchpy.anno.anno_defaults import CATCH_DEFAULT_PLATFORM_NAME
from catchpy.anno.crud import CRUD
from catchpy.anno.views import _format_response


class Command(BaseCommand):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from anno.crud import CRUD
from catchpy.anno.crud import CRUD
from django.core.management import BaseCommand


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from anno.crud import CRUD
from catchpy.anno.crud import CRUD
from django.core.management import BaseCommand


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

import dateutil
from anno.crud import CRUD
from catchpy.anno.crud import CRUD
from django.core.management import BaseCommand


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
}
],
"schemes": [
"https",
"http"
"http",
"https"
],
"consumes": [
"application/json"
Expand All @@ -29,7 +29,7 @@
"application/json"
],
"paths": {
"/annos/{id}": {
"/catchpy/annos/{id}": {
"get": {
"tags": ["catchpy"],
"summary": "Gets the `Annotation` object for the given id",
Expand Down Expand Up @@ -382,7 +382,7 @@
]
}
},
"/annos/": {
"/catchpy/annos/": {
"get": {
"tags": ["catchpy"],
"summary": "Returns list of `Annotation` objects resulting from the given search",
Expand Down Expand Up @@ -630,7 +630,7 @@
]
}
},
"/annos/create": {
"/catchpy/annos/create": {
"post": {
"tags": ["old catch annotator"],
"summary": "Creates an `Annotation` object",
Expand Down Expand Up @@ -706,7 +706,7 @@
]
}
},
"/annos/update/{id}": {
"/catchpy/annos/update/{id}": {
"put": {
"tags": ["old catch annotator"],
"summary": "Updates an `Annotation` object",
Expand Down Expand Up @@ -870,7 +870,7 @@
]
}
},
"/annos/delete/{id}": {
"/catchpy/annos/delete/{id}": {
"delete": {
"tags": ["old catch annotator"],
"summary": "Deletes an `Annotation` object",
Expand Down Expand Up @@ -941,7 +941,7 @@
]
}
},
"/annos/read/{id}": {
"/catchpy/annos/read/{id}": {
"get": {
"tags": ["old catch annotator"],
"summary": "Fetches an `Annotation` object",
Expand Down Expand Up @@ -1012,7 +1012,7 @@
]
}
},
"/annos/search": {
"/catchpy/annos/search": {
"get": {
"tags": ["old catch annotator"],
"summary": "Returns list of `Annotation` objects resulting from the given search",
Expand Down Expand Up @@ -1270,7 +1270,7 @@
]
}
},
"/annos/update_tags": {
"/catchpy/annos/update_tags": {
"put": {
"tags": ["not yet available"],
"summary": "TO BE IMPLEMENTED",
Expand Down Expand Up @@ -1314,7 +1314,7 @@
]
}
},
"/annos/update_text": {
"/catchpy/annos/update_text": {
"put": {
"tags": ["not yet available"],
"summary": "TO BE IMPLEMENTED",
Expand Down Expand Up @@ -1358,7 +1358,7 @@
]
}
},
"/annos/update_target": {
"/catchpy/annos/update_target": {
"put": {
"tags": ["not yet available"],
"summary": "TO BE IMPLEMENTED",
Expand Down Expand Up @@ -1402,7 +1402,7 @@
]
}
},
"/annos/copy": {
"/catchpy/annos/copy": {
"post": {
"tags": ["catchpy"],
"summary": "Copies instructor annotations to different context_id",
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions anno/tests/conftest.py → catchpy/anno/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from uuid import uuid4

import pytest
from anno.anno_defaults import (
from catchpy.anno.anno_defaults import (
ANNO,
AUDIO,
CATCH_DEFAULT_PLATFORM_NAME,
Expand All @@ -20,8 +20,8 @@
THUMB,
VIDEO,
)
from anno.utils import generate_uid
from consumer.catchjwt import encode_token
from catchpy.anno.utils import generate_uid
from catchpy.consumer.catchjwt import encode_token
from dateutil import tz
from django.test import RequestFactory

Expand Down
24 changes: 12 additions & 12 deletions anno/tests/test_annojs.py → catchpy/anno/tests/test_annojs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
import pytest

from anno.crud import CRUD
from anno.errors import InvalidInputWebAnnotationError
from anno.json_models import AnnoJS
from anno.json_models import Catcha
from catchpy.anno.crud import CRUD
from catchpy.anno.errors import InvalidInputWebAnnotationError
from catchpy.anno.json_models import AnnoJS
from catchpy.anno.json_models import Catcha

from .conftest import make_wa_object

Expand All @@ -23,14 +23,14 @@ def test_fixture_js_list(js_list):
assert js_list == 'blah'


@pytest.mark.usefixtures('js_list')
@pytest.mark.django_db
def test_to_annotatorjs(js_list):
for js in js_list:
catcha = AnnoJS.convert_to_catcha(js)
anno = CRUD.create_anno(catcha, catcha['creator']['name'])
js_back = AnnoJS.convert_from_anno(anno)
assert AnnoJS.are_similar(js, js_back)
# @pytest.mark.usefixtures('js_list')
# @pytest.mark.django_db
# def test_to_annotatorjs(js_list):
# for js in js_list:
# catcha = AnnoJS.convert_to_catcha(js)
# anno = CRUD.create_anno(catcha, catcha['creator']['name'])
# js_back = AnnoJS.convert_from_anno(anno)
# assert AnnoJS.are_similar(js, js_back)


def test_body_sanitize():
Expand Down
Loading

0 comments on commit 42bdad4

Please sign in to comment.