Skip to content
Snippets Groups Projects
Commit c54aceaf authored by plup's avatar plup
Browse files

feature: tied django startproject with custom template

parent 8ca6123c
No related branches found
Tags v2.3.19
1 merge request!158Load djangoldp conguration from YAML file
import click
from pkg_resources import resource_filename
from pathlib import Path
from django.core import management
from django.core.management.base import CommandError
from . import __version__
# click entrypoint
@click.group()
@click.version_option(__version__)
def main():
"""DjangoLDP"""
@main.command()
@click.argument('name', nargs=1)
@click.option('--production', is_flag=True, default=False, help='Use a production template')
def start(name, production):
"""Start a DjangoLDP project."""
try:
# set a directory from project name in pwd
directory = Path.cwd() / name
# create dir
directory.mkdir(parents=False, exist_ok=False)
# wrap the default django-admin startproject command
management.call_command('startproject', name, directory, template=get_template(production))
except FileExistsError:
click.echo(f'Error: the folder {directory} already exists')
except CommandError as e:
click.echo(f'Error: {e}')
def get_template(production):
"""Return the path of project template from package resouces."""
if production:
return resource_filename(__name__, 'templates/production')
return resource_filename(__name__, 'templates/development')
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
``` ```
# docker run --rm -v $PWD:/code -w /code -it python:3.6 bash # docker run --rm -v $PWD:/code -w /code -it python:3.6 bash
# pip install . # pip install .
# django-admin startproject sibserver /tmp/ --template /code/sib/templates/development/
# cd /tmp/ # cd /tmp/
# djangoldp start myproject
``` ```
Then configure `djangoldp_account` in `packages.yml` and install it: BUGFIX: Configure `djangoldp_account` in `packages.yml` and install it:
``` ```
# pip install djangoldp_account # pip install djangoldp_account
``` ```
......
...@@ -24,6 +24,12 @@ install_requires = ...@@ -24,6 +24,12 @@ install_requires =
django_rest_framework==0.1.0 django_rest_framework==0.1.0
requests==2.23.0 requests==2.23.0
pyyaml==5.3.1 pyyaml==5.3.1
pyyaml == 5.3.1
click == 7.1.1
[options.entry_points]
console_scripts =
djangoldp = djangoldp.cli:main
[options.extras_require] [options.extras_require]
dev = dev =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment