Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add field Note for User model

michal2eb65ec10119
diff --git a/saleor/account/migrations/0019_user_note.py b/saleor/account/migrations/0019_user_note.py
new file mode 100644
index 0000000000..d42c6df707
--- /dev/null
+++ b/saleor/account/migrations/0019_user_note.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.0.3 on 2018-04-06 09:51
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('account', '0018_customernote'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='user',
+ name='note',
+ field=models.TextField(blank=True, null=True),
+ ),
+ ]
diff --git a/saleor/account/models.py b/saleor/account/models.py
index b9a722ee3f..24220ea26e 100644
--- a/saleor/account/models.py
+++ b/saleor/account/models.py
@@ -93,6 +93,7 @@ class User(PermissionsMixin, AbstractBaseUser):
addresses = models.ManyToManyField(Address, blank=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
+ note = models.TextField(null=True, blank=True)
date_joined = models.DateTimeField(default=timezone.now, editable=False)
default_shipping_address = models.ForeignKey(
Address, related_name='+', null=True, blank=True,
diff --git a/saleor/dashboard/customer/forms.py b/saleor/dashboard/customer/forms.py
index 2aa9d50367..12da3dc78b 100644
--- a/saleor/dashboard/customer/forms.py
+++ b/saleor/dashboard/customer/forms.py
@@ -11,10 +11,11 @@ class CustomerForm(forms.ModelForm):
# disable 'is_active' checkbox if user edits his own account
if self.user == self.instance:
self.fields['is_active'].disabled = True
+ self.fields['note'].disabled = True
class Meta:
model = User
- fields = ['email', 'is_active']
+ fields = ['email', 'is_active', 'note']
class CustomerNoteForm(forms.ModelForm):
diff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.html
index 07d6fc91ae..8643c33ccb 100644
--- a/templates/dashboard/customer/detail.html
+++ b/templates/dashboard/customer/detail.html
@@ -56,6 +56,18 @@
</div>
{% endif %}
</div>
+ <div class="row">
+ {% if customer.note %}
+ <div class="col s12 m4 l12">
+ <h4>
+ {% trans "Note" context "Customer field" %}
+ </h4>
+ <p>
+ {{ customer.note }}
+ </p>
+ </div>
+ {% endif %}
+ </div>
</div>
<div class="card-action">
{% if perms.account.edit_user %}
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index d6ac7e2a42..559a6f04bc 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -200,7 +200,10 @@
{% endif %}
</span>
{% if order.user %}
- <a href="{% url "dashboard:customer-details" pk=order.user.pk %}">{{ order.user }}</a>
+ <a href="{% url 'dashboard:customer-details' pk=order.user.pk %}">{{ order.user }}</a>
+ {% if order.user.note %}
+ <p>{{ order.user.note|truncatechars:80 }}</p>
+ {% endif %}
{% elif order.user_email %}
{{ order.user_email }}
{% else %}
diff --git a/templates/materializecssform/field.html b/templates/materializecssform/field.html
index 7049c49df2..874fc60e6b 100644
--- a/templates/materializecssform/field.html
+++ b/templates/materializecssform/field.html
@@ -151,7 +151,8 @@
<div class="input input-field col {{ classes.label }}">
<textarea id="{{ field.auto_id }}"
class="materialize-textarea {{ field.field.widget.attrs.class }}"
- name="{{ field.name }}">{% if field.value %}{{ field.value }}{% endif %}</textarea>
+ name="{{ field.name }}"
+ {% if field.field.disabled %} disabled {% endif %}>{% if field.value %}{{ field.value }}{% endif %}</textarea>
{% if field.auto_id %}
<label class="{{ classes.label }}" for="{{ field.auto_id }}">
{{ field.label }}