-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ef8617
commit 3122c38
Showing
10 changed files
with
2,984 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
.PHONY: help clean | ||
|
||
define BROWSER_PYSCRIPT | ||
import os, webbrowser, sys | ||
|
||
from urllib.request import pathname2url | ||
|
||
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) | ||
endef | ||
export BROWSER_PYSCRIPT | ||
|
||
BROWSER := python -c "$$BROWSER_PYSCRIPT" | ||
|
||
help: | ||
@echo "clean | Remove all build, test, coverage and Python artifacts" | ||
@echo "clean-build | Remove build artifacts" | ||
@echo "clean-pyc | Remove Python file artifacts" | ||
@echo "clean-test | Remove test and coverage artifacts" | ||
@echo "run | Run the project in Docker" | ||
|
||
clean: clean-build clean-pyc clean-test | ||
|
||
clean-build: | ||
rm -rf build/ | ||
rm -rf dist/ | ||
rm -rf **/*.egg-info | ||
rm -rf static/CACHE | ||
|
||
clean-pyc: | ||
find . -name '*.pyc' -exec rm -f {} + | ||
find . -name '*.pyo' -exec rm -f {} + | ||
find . -name '*~' -exec rm -f {} + | ||
find . -name '__pycache__' -exec rm -fr {} + | ||
|
||
clean-test: | ||
rm -rf .pytest_cache; \ | ||
rm -rf .ipython/profile_default; \ | ||
rm -rf htmlcov; \ | ||
rm -rf build; \ | ||
rm -f .coverage; \ | ||
rm -f coverage.xml; \ | ||
rm -f junit.xml; \ | ||
rm -rf .hypothesis; \ | ||
find . -name '*.py,cover' -exec rm -f {} + | ||
|
||
fix-file-permissions: | ||
sudo chown $$USER:$$USER src/fobi/migrations/ -R || true | ||
sudo chown $$USER:$$USER src/fobi/contrib/apps/djangocms_integration/migrations/ -R || true | ||
sudo chown $$USER:$$USER src/fobi/contrib/apps/wagtail_integration/migrations/ -R || true | ||
sudo chown $$USER:$$USER src/fobi/contrib/form_handlers/db_store/migrations/ -R || true | ||
sudo chown $$USER:$$USER examples/simple/page/migrations/ -R || true | ||
sudo chown $$USER:$$USER tmp/ -R || true | ||
|
||
run: prepare-required-files | ||
docker-compose -f docker-compose.yml up --remove-orphans; | ||
|
||
build: prepare-required-files | ||
docker-compose -f docker-compose.yml build; | ||
|
||
build-%: prepare-required-files | ||
docker-compose -f docker-compose.yml build $*; | ||
|
||
stop: | ||
docker-compose -f docker-compose.yml stop; | ||
|
||
make-migrations: | ||
docker-compose -f docker-compose.yml exec backend ./manage.py makemigrations $(APP); | ||
|
||
migrate: | ||
docker-compose -f docker-compose.yml exec backend ./manage.py migrate $(APP); | ||
|
||
test: | ||
docker-compose -f docker-compose.yml exec backend pytest /backend/src/ $(APP); | ||
|
||
show-migrations: | ||
docker-compose -f docker-compose.yml exec backend ./manage.py showmigrations | ||
|
||
show-urls: | ||
docker-compose -f docker-compose.yml exec backend ./manage.py show_urls | ||
|
||
shell: | ||
docker-compose -f docker-compose.yml exec backend python examples/simple/manage.py shell | ||
|
||
create-superuser: | ||
docker-compose -f docker-compose.yml exec backend python examples/simple/manage.py createsuperuser | ||
|
||
fobi-sync-plugins: | ||
docker-compose -f docker-compose.yml exec backend ./manage.py fobi_sync_plugins | ||
|
||
pip-install: | ||
docker-compose -f docker-compose.yml exec backend pip install -r requirements/local.txt | ||
|
||
pip-list: | ||
docker-compose -f docker-compose.yml exec backend pip list | ||
|
||
black: | ||
docker-compose -f docker-compose.yml exec backend black . | ||
|
||
isort: | ||
docker-compose -f docker-compose.yml exec backend isort . --overwrite-in-place | ||
|
||
bash: | ||
docker-compose -f docker-compose.yml run backend /bin/bash | ||
|
||
prepare-required-files: | ||
mkdir -p examples/logs examples/db examples/media examples/media/static examples/media/fobi_plugins/content_image | ||
mkdir -p examples/media/fobi_plugins/file |
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,30 @@ | ||
# Example configuration for Black. | ||
|
||
# NOTE: you have to use single-quoted strings in TOML for regular expressions. | ||
# It's the equivalent of r-strings in Python. Multiline strings are treated as | ||
# verbose regular expressions by Black. Use [ ] to denote a significant space | ||
# character. | ||
|
||
[tool.black] | ||
line-length = 80 | ||
target-version = ['py39'] | ||
include = '\.pyi?$' | ||
exclude = ''' | ||
/( | ||
\.eggs | ||
| \.git | ||
| \.hg | ||
| \.mypy_cache | ||
| \.tox | ||
| \.venv | ||
| _build | ||
| buck-out | ||
| build | ||
| dist | ||
| migrations | ||
# The following are specific to Black, you probably don't want those. | ||
| blib2to3 | ||
| tests/data | ||
| profiling | ||
)/ | ||
''' |
File renamed without changes.
Empty file.
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,22 @@ | ||
from django.urls import re_path as url | ||
from django.utils.translation import gettext_lazy as _ | ||
from fobi.views.class_based import ( | ||
CreateFormEntryView, | ||
) | ||
|
||
__title__ = 'fobi.urls.edit' | ||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>' | ||
__copyright__ = '2014-2019 Artur Barseghyan' | ||
__license__ = 'GPL 2.0/LGPL 2.1' | ||
__all__ = ('urlpatterns',) | ||
|
||
urlpatterns = [ | ||
# *********************************************************************** | ||
# **************************** Form entry CUD *************************** | ||
# *********************************************************************** | ||
|
||
# Create form entry | ||
url(_(r'^forms/create/$'), | ||
view=CreateFormEntryView.as_view(), | ||
name='fobi.create_form_entry'), | ||
] |
Empty file.
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 @@ | ||
from .function_based import * |
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,81 @@ | ||
from django.contrib import messages | ||
from django.db import IntegrityError | ||
from django.shortcuts import redirect | ||
from django.urls import reverse_lazy | ||
from django.utils.translation import gettext_lazy as _ | ||
from django.views import View | ||
from django.views.generic import CreateView | ||
|
||
from ..base import get_theme | ||
from ..forms import FormEntryForm | ||
|
||
__all__ = ("CreateFormEntryView",) | ||
|
||
|
||
class CreateFormEntryView(CreateView): | ||
"""Create form entry view.""" | ||
|
||
template_name = None | ||
form_class = FormEntryForm | ||
theme = None | ||
|
||
def get_context_data(self, **kwargs): | ||
"""Get context data.""" | ||
context = super().get_context_data(**kwargs) | ||
context["form"] = self.get_form() | ||
if self.theme: | ||
context.update({"fobi_theme": self.theme}) | ||
return context | ||
|
||
def get_template_names(self): | ||
"""Get template names.""" | ||
template_name = self.template_name | ||
if not template_name: | ||
if not self.theme: | ||
theme = get_theme(request=self.request, as_instance=True) | ||
template_name = theme.create_form_entry_template | ||
return [template_name] | ||
|
||
def get_form_kwargs(self): | ||
kwargs = super().get_form_kwargs() | ||
kwargs["request"] = self.request | ||
return kwargs | ||
|
||
def get(self, request, *args, **kwargs): | ||
"""Handle GET requests: instantiate a blank version of the form.""" | ||
self.object = None | ||
return self.render_to_response(self.get_context_data()) | ||
|
||
def post(self, request, *args, **kwargs): | ||
""" | ||
Handle POST requests: instantiate a form instance with the passed | ||
POST variables and then check if it's valid. | ||
""" | ||
self.object = None | ||
form = self.get_form() | ||
if form.is_valid(): | ||
form_entry = form.save(commit=False) | ||
form_entry.user = request.user | ||
try: | ||
form_entry.save() | ||
messages.info( | ||
request, | ||
_("Form {0} was created successfully.").format( | ||
form_entry.name | ||
), | ||
) | ||
return redirect( | ||
"fobi.edit_form_entry", form_entry_id=form_entry.pk | ||
) | ||
except IntegrityError as err: | ||
messages.info( | ||
request, | ||
_("Errors occurred while saving the form: {0}.").format( | ||
str(err) | ||
), | ||
) | ||
|
||
return self.render_to_response(self.get_context_data()) | ||
|
||
def post_hook(self, form_entry): | ||
"""Post hook.""" |
Oops, something went wrong.