Skip to content

Commit

Permalink
Setup playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
k9845 committed Oct 30, 2023
1 parent 58a9269 commit c141645
Show file tree
Hide file tree
Showing 7 changed files with 634 additions and 206 deletions.
20 changes: 20 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import reversion
import uuid

from django.utils.translation import gettext_lazy as _
# from django.db import models
from django.contrib.gis.db import models
Expand Down Expand Up @@ -2139,3 +2141,21 @@ class CountryOfFieldReportToReview(models.Model):
class Meta:
verbose_name = "Country of Field Report to review"
verbose_name_plural = "Countries of Field Report to review"


class ExportToken(models.Model):
class ExportStatus(models.IntegerChoices):
STARTED = 0, _('Started')
PENDING = 1, _('Pending')
COMPLETED = 2, _('Completed')
ERRORED = 3, _('Errored')

url = models.URLField(verbose_name=_("Url"), max_length=255)
token = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
requested_at = models.DateTimeField(verbose_name=_('Requested At'), null=True, blank=True)
completed_at = models.DateTimeField(verbose_name=_('Completed At'), null=True, blank=True)
status = models.IntegerField(verbose_name=_('Status'), choices=ExportStatus.choices)
pdf_url = models.URLField(verbose_name=_('Pdf Url'), max_length=255)

def __str__(self):
return f'{self.url} - {self.token} - {self.pdf_url}'
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ x-server: &base_server_setup
- redis
- elasticsearch
- kibana
- playwright


services:
Expand Down Expand Up @@ -105,6 +106,16 @@ services:
depends_on:
- elasticsearch

playwright:
image: mcr.microsoft.com/playwright:v1.37.0-jammy
user: pwuser
security_opt:
- seccomp=seccomp_profile.json
ipc: host
stdin_open: true
tty: true
environment:
- NODE_NO_WARNINGS=1

serve:
<<: *base_server_setup
Expand Down
1 change: 0 additions & 1 deletion main/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def map_error_codes(codes, default=None):

if isinstance(codes, str):
return error_code_map.get(codes, default)

if codes == {'non_field_errors': ['invalid']}:
return error_codes.TOKEN_INVALID

Expand Down
2 changes: 1 addition & 1 deletion per/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from api.models import Country

logger = logging.getLogger(__name__)

from playwright.sync_api import sync_playwright

def get_now_str():
return datetime.now(timezone.utc)
Expand Down
791 changes: 588 additions & 203 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ opencensus-ext-azure = "==1.0.7"
opencensus-ext-django = "==0.7.4"
pandas = "==1.3.5"
"pdfminer.six" = "==20191110"
pytest-playwright = "==0.4.2"
pytidylib = "==0.3.2"
polib = "==1.1.0"
psycopg2 = "==2.8.6"
psycopg2-binary = "*"
pycountry = "==19.8.18"
pydash = "==4.8.0"
python-Levenshtein = "==0.12.1"
Expand Down
12 changes: 12 additions & 0 deletions seccomp_profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"comment": "Allow create user namespaces",
"names": [
"clone",
"setns",
"unshare"
],
"action": "SCMP_ACT_ALLOW",
"args": [],
"includes": {},
"excludes": {}
}

0 comments on commit c141645

Please sign in to comment.