main
Jaap Joris Vens 2021-01-23 10:29:24 +01:00
rodzic a5d468d54c
commit 8dcf61c766
5 zmienionych plików z 42 dodań i 31 usunięć

Wyświetl plik

@ -85,7 +85,7 @@ Another useful feature is the automatic compilation of `SCSS` files to
Use the provided helper command `simplecms` to quickly setup a new Use the provided helper command `simplecms` to quickly setup a new
project: project:
$ pip install https://github.com/rtts/django-simplecms.git $ pip install django-simplecms
$ simplecms mysite $ simplecms mysite
After the project files have been created, initialize the database and After the project files have been created, initialize the database and

Wyświetl plik

@ -1 +1,2 @@
__version__ = '1.0.4'
default_app_config = 'cms.apps.CmsConfig' default_app_config = 'cms.apps.CmsConfig'

Wyświetl plik

@ -1,48 +1,58 @@
import os, argparse, shutil, example import os, re, argparse, shutil, example, cms
from pip._internal.operations import freeze as pip from pip._internal.operations import freeze as pip
def main(): def main():
parser = argparse.ArgumentParser(description='SimpleCMS') parser = argparse.ArgumentParser(description='SimpleCMS')
parser.add_argument('project_name', nargs='?') parser.add_argument('project_name', nargs='?', default='.')
if project_name := parser.parse_args().project_name: project_name = parser.parse_args().project_name
project_dir = os.path.join(os.getcwd(), project_name) if project_name == '.':
else:
project_name = os.path.basename(os.getcwd())
project_dir = os.getcwd() project_dir = os.getcwd()
if input(f'Do you want to create a new project in `{project_dir}` ?\033[1D') in 'Yy': project_name = os.path.basename(project_dir)
create_project(project_name, project_dir) else:
project_dir = os.path.join(os.getcwd(), project_name)
if re.match(r'^\w+$', project_name):
if input(f'Do you want to create a new project in `{project_dir}` ?\033[1D') in 'Yy':
create_project(project_name, project_dir)
else:
print(f'Invalid project name: {project_name}')
def create_project(project_name, project_dir): def create_project(project_name, project_dir):
os.makedirs(project_dir, exist_ok=True) os.makedirs(project_dir, exist_ok=True)
with open(os.path.join(project_dir, 'requirements.txt'), 'w') as f: with open(os.path.join(project_dir, 'requirements.txt'), 'w') as f:
for line in pip.freeze(): for line in pip.freeze():
# Central point of failure
if 'django_simplecms' in line: if 'django_simplecms' in line:
line = 'git+https://github.com/rtts/django-simplecms' line = f'django-simplecms=={cms.__version__}'
print(line, file=f) print(line, file=f)
shutil.copytree(os.path.dirname(example.__file__), os.path.join(project_dir, project_name), dirs_exist_ok=True) shutil.copytree(os.path.dirname(example.__file__),os.path.join(project_dir, project_name), dirs_exist_ok=True)
with open(os.open(os.path.join(project_dir, 'manage.py'), os.O_CREAT|os.O_WRONLY, 0o755), 'w') as f: with open(os.open(os.path.join(project_dir, 'manage.py'), os.O_CREAT|os.O_WRONLY, 0o755), 'w') as f:
print('''#!/usr/bin/env python print('#!/usr/bin/env python',
import os, sys 'import os, sys',
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{project_name}.settings') f"os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{project_name}.settings')",
from django.core.management import execute_from_command_line 'from django.core.management import execute_from_command_line',
execute_from_command_line(sys.argv)''', file=f) 'execute_from_command_line(sys.argv)',
sep='\n', file=f)
with open(os.path.join(project_dir, project_name, 'wsgi.py'), 'w') as f:
print('import os',
'from django.core.wsgi import get_wsgi_application',
f"os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{project_name}.settings')",
'application = get_wsgi_application()',
sep='\n', file=f)
with open(os.path.join(project_dir, '.gitignore'), 'w') as f: with open(os.path.join(project_dir, '.gitignore'), 'w') as f:
print('*.pyc\n__pycache__/', file=f) print('*.pyc\n__pycache__/', file=f)
print(f''' print(f'Successfully created project "{project_name}"',
Successfully created project "{project_name}" '',
'Things to do next:',
'- create a database',
'- ./manage.py makemigrations',
'- ./manage.py migrate',
'- ./manage.py createsuperuser',
'- ./manage.py runserver',
sep='\n')
Things to do next:
- create a database
- ./manage.py makemigrations
- ./manage.py migrate
- ./manage.py createsuperuser
- ./manage.py runserver
''')
if __name__ == '__main__': if __name__ == '__main__':
main() main()

Wyświetl plik

@ -5,8 +5,7 @@ from django.conf.urls.static import static
from django.views.generic import RedirectView from django.views.generic import RedirectView
from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.contrib.staticfiles.urls import staticfiles_urlpatterns
admin.site.site_header = settings.PROJECT_NAME.capitalize() admin.site.site_header = admin.site.site_title = settings.PROJECT_NAME.replace('_', ' ').title()
admin.site.site_title = settings.PROJECT_NAME.capitalize()
urlpatterns = staticfiles_urlpatterns() + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns = staticfiles_urlpatterns() + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += [ urlpatterns += [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),

Wyświetl plik

@ -1,4 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
import cms
from setuptools import setup, find_packages from setuptools import setup, find_packages
with open('README.md', 'r') as fh: with open('README.md', 'r') as fh:
@ -7,7 +8,7 @@ with open('README.md', 'r') as fh:
setup( setup(
name = 'django-simplecms', name = 'django-simplecms',
description = 'Simple Django CMS', description = 'Simple Django CMS',
version = '1.0.3', version = cms.__version__,
author = 'Jaap Joris Vens', author = 'Jaap Joris Vens',
author_email = 'jj+cms@rtts.eu', author_email = 'jj+cms@rtts.eu',
url = 'https://github.com/rtts/django-simplecms', url = 'https://github.com/rtts/django-simplecms',