Add Address model and monero-python as dependency
This commit is contained in:
parent
996ac1312c
commit
903e55f75e
|
@ -0,0 +1,6 @@
|
|||
from django.contrib.auth.backends import ModelBackend
|
||||
|
||||
|
||||
class MoneroAddressBackend(ModelBackend):
|
||||
def authenticate(self, request, address=None, challenge=None, signature=None):
|
||||
pass
|
|
@ -0,0 +1,34 @@
|
|||
# Generated by Django 2.2.5 on 2019-10-15 14:37
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
import django_cryptolock.validators
|
||||
import model_utils.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Address',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
|
||||
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
|
||||
('address', models.CharField(max_length=106, validators=[django_cryptolock.validators.validate_monero_address])),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Address',
|
||||
'verbose_name_plural': 'Addresses',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -1,9 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from model_utils.models import TimeStampedModel
|
||||
|
||||
from .validators import validate_monero_address
|
||||
|
||||
|
||||
class Address(TimeStampedModel):
|
||||
pass
|
||||
"""Addresses that belong to a given user account."""
|
||||
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
address = models.CharField(max_length=106, validators=[validate_monero_address])
|
||||
|
||||
class Meta:
|
||||
"""Meta definition for Address."""
|
||||
|
||||
verbose_name = _("Address")
|
||||
verbose_name_plural = _("Addresses")
|
||||
|
||||
def __str__(self):
|
||||
"""Unicode representation of Address."""
|
||||
return self.address
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.conf import settings
|
||||
|
||||
from monero.address import Address
|
||||
|
||||
|
||||
def validate_monero_address(value):
|
||||
try:
|
||||
address = Address(value)
|
||||
except ValueError as e:
|
||||
raise ValidationError(
|
||||
_("%(value)s is not a valid address"), params={"value": value}
|
||||
)
|
||||
|
||||
network = getattr(settings, "MONERO_NETWORK", None)
|
||||
if not network:
|
||||
raise ValidationError(
|
||||
_("Please configure the monero network in the settings file")
|
||||
)
|
||||
if network == "mainnet" and not address.is_mainnet():
|
||||
raise ValidationError(_("Invalid address for mainnet"))
|
||||
elif network == "stagenet" and not address.is_stagenet():
|
||||
raise ValidationError(_("Invalid address for stagenet"))
|
||||
elif network == "testnet" and not address.is_testnet():
|
||||
raise ValidationError(_("Invalid address for testnet"))
|
|
@ -1,2 +1,3 @@
|
|||
django>=2.2
|
||||
django-model-utils>=2.0
|
||||
# Additional requirements go here
|
||||
monero>=0.6
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
-r requirements.txt
|
||||
|
||||
bumpversion==0.5.3
|
||||
wheel==0.30.0
|
||||
django-model-utils>=2.0
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
-r requirements.txt
|
||||
|
||||
coverage==4.4.1
|
||||
mock>=1.0.1
|
||||
flake8>=2.1.0
|
||||
tox>=1.7.0
|
||||
coveralls
|
||||
django-model-utils>=2.0
|
||||
|
||||
# Additional test requirements go here
|
||||
|
|
5
setup.py
5
setup.py
|
@ -44,6 +44,9 @@ if sys.argv[-1] == "tag":
|
|||
readme = open("README.rst").read()
|
||||
history = open("HISTORY.rst").read().replace(".. :changelog:", "")
|
||||
|
||||
with open("requirements.txt", "r") as f:
|
||||
requirements = [req.strip() for req in f.readlines()]
|
||||
|
||||
setup(
|
||||
name="django-cryptolock",
|
||||
version=version,
|
||||
|
@ -54,7 +57,7 @@ setup(
|
|||
url="https://github.com/dethos/django-cryptolock",
|
||||
packages=["django_cryptolock"],
|
||||
include_package_data=True,
|
||||
install_requires=["django-model-utils>=2.0"],
|
||||
install_requires=requirements,
|
||||
license="MIT",
|
||||
zip_safe=False,
|
||||
keywords="django-cryptolock",
|
||||
|
|
Loading…
Reference in New Issue