Compare commits
No commits in common. "master" and "master" have entirely different histories.
23 changed files with 125 additions and 200 deletions
2
.devcontainer/.gitignore
vendored
2
.devcontainer/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
\.*
|
||||
!.gitignore
|
|
@ -1,50 +1,41 @@
|
|||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
|
||||
{
|
||||
"name": "Extend base docker-compose for development purposes",
|
||||
"name": "Existing Docker Compose (Extend)",
|
||||
|
||||
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
|
||||
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
|
||||
"dockerComposeFile": [
|
||||
"../docker-compose.yml",
|
||||
"docker-compose.yml"
|
||||
],
|
||||
"dockerComposeFile": ["../docker-compose.yml", "docker-compose.yml"],
|
||||
|
||||
// The 'service' property is the name of the service for the container that VS Code should
|
||||
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
|
||||
"service": "web",
|
||||
|
||||
// The optional 'workspaceFolder' property is the path VS Code should open by default when
|
||||
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
|
||||
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/git:1": {},
|
||||
"ghcr.io/devcontainers/features/sshd:1": {}
|
||||
},
|
||||
"ghcr.io/wxw-matt/devcontainer-features/script_runner:0": {}
|
||||
}
|
||||
|
||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||
// "features": {},
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Uncomment the next line if you want start specific services in your Docker Compose config.
|
||||
// "runServices": [],
|
||||
|
||||
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
|
||||
// "shutdownAction": "none",
|
||||
|
||||
// Uncomment the next line to run commands after the container is created.
|
||||
"postStartCommand": "${containerWorkspaceFolder}/manage.py migrate",
|
||||
"postCreateCommand": "${containerWorkspaceFolder}/manage.py collectstatic --no-input --clear",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"settings": {
|
||||
"extensions.verifySignature": false
|
||||
},
|
||||
"extensions": [
|
||||
"ms-python.python",
|
||||
"mikestead.dotenv",
|
||||
"VisualStudioExptTeam.vscodeintellicode",
|
||||
"ms-python.black-formatter",
|
||||
"VisualStudioExptTeam.intellicode-api-usage-examples",
|
||||
"ms-azuretools.vscode-docker",
|
||||
"DavidAnson.vscode-markdownlint",
|
||||
"yzhang.markdown-all-in-one"
|
||||
]
|
||||
}
|
||||
},
|
||||
"containerUser": "spejstore"
|
||||
// "postCreateCommand": "cat /etc/os-release",
|
||||
|
||||
// Configure tool-specific properties.
|
||||
// "customizations": {},
|
||||
|
||||
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
|
||||
// "remoteUser": "devcontainer"
|
||||
}
|
||||
|
|
|
@ -1,9 +1,25 @@
|
|||
version: "3.4"
|
||||
version: '3'
|
||||
services:
|
||||
# Update this to the name of the service you want to work with in your docker-compose.yml file
|
||||
web:
|
||||
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
|
||||
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
|
||||
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
|
||||
# array). The sample below assumes your primary file is in the root of your project.
|
||||
#
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: .devcontainer/Dockerfile
|
||||
|
||||
volumes:
|
||||
# Update this to wherever you want VS Code to mount the folder of your project
|
||||
- ..:/workspaces:cached
|
||||
restart: unless-stopped
|
||||
|
||||
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
|
||||
# cap_add:
|
||||
# - SYS_PTRACE
|
||||
# security_opt:
|
||||
# - seccomp:unconfined
|
||||
|
||||
# Overrides default command so things don't shut down after the process ends.
|
||||
command: /bin/sh -c "while sleep 1000; do :; done"
|
||||
|
@ -14,11 +30,11 @@ services:
|
|||
- SPEJSTORE_DB_PASSWORD=postgres
|
||||
- SPEJSTORE_DB_HOST=db
|
||||
# - SPEJSTORE_DB_PORT=
|
||||
- SPEJSTORE_ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
|
||||
- SPEJSTORE_ALLOWED_HOSTS=localhost,127.0.0.1
|
||||
# - SPEJSTORE_CLIENT_ID=
|
||||
# - SPEJSTORE_SECRET=
|
||||
# - SPEJSTORE_MEDIA_ROOT=
|
||||
# - SPEJSTORE_REQUIRE_AUTH=true
|
||||
- SPEJSTORE_OAUTH_REDIRECT_IS_HTTPS=false
|
||||
- SPEJSTORE_SPEJSTORE_FILE_STORAGE_TYPE="filesystem"
|
||||
# - SPEJSTORE_PROXY_TRUSTED_IPS=172.21.37.1
|
||||
- SPEJSTORE_PROXY_TRUSTED_IPS=172.21.37.1
|
||||
|
||||
|
|
|
@ -20,4 +20,3 @@ log
|
|||
.Dockerfile
|
||||
.env
|
||||
.devcontainer
|
||||
readme
|
||||
|
|
11
.env.example
11
.env.example
|
@ -7,14 +7,3 @@ SPEJSTORE_DB_USER=postgres
|
|||
SPEJSTORE_DB_HOST=db
|
||||
SPEJSTORE_HOST="https://inventory.hackerspace.pl"
|
||||
SPEJSTORE_LABEL_API=https://label.waw.hackerspace.pl
|
||||
|
||||
|
||||
# "filesystem" or "s3"
|
||||
SPEJSTORE_FILE_STORAGE_TYPE="filesystem"
|
||||
|
||||
# S3 bucket
|
||||
SPEJSTORE_S3_ACCESS_KEY="SPEJSTORE_S3_ACCESS_KEY"
|
||||
SPEJSTORE_S3_SECRET_KEY="SPEJSTORE_S3_SECRET_KEY"
|
||||
SPEJSTORE_S3_ENDPOINT_URL="SPEJSTORE_S3_ENDPOINT_URL"
|
||||
SPEJSTORE_S3_BUCKET_NAME="SPEJSTORE_S3_BUCKET_NAME"
|
||||
SPEJSTORE_S3_MEDIA_LOCATION="SPEJSTORE_S3_MEDIA_LOCATION"
|
||||
|
|
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -12,13 +12,6 @@ postgres-hstore/
|
|||
docker-compose.override.yml
|
||||
build_static
|
||||
.venv
|
||||
.vscode
|
||||
|
||||
__pycache__
|
||||
|
||||
# Is not ignored by default in devcontainers, macs bad
|
||||
.DS_Store
|
||||
|
||||
# Ignore vscode devcontainer files
|
||||
.vscode-server
|
||||
.ssh
|
||||
.gitconfig
|
||||
|
|
5
.vscode/extensions.json
vendored
5
.vscode/extensions.json
vendored
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"recommendations": [
|
||||
"ms-vscode-remote.remote-containers"
|
||||
]
|
||||
}
|
20
.vscode/launch.json
vendored
20
.vscode/launch.json
vendored
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Django",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/manage.py",
|
||||
"args": [
|
||||
"runserver",
|
||||
"0.0.0.0:8000",
|
||||
],
|
||||
"django": true,
|
||||
"justMyCode": true
|
||||
}
|
||||
]
|
||||
}
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"[python]": {
|
||||
"editor.defaultFormatter": "ms-python.black-formatter"
|
||||
},
|
||||
}
|
27
.vscode/tasks.json
vendored
27
.vscode/tasks.json
vendored
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "migrate",
|
||||
"type": "shell",
|
||||
"command": "${workspaceFolder}/manage.py migrate"
|
||||
},
|
||||
{
|
||||
"label": "makemigrations",
|
||||
"type": "shell",
|
||||
"command": "${workspaceFolder}/manage.py makemigrations"
|
||||
},
|
||||
{
|
||||
"label": "runserver",
|
||||
"type": "shell",
|
||||
"command": "${workspaceFolder}/manage.py runserver"
|
||||
},
|
||||
{
|
||||
"label": "collectstatic",
|
||||
"type": "shell",
|
||||
"command": "${workspaceFolder}/manage.py collectstatic"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -12,7 +12,6 @@ ADD requirements.txt /code/
|
|||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
ADD . /code/
|
||||
|
||||
RUN groupadd --gid 1000 spejstore && useradd --uid 1000 --gid 1000 --home /code --shell /bin/bash spejstore
|
||||
USER spejstore
|
||||
RUN python -m pip install gunicorn
|
||||
|
||||
CMD bash -c "python manage.py collectstatic --no-input --clear && python manage.py migrate && gunicorn --workers 1 --threads 4 -b 0.0.0.0:8000 --capture-output --error-logfile - --access-logfile - spejstore.wsgi:application"
|
||||
|
|
50
README.md
50
README.md
|
@ -1,47 +1,33 @@
|
|||
# spejstore (AKA inventory)
|
||||
|
||||
The general HSWAW (and other polish hackerspaces) inventory system.
|
||||
# spejstore
|
||||
|
||||
Because there is not enough general inventory software invented here yet.
|
||||
Please use Python3, for the love of `$deity`...
|
||||
|
||||
## Usage
|
||||
|
||||
### Quick start (VSCode)
|
||||
### Quick start
|
||||
|
||||
1. Copy `.env.example` as `.env`
|
||||
2. Have `docker compose` 2.0. You can identify it by having `docker compose` command instead of `docker-compose`.
|
||||
3. Customize your `.env` for your specific usecase.
|
||||
1. Run:
|
||||
```sh
|
||||
ln -s docker-compose.dev-override.yml docker-compose.override.yml
|
||||
docker-compose up --build
|
||||
```
|
||||
2. Run `docker-compose run --rm web python manage.py createsuperuser` -- now you can dev authenticate w/o SSO
|
||||
|
||||
#### VSCode
|
||||
### Build & run
|
||||
|
||||
0. Setup environment variables
|
||||
1. Get VSCode from [here](https://code.visualstudio.com/download), *CAN NOT* be VSCodium, as the extension is a microsoft binary which does not work with VSCodium.
|
||||
2. Install [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension
|
||||
3. Clone the repository and open it with VSCode.
|
||||
4. You should get a toast like this when re-opening directory with the cloned repository. ![Toast example](readme/toast-example.png 'Toast example')
|
||||
1. If you don't get a toast, then use (CMD|Ctrl)+Shift+P to open actions menu and choose option **Rebuild Without Cache and Reopen in Container**. ![Command example](readme/command-example.png 'Command example')
|
||||
5. Reopen the directory in container either via command or popup button.
|
||||
6. Wait for the application and container to properly build.
|
||||
1. Devcontainer's VSCode instance will be automatically configured with extensions to help your development process.
|
||||
2. You might get a Toast telling you to re-open the directory due to Black not working properly. Do so for proper autoformatting support.
|
||||
3. Make sure that extensions were installed in your vscode devcontainer. It might take a couple of minutes.
|
||||
7. `manage.py migrate` will be run automatically after container creation, to make sure you have the latest migrations done on the development database without any need for interaction.
|
||||
8. Run debug session with either command of "Start Debugging" (default hotkey F5), or with the Debug sidebar. ![Debug sidebar instructions](readme/debug-example.png 'Debug sidebar')
|
||||
9. You should have automatically forwarded ports, so the only thing remaining is opening browser window with the url provided in terminal.
|
||||
```sh
|
||||
docker-compose up --build
|
||||
|
||||
#### Everything else (docker)
|
||||
# if you need to reset built static files and/or postgres database:
|
||||
docker-compose up --build --renew-anon-volumes
|
||||
```
|
||||
|
||||
1. Run `docker compose up`. This will create a production-ready setup with gunicorn. out of the box.
|
||||
### Troubleshooting
|
||||
|
||||
### Everything else (python)
|
||||
- https://askubuntu.com/q/615394/413683
|
||||
|
||||
1. Get python3
|
||||
2. `pip install -r requirements.txt`
|
||||
3. `python3 manage.py migrate`
|
||||
4. `python3 manage.py collectstatic`
|
||||
5. `python3 manage.py runserver 0.0.0.0:8000`
|
||||
|
||||
## New docs (WIP)
|
||||
## New docs (WIP):
|
||||
|
||||
Spejstore is a simple inventory system made for Warsaw Hackerspace purposes. Includes some features very specific to hswaw requirements, which are:
|
||||
|
||||
|
|
17
docker-compose.dev-override.yml
Normal file
17
docker-compose.dev-override.yml
Normal file
|
@ -0,0 +1,17 @@
|
|||
version: "3"
|
||||
services:
|
||||
web:
|
||||
environment:
|
||||
- SPEJSTORE_ENV=dev
|
||||
- SPEJSTORE_DB_NAME=postgres
|
||||
- SPEJSTORE_DB_USER=postgres
|
||||
- SPEJSTORE_DB_PASSWORD=postgres
|
||||
- SPEJSTORE_DB_HOST=db
|
||||
# - SPEJSTORE_DB_PORT=
|
||||
- SPEJSTORE_ALLOWED_HOSTS=localhost,127.0.0.1
|
||||
# - SPEJSTORE_CLIENT_ID=
|
||||
# - SPEJSTORE_SECRET=
|
||||
# - SPEJSTORE_MEDIA_ROOT=
|
||||
# - SPEJSTORE_REQUIRE_AUTH=true
|
||||
- SPEJSTORE_OAUTH_REDIRECT_IS_HTTPS=false
|
||||
- SPEJSTORE_PROXY_TRUSTED_IPS=172.21.37.1
|
8
docker-compose.prod-override.yml
Normal file
8
docker-compose.prod-override.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
version: "3"
|
||||
|
||||
services:
|
||||
db:
|
||||
volumes:
|
||||
- /var/spejstore-data-new:/var/lib/postgresql/data
|
||||
web:
|
||||
build: .
|
|
@ -2,9 +2,7 @@ version: "3"
|
|||
services:
|
||||
db:
|
||||
image: postgres:15.4
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- spejstore-db:/var/lib/postgresql/data
|
||||
restart: always
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
|
@ -18,18 +16,13 @@ services:
|
|||
|
||||
web:
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
restart: always
|
||||
command: bash -c "python manage.py collectstatic --no-input --clear && python manage.py migrate && gunicorn --workers 1 --threads 4 -b 0.0.0.0:8000 --capture-output --error-logfile - --access-logfile - spejstore.wsgi:application"
|
||||
volumes:
|
||||
- .:/code
|
||||
- /code/build_static
|
||||
ports:
|
||||
- "8000:8000"
|
||||
env_file:
|
||||
- .env
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
spejstore-db:
|
||||
external: false
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 30 KiB |
Binary file not shown.
Before Width: | Height: | Size: 152 KiB |
Binary file not shown.
Before Width: | Height: | Size: 45 KiB |
|
@ -1,6 +1,4 @@
|
|||
asgiref==3.7.2
|
||||
boto3==1.34.32
|
||||
botocore==1.34.32
|
||||
certifi==2023.5.7
|
||||
cffi==1.15.1
|
||||
chardet==5.1.0
|
||||
|
@ -14,13 +12,12 @@ django-appconf==1.0.5
|
|||
django-hstore==1.4.2
|
||||
django-markdown2==0.3.1
|
||||
django-select2==8.1.2
|
||||
django-storages==1.14.2
|
||||
django-tree @ https://github.com/Palid/django-tree/archive/439e9a867e789b58f0c37e34e8ceb85ce1b806dc.zip#sha256=044e6766f4993512404492d7ec76949ca6b9ed44c88619ecc3a4e5339aa27b71
|
||||
django-storages[s3]==1.14.2
|
||||
# Django-tree
|
||||
https://github.com/Palid/django-tree/archive/master.zip
|
||||
djangorestframework==3.14.0
|
||||
docopt==0.6.2
|
||||
gunicorn==21.2.0
|
||||
idna==3.4
|
||||
jmespath==1.0.1
|
||||
markdown2==2.4.9
|
||||
oauthlib==3.2.2
|
||||
packaging==23.1
|
||||
|
@ -28,13 +25,10 @@ Pillow==10.0.0
|
|||
psycopg2==2.9.6
|
||||
pycparser==2.21
|
||||
PyJWT==2.7.0
|
||||
python-dateutil==2.8.2
|
||||
python3-openid==3.2.0
|
||||
pytz==2023.3
|
||||
requests==2.31.0
|
||||
requests-oauthlib==1.3.1
|
||||
s3transfer==0.10.0
|
||||
six==1.16.0
|
||||
social-auth-app-django==5.2.0
|
||||
social-auth-core==4.4.2
|
||||
sqlparse==0.4.4
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
"""
|
||||
Django settings for spejstore project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 1.10.1.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.10/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/1.10/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
|
@ -39,7 +51,7 @@ INSTALLED_APPS = [
|
|||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"django.contrib.postgres",
|
||||
"storages", # django-storages s3boto support
|
||||
"storages", # django-storages s3boto support
|
||||
"social_django",
|
||||
"tree",
|
||||
"django_select2",
|
||||
|
@ -159,11 +171,6 @@ SOCIAL_AUTH_PIPELINE = (
|
|||
|
||||
# Determines the storage type for Django static files and media.
|
||||
FILE_STORAGE_TYPE = env("FILE_STORAGE_TYPE", "filesystem")
|
||||
|
||||
# Make sure we check for correct file storage type
|
||||
if not (FILE_STORAGE_TYPE == "filesystem" or FILE_STORAGE_TYPE == "s3"):
|
||||
raise Exception("SPEJSTORE_FILE_STORAGE_TYPE must be 'filesystem' or 's3' ")
|
||||
|
||||
if FILE_STORAGE_TYPE == "filesystem":
|
||||
STORAGES = {
|
||||
"default": {
|
||||
|
@ -173,25 +180,14 @@ if FILE_STORAGE_TYPE == "filesystem":
|
|||
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
|
||||
},
|
||||
}
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.10/howto/static-files/
|
||||
|
||||
STATIC_URL = "/static/"
|
||||
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
|
||||
|
||||
MEDIA_URL = "/media/"
|
||||
MEDIA_ROOT = env("MEDIA_ROOT", os.path.join(BASE_DIR, "media"))
|
||||
|
||||
elif FILE_STORAGE_TYPE == "s3":
|
||||
S3_BUCKET_NAME = env("S3_BUCKET_NAME", "inventory")
|
||||
S3_ENDPOINT_URL = env("S3_ENDPOINT_URL", "https://object.ceph-eu.hswaw.net")
|
||||
S3_DOMAIN_NAME = env("S3_DOMAIN_NAME", "object.ceph-eu.hswaw.net")
|
||||
S3_ACCESS_KEY = env("S3_ACCESS_KEY", "")
|
||||
S3_SECRET_KEY = env("S3_SECRET_KEY", "=")
|
||||
|
||||
S3_STATIC_LOCATION = "static"
|
||||
S3_MEDIA_LOCATION = "media"
|
||||
|
||||
STORAGES = {
|
||||
"default": {
|
||||
"BACKEND": "storages.backends.s3.S3Storage",
|
||||
|
@ -219,13 +215,6 @@ elif FILE_STORAGE_TYPE == "s3":
|
|||
},
|
||||
},
|
||||
}
|
||||
bucket_domain_name = f"{S3_ENDPOINT_URL}/{S3_BUCKET_NAME}"
|
||||
STATIC_URL = f"{bucket_domain_name}/{S3_STATIC_LOCATION}/"
|
||||
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
|
||||
|
||||
MEDIA_URL = "/media/"
|
||||
STATIC_URL = f"{bucket_domain_name}/{S3_MEDIA_LOCATION}/"
|
||||
MEDIA_ROOT = env("MEDIA_ROOT", os.path.join(BASE_DIR, "media"))
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.10/topics/i18n/
|
||||
|
@ -236,6 +225,14 @@ USE_I18N = True
|
|||
USE_L10N = True
|
||||
USE_TZ = True
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.10/howto/static-files/
|
||||
|
||||
STATIC_URL = "/static/"
|
||||
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
|
||||
|
||||
MEDIA_URL = "/media/"
|
||||
MEDIA_ROOT = env("MEDIA_ROOT", os.path.join(BASE_DIR, "media"))
|
||||
|
||||
REQUIRE_AUTH = env("REQUIRE_AUTH", "true")
|
||||
if REQUIRE_AUTH == "true":
|
||||
|
|
|
@ -39,6 +39,13 @@ class LabelViewSet(viewsets.ModelViewSet):
|
|||
queryset = Label.objects.all()
|
||||
serializer_class = LabelSerializer
|
||||
|
||||
@action(
|
||||
detail=True,
|
||||
methods=["post"],
|
||||
)
|
||||
def print(self, request, pk):
|
||||
return api_print(request.query_params.get("quantity", 1), self.get_object())
|
||||
|
||||
|
||||
class ItemViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
|
|
|
@ -25,15 +25,8 @@ STATES = (
|
|||
)
|
||||
|
||||
|
||||
def api_print(item):
|
||||
resp = requests.post(
|
||||
"{}/api/2/print".format(settings.LABEL_API),
|
||||
params={
|
||||
"id": item.short_id(),
|
||||
"name": item.name,
|
||||
"owner": item.owner,
|
||||
}
|
||||
)
|
||||
def api_print(id):
|
||||
resp = requests.post("{}/api/1/print/{}".format(settings.LABEL_API, id))
|
||||
resp.raise_for_status()
|
||||
|
||||
|
||||
|
@ -131,7 +124,7 @@ class Item(models.Model, TreeModelMixin):
|
|||
return next((c for c in self.categories.all() if c.icon_id), None)
|
||||
|
||||
def print(self):
|
||||
api_print(self)
|
||||
api_print(self.short_id())
|
||||
|
||||
class Meta:
|
||||
ordering = ("path",)
|
||||
|
@ -165,3 +158,6 @@ class Label(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return "{}".format(self.id)
|
||||
|
||||
def print(self):
|
||||
api_print(self.id)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
{% load static %}
|
||||
{% if category and category.icon_id %}
|
||||
<div class="containericon" title="{{ category.name }}"><img src="{% static 'icons/' %}{{ category.icon_id }}.svg" />
|
||||
<div class="containericon" title="{{ category.name }}"><img src="/static/icons/{{ category.icon_id }}.svg" />
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in a new issue