-
-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1671 from strikaco/modernize
Frontend CRUD enhancements (character/account creation and management)
- Loading branch information
Showing
29 changed files
with
1,310 additions
and
70 deletions.
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
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
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
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,56 @@ | ||
from django import forms | ||
from django.conf import settings | ||
from django.contrib.auth.forms import UserCreationForm, UsernameField | ||
from django.forms import ModelForm | ||
from django.utils.html import escape | ||
from evennia.utils import class_from_module | ||
|
||
class EvenniaForm(forms.Form): | ||
|
||
def clean(self): | ||
cleaned = super(EvenniaForm, self).clean() | ||
|
||
# Escape all values provided by user | ||
cleaned = {k:escape(v) for k,v in cleaned.items()} | ||
return cleaned | ||
|
||
class AccountForm(EvenniaForm, UserCreationForm): | ||
|
||
class Meta: | ||
model = class_from_module(settings.BASE_ACCOUNT_TYPECLASS) | ||
fields = ("username", "email") | ||
field_classes = {'username': UsernameField} | ||
|
||
email = forms.EmailField(help_text="A valid email address. Optional; used for password resets.", required=False) | ||
|
||
class ObjectForm(EvenniaForm, ModelForm): | ||
|
||
class Meta: | ||
model = class_from_module(settings.BASE_OBJECT_TYPECLASS) | ||
fields = ("db_key",) | ||
labels = { | ||
'db_key': 'Name', | ||
} | ||
|
||
class CharacterForm(ObjectForm): | ||
|
||
class Meta: | ||
# Get the correct object model | ||
model = class_from_module(settings.BASE_CHARACTER_TYPECLASS) | ||
# Allow entry of the 'key' field | ||
fields = ("db_key",) | ||
# Rename 'key' to something more intelligible | ||
labels = { | ||
'db_key': 'Name', | ||
} | ||
|
||
# Fields pertaining to user-configurable attributes on the Character object. | ||
desc = forms.CharField(label='Description', widget=forms.Textarea(attrs={'rows': 3}), max_length=2048, required=False) | ||
|
||
class CharacterUpdateForm(CharacterForm): | ||
""" | ||
Provides a form that only allows updating of db attributes, not model | ||
attributes. | ||
""" | ||
pass |
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
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,51 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block titleblock %} | ||
{{ view.page_title }} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
{% load addclass %} | ||
|
||
<div class="row"> | ||
<div class="col"> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<h1 class="card-title">{{ view.page_title }}</h1> | ||
<hr /> | ||
|
||
{% if form.errors %} | ||
{% for field in form %} | ||
{% for error in field.errors %} | ||
<div class="alert alert-danger" role="alert">{{ error }}</div> | ||
{% endfor %} | ||
{% endfor %} | ||
{% endif %} | ||
|
||
<form method="post" action="?"> | ||
{% csrf_token %} | ||
|
||
{% for field in form %} | ||
<div class="form-field my-3"> | ||
{{ field.label_tag }} | ||
{{ field | addclass:"form-control" }} | ||
{% if field.help_text %} | ||
<small class="form-text text-muted">{{ field.help_text|safe }}</small> | ||
{% endif %} | ||
</div> | ||
{% endfor %} | ||
|
||
<hr /> | ||
<div class="form-group"> | ||
<input class="form-control btn btn-outline-secondary" type="submit" value="Submit" /> | ||
<input type="hidden" name="next" value="{{ next }}" /> | ||
</div> | ||
</form> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{% endblock %} |
Oops, something went wrong.