Skip to content

Commit

Permalink
Merge pull request #40 from schemen/dev
Browse files Browse the repository at this point in the history
version 1.2.0
  • Loading branch information
schemen authored Sep 14, 2021
2 parents d94d73e + fee7ac8 commit a911f46
Show file tree
Hide file tree
Showing 24 changed files with 426 additions and 261 deletions.
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions .idea/monsterforge.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog


## 1.2.0 (2021-09-14)

### Improvements

* Code refactoring and cleanup
* Migrate to Django 3.2 (From Django 2.2)
* Enhance RPG Agnostic aspect
* Several bugfixes
* Dependency updates

## 1.1.1 (2021-08-19)

### Improvements
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ The website at [forge.dice.quest](https://forge.dice.quest) provides tools for t
The website is free and contains no ads.
Feel free to contribute anything from commenting to design or new options and tools. If you plan something bigger, please contact me beforehand.

This project is supported by [JetBrains - PyCharm](https://www.jetbrains.com/pycharm/)!

### Fork

I took over as maintainer for the project originally made by matnad. I have since made it more perfomand, slimmer as well as added new features to it.
Expand Down
18 changes: 7 additions & 11 deletions dndtools/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os

# import secret settings
from .settings_secret import *


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand All @@ -32,7 +30,7 @@
else:
DEBUG = True

ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ['*']

# Email

Expand All @@ -52,12 +50,11 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.sites',
'paperminis.apps.PaperminisConfig',
'widget_tweaks',
]


MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -73,8 +70,8 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'templates/paperminis'), os.path.join(BASE_DIR, 'templates/registration')]
,
'DIRS': [os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'templates/paperminis'),
os.path.join(BASE_DIR, 'templates/registration')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand All @@ -89,7 +86,6 @@

WSGI_APPLICATION = 'dndtools.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
if os.getenv('PRODUCTION', False) == "True":
Expand All @@ -111,7 +107,6 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

Expand All @@ -130,7 +125,6 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

Expand All @@ -144,7 +138,6 @@

USE_TZ = True


LOGGING = {
'version': 1,
'disable_existing_loggers': False,
Expand Down Expand Up @@ -178,3 +171,6 @@

# Due to BestiaryLink we need to set this value higher
DATA_UPLOAD_MAX_NUMBER_FIELDS = 2500

# Set the AUTO_FIELD globally for Django 3.2
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
16 changes: 16 additions & 0 deletions example_monster.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"RPG Agnostic Creature": {
"img_url": "https://www.dndbeyond.com/avatars/thumbnails/0/301/1000/1000/636252771691385727.jpeg",
"name": "Orc",
"creature_size": "Medium"
},
"A Dnd SRE Creature": {
"CR": "3",
"alignment": "chaotic evil",
"img_url": "https://www.dndbeyond.com/avatars/thumbnails/0/74/1000/1000/636252734224239957.jpeg",
"name": "Werewolf",
"creature_size": "Medium",
"source": "Basic Rules",
"creature_type": "Humanoid"
}
}
2 changes: 1 addition & 1 deletion paperminis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.1.1'
__version__ = '1.2.0'
VERSION = __version__ # synonym
4 changes: 3 additions & 1 deletion paperminis/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class UserAdmin(DjangoUserAdmin):
search_fields = ('email', 'first_name', 'last_name')
ordering = ('email',)


class BestiaryInline(admin.TabularInline):
model = CreatureQuantity
extra = 1
Expand All @@ -35,7 +36,6 @@ def get_formset(self, request, obj=None, **kwargs):
self.parent_obj = obj
return super(BestiaryInline, self).get_formset(request, obj, **kwargs)


def formfield_for_foreignkey(self, db_field, request, **kwargs):
parent = self.parent_obj
if db_field.name == "creature":
Expand All @@ -49,12 +49,14 @@ class CreatureAdmin(admin.ModelAdmin):
list_filter = ['size']
fields = ['owner', 'name', 'img_url', 'size']


@admin.register(Bestiary)
class CreatureAdmin(admin.ModelAdmin):
list_display = ('owner', 'id', 'name')
fields = ['owner', 'name']
inlines = [BestiaryInline]


@admin.register(CreatureQuantity)
class CreatureQuantityAdmin(admin.ModelAdmin):
list_display = ('owner', 'id', 'creature', 'bestiary')
33 changes: 24 additions & 9 deletions paperminis/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,47 @@

from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import get_user_model

User = get_user_model()


class SignUpForm(UserCreationForm):
"""Used to register new users"""
# email
email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')

class Meta:
model = User
fields = ('email', 'password1', 'password2', )
fields = ('email', 'password1', 'password2',)


class CreatureModifyForm(forms.ModelForm):
"""Add or Update creatures"""
name = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control', 'size': '60%'}))

class Meta:
model = Creature
fields = ['name', 'show_name', 'img_url', 'creature_type', 'size', 'CR', 'position', 'color']

def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user') # To get request.user. Do not use kwargs.pop('user', None) due to potential security hole
#self.method = kwargs.pop('method') # To get create or update
# self.method = kwargs.pop('method') # To get create or update
super(CreatureModifyForm, self).__init__(*args, **kwargs)
self.fields['color'].required = False
self.fields['position'].required = False

def clean(self):
cleaned_data = super(CreatureModifyForm, self).clean()
if self.user:
name = cleaned_data.get("name")
img_url = cleaned_data.get("img_url")
cr = cleaned_data.get("CR")
# name + img_url must be unique. Otherwise raise a ValidationError
count = Creature.objects.filter(owner=self.user,name=name,img_url=img_url).exclude(id=self.instance.id).count()
count = Creature.objects.filter(owner=self.user, name=name, img_url=img_url).exclude(
id=self.instance.id).count()
if count == 1:
raise forms.ValidationError(('This creature already exists. Use a different name or image url.'), code='exists',)
raise forms.ValidationError(('This creature already exists. Use a different name or image url.'),
code='exists', )

# patreon early access backend validation
# if self.user.groups.filter(name='Patrons').count() <= 0:
Expand All @@ -56,16 +63,18 @@ def clean(self):
if not isinstance(cr, float) or cr < 0 or cr > 1000:
raise forms.ValidationError(('CR must a number be between 0 and 1000.'), code='value error', )


return cleaned_data


class BestiaryModifyForm(forms.ModelForm):
"""Simple bestiary create/update form"""
name = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control', 'size': '80%'}))

class Meta:
model = Bestiary
fields = ['name', ]


def validate_ddbenc_url(value):
if not value:
return # Required error is done the field
Expand All @@ -77,20 +86,23 @@ def validate_ddbenc_url(value):
class DDBEncounterBestiaryCreate(forms.Form):
"""create bestiary and monsters from ddb encounter"""
# URL
ddb_enc_url = forms.URLField(help_text="Required. Enter a Dndbeyond Encounter URL.",validators=[validate_ddbenc_url])
ddb_enc_url = forms.URLField(help_text="Required. Enter a Dndbeyond Encounter URL.",
validators=[validate_ddbenc_url])


class QuantityForm(forms.ModelForm):
"""Form to link creatures to bestiary. Most of this is done in views. """
quantity = forms.IntegerField()
#name = forms.CharField(max_length=150)

# name = forms.CharField(max_length=150)
class Meta:
model = Creature
fields = ['name',]
fields = ['name', ]


class PrintForm(forms.ModelForm):
"""Simple Form for print settings."""

class Meta:
model = PrintSettings
exclude = ['user']
Expand All @@ -104,14 +116,17 @@ def clean_darken(self):
raise forms.ValidationError("Enter a multiple of 1")
return darken


def validate_file_extension(value):
"""Function to validate json file extension and size."""
ext = os.path.splitext(value.name)[1]
valid_extensions = ['.json']
if not ext.lower() in valid_extensions:
raise ValidationError('Unsupported file extension. Please only upload .json files.')
if value.size > settings.MAX_UPLOAD_SIZE:
raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (filesizeformat(settings.MAX_UPLOAD_SIZE), filesizeformat(value._size)))
raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (
filesizeformat(settings.MAX_UPLOAD_SIZE), filesizeformat(value._size)))


class UploadFileForm(forms.Form):
"""Upload form with validator."""
Expand Down
Loading

0 comments on commit a911f46

Please sign in to comment.