Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend Improvements #85

Merged
merged 30 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e187d1d
Added form with many fields
JakeUrban Jan 7, 2020
e3c98f2
Added settings for custom widgets
JakeUrban Jan 7, 2020
4574e0b
Added SASS django support
JakeUrban Jan 8, 2020
78bf0f1
Add some basic CSS, replace bulma
vcarl Jan 10, 2020
88cba05
Pull in SCSS files from Bruno
vcarl Jan 10, 2020
8777729
Add some form template overrides
vcarl Jan 13, 2020
9437add
Refine input styles
vcarl Jan 13, 2020
f8250d7
Dump default django templates
vcarl Jan 13, 2020
9633f0d
Move form styles
vcarl Jan 13, 2020
45c66c4
Pretty up inputs
vcarl Jan 13, 2020
287f400
Pretty up layout
vcarl Jan 13, 2020
93ee116
Add prettier (broken) file picker
vcarl Jan 13, 2020
46a011c
Fix select dropdown
vcarl Jan 14, 2020
1fcb0ec
Fix file input
vcarl Jan 14, 2020
a0108f7
Added compilescss command to run.sh
JakeUrban Jan 14, 2020
5d42d02
Added title, guidance, and icon label template variable integrations
JakeUrban Jan 14, 2020
09f2d12
Remove changes to example settings
JakeUrban Jan 14, 2020
630d3e5
Add 'safe' tag to template variables
JakeUrban Jan 14, 2020
2683a2e
Adjust settings to allow server to override polaris' static assets
JakeUrban Jan 14, 2020
da062f8
Updated documentation
JakeUrban Jan 15, 2020
cd91ea2
Forgot to add docs on static files config
JakeUrban Jan 15, 2020
c92621f
Fixed bug tests failed for
JakeUrban Jan 15, 2020
d50603f
Added SASS_PROCESSOR_ROOT to setup documentation
JakeUrban Jan 15, 2020
d3dedf9
Updated docs and updated setup.py
JakeUrban Jan 15, 2020
c0d441e
Added CreditCardForm
JakeUrban Jan 15, 2020
92c5375
Made changes to CreditCardForm
JakeUrban Jan 15, 2020
8eb00f5
Fix layout styles
vcarl Jan 14, 2020
e8cd300
Add prettier radio buttons
vcarl Jan 15, 2020
eb15bb1
Polish amount input
vcarl Jan 15, 2020
d45b7f8
Add info list
vcarl Jan 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ MANIFEST
# Static files
polaris/polaris/collectstatic/*
!polaris/polaris/collectstatic/__init__.py
polaris/polaris/static/base.css
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is now created via python manage.py compilescss so we don't want to check it into version control


# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ django-cors-headers = "*"
toml = "*"
pyjwt = "*"
django-sslserver = "*"
libsass = "*"
django-compressor = "*"
django-sass-processor = "*"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packages needed to compile SCSS


[requires]
python_version = "3.7"
254 changes: 161 additions & 93 deletions Pipfile.lock

Large diffs are not rendered by default.

71 changes: 57 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,41 @@ Installation and Configuration
==============================

.. _CLI tool: https://github.com/msfeldstein/create-stellar-token
.. _Static Files: https://docs.djangoproject.com/en/2.2/howto/static-files/

First make sure you have ``cd``'ed into your django project's main directory
and then run
::

pip install django-polaris

Add it to ``INSTALLED_APPS`` in settings.py
Configuring settings.py
^^^^^^^^^^^^^^^^^^^^^^^

Add the following to ``INSTALLED_APPS`` in settings.py. Any app that overrides
a static asset in Polaris should be listed `before` "polaris". This ensures that
django will find your asset before the Polaris default.
::

INSTALLED_APPS = [
...,
"django.contrib.staticfiles",
"corsheaders",
"rest_framework",
"sass_processor",
"polaris",
]

Add Polaris' ``PolarisSameSiteMiddleware`` to your
``settings.MIDDLEWARE``. Make sure its listed `above` ``SessionMiddleware``.
Add Polaris' ``PolarisSameSiteMiddleware`` and ``CorsMiddleware`` to your
``settings.MIDDLEWARE``. The former must be listed `above` ``SessionMiddleware``.
::

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
...,
'polaris.middleware.PolarisSameSiteMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
...
]


Expand All @@ -72,15 +79,38 @@ find your ``.env`` file.

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Paste the text below into ``PROJECT_ROOT/.env``.
Add the following to your settings.py as well:
::

FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
STATIC_ROOT = os.path.join(BASE_DIR, "<your static root directory>")
STATIC_URL = "<your static url path>"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"sass_processor.finders.CssFinder",
]
SASS_PROCESSOR_ROOT = STATIC_ROOT
DEFAULT_PAGE_SIZE = <your default page size>

This allows Polaris to override django's default HTML widgets to provide
a great UI out of the box. See the `Static Files`_ django page for more
information.

Environment Variables
^^^^^^^^^^^^^^^^^^^^^

Polaris uses several environment variables that should be defined in the
environment or included in ``PROJECT_ROOT/.env``.
::

DJANGO_SECRET_KEY="yoursupersecretkey"
DJANGO_DEBUG=True

ASSETS="USD"
USD_STELLAR_DISTRIBUTION_ACCOUNT_SEED=""
USD_STELLAR_ISSUER_ACCOUNT_ADDRESS=""
USD_DISTRIBUTION_ACCOUNT_SEED=""
USD_ISSUER_ACCOUNT_ADDRESS=""

STELLAR_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
HORIZON_URI="https://horizon-testnet.stellar.org/"
Expand All @@ -94,6 +124,9 @@ account's private key and issuer account's public key. Note that each pair of va
names should be prepended with the asset code. The SDF has built a small `CLI tool`_
for creating these accounts on testnet.

Python Code and Bash Commands
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Add the Polaris endpoints in ``urls.py``
::

Expand All @@ -105,9 +138,19 @@ Add the Polaris endpoints in ``urls.py``
path("", include(polaris.urls)),
]

Run migrations: ``python manage.py migrate``
| Run migrations: ``python manage.py migrate``
| Compile static assets: ``python manage.py compilescss``
| Collect static assets: ``python manage.py collectstatic --no-input``

The last step is to add an ``Asset`` database object for the token you
intend to anchor. Get into the django python shell like so:
``python manage.py shell``, then:
::

from polaris.models import Asset
Asset.objects.create(code="USD", issuer="<the issuer address>")

You now have Polaris completely integrated into your Django project!
You are now ready to run the Polaris anchor server!

Running the Server Locally
^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
73 changes: 58 additions & 15 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,82 @@ Installation and Configuration
==============================

.. _CLI tool: https://github.com/msfeldstein/create-stellar-token
.. _Static Files: https://docs.djangoproject.com/en/2.2/howto/static-files/

First make sure you have ``cd``'ed into your django project's main directory
and then run
::

pip install django-polaris

Add it to ``INSTALLED_APPS`` in settings.py
Configuring settings.py
^^^^^^^^^^^^^^^^^^^^^^^

Add the following to ``INSTALLED_APPS`` in settings.py. Any app that overrides
a static asset in Polaris should be listed `before` "polaris". This ensures that
django will find your asset before the Polaris default.
::

INSTALLED_APPS = [
...,
"django.contrib.staticfiles",
"corsheaders",
"rest_framework",
"sass_processor",
"polaris",
]

Add Polaris' :doc:`PolarisSameSiteMiddleware </middleware/index>` to your
``settings.MIDDLEWARE``. Make sure its listed `above` ``SessionMiddleware``.
Add Polaris' :doc:`PolarisSameSiteMiddleware </middleware/index>` and
``CorsMiddleware`` to your ``settings.MIDDLEWARE``.
The form must be listed `above` ``SessionMiddleware``.
::

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
...,
'polaris.middleware.PolarisSameSiteMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
...
]


Define ``PROJECT_ROOT`` in your project's settings.py. Polaris uses this to
find your ``.env`` file.
::

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Paste the text below into ``PROJECT_ROOT/.env``.
Add the following to your settings.py as well:
::

FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
STATIC_ROOT = os.path.join(BASE_DIR, "<your static root directory>")
STATIC_URL = "<your static url path>"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"sass_processor.finders.CssFinder",
]
SASS_PROCESSOR_ROOT = STATIC_ROOT
DEFAULT_PAGE_SIZE = <your default page size>

This allows Polaris to override django's default HTML widgets to provide
a great UI out of the box. See the `Static Files`_ django page for more
information.

Environment Variables
^^^^^^^^^^^^^^^^^^^^^

Polaris uses several environment variables that should be defined in the
environment or included in ``PROJECT_ROOT/.env``.
::

DJANGO_SECRET_KEY="yoursupersecretkey"
DJANGO_DEBUG=True

ASSETS="USD"
USD_STELLAR_DISTRIBUTION_ACCOUNT_SEED=""
USD_STELLAR_ISSUER_ACCOUNT_ADDRESS=""
USD_DISTRIBUTION_ACCOUNT_SEED=""
USD_ISSUER_ACCOUNT_ADDRESS=""

STELLAR_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
HORIZON_URI="https://horizon-testnet.stellar.org/"
Expand All @@ -91,6 +121,9 @@ account's private key and issuer account's public key. Note that each pair of va
names should be prepended with the asset code. The SDF has built a small `CLI tool`_
for creating these accounts on testnet.

Python Code and Bash Commands
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Add the Polaris endpoints in ``urls.py``
::

Expand All @@ -102,9 +135,19 @@ Add the Polaris endpoints in ``urls.py``
path("", include(polaris.urls)),
]

Run migrations: ``python manage.py migrate``
| Run migrations: ``python manage.py migrate``
| Compile static assets: ``python manage.py compilescss``
| Collect static assets: ``python manage.py collectstatic --no-input``

The last step is to add an ``Asset`` database object for the token you
intend to anchor. Get into the django python shell like so:
``python manage.py shell``, then:
::

from polaris.models import Asset
Asset.objects.create(code="USD", issuer="<the issuer address>")

You now have Polaris completely integrated into your Django project!
You are now ready to run the Polaris anchor server!

Running the Server Locally
^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
15 changes: 0 additions & 15 deletions docs/integrations/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ integration functions for anchors to override.
Form Integrations
-----------------

.. _Bulma: https://bulma.io/documentation
.. _Django Forms: https://docs.djangoproject.com/en/2.2/topics/forms/#forms-in-django

Polaris uses `Django Forms`_ for collecting users' information, such as their
Expand All @@ -60,20 +59,6 @@ See the :doc:`../forms/index` documentation for the `TransactionForm` definition

.. autofunction:: polaris.integrations.WithdrawalIntegration.after_form_validation

Form CSS
^^^^^^^^
Polaris uses default CSS provided by Bulma_ for styling forms. To keep the
UX consistent, make sure to pass in a modified `widget` parameter to all
form fields displaying text like so:

::

widget=forms.widgets.TextInput(attrs={"class": "input"})

The `attrs` parameter adds a HTML attribute to the `<input>` tag that Bulma
uses to add better styling. You may also add more Bulma-supported attributes
to Polaris forms.

Use an External Application for the Interactive Flow
----------------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
# `Pipfile.lock` and then regenerate `requirements*.txt`.
################################################################################

django-compressor
django-cors-headers
django-environ
django-model-utils
django-sass-processor
django-sslserver
django==2.2.8
djangorestframework
libsass
psycopg2-binary
pyjwt
stellar-sdk==2.0.0
Expand Down
2 changes: 1 addition & 1 deletion example/server/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.db.models import QuerySet
from django import forms

from polaris.models import Transaction, Asset
from polaris.models import Transaction
from polaris.integrations import (
DepositIntegration,
WithdrawalIntegration,
Expand Down
20 changes: 15 additions & 5 deletions polaris/polaris/deposit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def post_interactive_deposit(request: Request) -> Response:
if error_resp:
return error_resp

form = rdi.form_for_transaction(transaction)(request.POST)
form_class, _ = rdi.form_for_transaction(transaction)
form = form_class(request.POST)
is_transaction_form = issubclass(form.__class__, TransactionForm)
if is_transaction_form:
form.asset = asset
Expand All @@ -115,9 +116,9 @@ def post_interactive_deposit(request: Request) -> Response:
rdi.after_form_validation(form, transaction)

# Check to see if there is another form to render
form_class = rdi.form_for_transaction(transaction)
form_data = rdi.form_for_transaction(transaction)

if form_class:
if form_data:
args = {"transaction_id": transaction.id, "asset_code": asset.code}
url = reverse("get_interactive_deposit")
return redirect(f"{url}?{urlencode(args)}")
Expand Down Expand Up @@ -158,10 +159,19 @@ def get_interactive_deposit(request: Request) -> Response:
if err_resp:
return err_resp

form = rdi.form_for_transaction(transaction)()
try:
form_class, context = rdi.form_for_transaction(transaction)
except TypeError:
return render_error_response(
"The anchor did not provide a form, unable to serve page.",
status_code=500,
content_type="text/html",
)

url_args = {"transaction_id": transaction.id, "asset_code": asset.code}
post_url = f"{reverse('post_interactive_deposit')}?{urlencode(url_args)}"
resp_data = {"form": form, "post_url": post_url}
resp_data = {"form": form_class(), "post_url": post_url}
resp_data.update(context)
return Response(resp_data, template_name="deposit/form.html")


Expand Down
Loading