-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from openzim/archives-metadata
Request Task to farm
- Loading branch information
Showing
23 changed files
with
1,226 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
# Contribution | ||
|
||
## Dependencies | ||
```bash | ||
# Install all the dependencies. | ||
pipenv sync | ||
# Update dependencies. | ||
pipenv install | ||
``` | ||
# backend | ||
|
||
## Development | ||
Leverages great things to achieve great results | ||
|
||
If you want to link to Postgresql, create the `.env` file and set the `POSTGRES_URI` environment variable in it, example: | ||
[![CodeFactor](https://www.codefactor.io/repository/github/openzim/nautilus-webui/badge)](https://www.codefactor.io/repository/github/openzim/nautilus-webui) | ||
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) | ||
[![codecov](https://codecov.io/gh/openzim/nautilus-webui/branch/main/graph/badge.svg)](https://codecov.io/gh/openzim/nautilus-webui) | ||
![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fgithub.com%2Fopenzim%2Fnautilus-webui%2Fraw%2Fmain%2Fbackend%2Fpyproject.toml) | ||
|
||
```env | ||
POSTGRES_URI=postgresql+psycopg://username:password@host/database | ||
``` | ||
|
||
Dev commands: | ||
```bash | ||
# Init database | ||
pipenv run init | ||
# Start FastAPI | ||
pipenv run start | ||
# Run tests | ||
pipenv run tests | ||
# Format code | ||
pipenv run format | ||
# Check format. | ||
pipenv run format:check | ||
## Usage | ||
|
||
**CAUTION**: this is not a standalone, installable Python package. | ||
|
||
- It's the backend of a web service that is intended to be deployed using OCI images. | ||
- See the sample Composefile in the dev folder of the repository. | ||
- It has external dependencies (including [S3 Storage](https://wasabi.com/), [Mailgun](https://www.mailgun.com/) account and a full-fledged [Zimfarm](https://github.com/openzim/zimfarm). | ||
- It **must be configured** via environment variables (see `constants.py` and Compose's Envfile) | ||
- There is no CHANGELOG nor release management. Production is tied to CD on `main` branch. | ||
|
||
```sh | ||
❯ hatch run serve | ||
``` | ||
|
||
nautilus-webui backend adheres to openZIM's [Contribution Guidelines](https://github.com/openzim/overview/wiki/Contributing). | ||
|
||
nautilus-webui backend has implemented openZIM's [Python bootstrap, conventions and policies](https://github.com/openzim/_python-bootstrap/docs/Policy.md) **v1.0.1**. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from uuid import UUID | ||
|
||
from sqlalchemy import select | ||
|
||
from api.database import Session as DBSession | ||
from api.database.models import File, Project | ||
|
||
|
||
def get_file_by_id(file_id: UUID) -> File: | ||
"""Get File instance by its id.""" | ||
with DBSession.begin() as session: | ||
stmt = select(File).where(File.id == file_id) | ||
file = session.execute(stmt).scalar() | ||
if not file: | ||
raise ValueError(f"File not found: {file_id}") | ||
session.expunge(file) | ||
return file | ||
|
||
|
||
def get_project_by_id(project_id: UUID) -> Project: | ||
"""Get Project instance by its id.""" | ||
with DBSession.begin() as session: | ||
stmt = select(Project).where(Project.id == project_id) | ||
project = session.execute(stmt).scalar() | ||
if not project: | ||
raise ValueError(f"Project not found: {project_id}") | ||
session.expunge(project) | ||
return project |
Oops, something went wrong.