added comment system preference
This commit is contained in:
parent
08b805a547
commit
8cd94d49e8
@ -1,4 +1,5 @@
|
|||||||
# only set this to true when testing/debugging
|
# only set this to true when testing/debugging
|
||||||
|
# when unset: 1 (true) - dont unset this, just for development
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
|
|
||||||
# hosts the application can run under e.g. recipes.mydomain.com,cooking.mydomain.com,...
|
# hosts the application can run under e.g. recipes.mydomain.com,cooking.mydomain.com,...
|
||||||
@ -18,9 +19,17 @@ POSTGRES_DB=djangodb
|
|||||||
# Serve mediafiles directly using gunicorn. Basically everyone recommends not doing this. Please use any of the examples
|
# Serve mediafiles directly using gunicorn. Basically everyone recommends not doing this. Please use any of the examples
|
||||||
# provided that include an additional nxginx container to handle media file serving.
|
# provided that include an additional nxginx container to handle media file serving.
|
||||||
# If you know what you are doing turn this back on (1) to serve media files using djangos serve() method.
|
# If you know what you are doing turn this back on (1) to serve media files using djangos serve() method.
|
||||||
|
# when unset: 1 (true) - this is temporary until an appropriate amount of time has passed for everyone to migrate
|
||||||
GUNICORN_MEDIA=0
|
GUNICORN_MEDIA=0
|
||||||
|
|
||||||
|
|
||||||
# allow authentication via reverse proxy (e.g. authelia), leave of if you dont know what you are doing
|
# allow authentication via reverse proxy (e.g. authelia), leave of if you dont know what you are doing
|
||||||
# docs: https://github.com/vabene1111/recipes/tree/develop/docs/docker/nginx-proxy%20with%20proxy%20authentication
|
# docs: https://github.com/vabene1111/recipes/tree/develop/docs/docker/nginx-proxy%20with%20proxy%20authentication
|
||||||
|
# when unset: 0 (false)
|
||||||
REVERSE_PROXY_AUTH=0
|
REVERSE_PROXY_AUTH=0
|
||||||
|
|
||||||
|
|
||||||
|
# the default value for the user preference 'comments' (enable/disable commenting system)
|
||||||
|
# when unset: 1 (true)
|
||||||
|
COMMENT_PREF_DEFAULT=1
|
||||||
|
|
||||||
|
@ -31,14 +31,15 @@ class UserPreferenceForm(forms.ModelForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserPreference
|
model = UserPreference
|
||||||
fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'show_recent', 'search_style', 'plan_share', 'ingredient_decimals')
|
fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'show_recent', 'search_style', 'plan_share', 'ingredient_decimals', 'comments')
|
||||||
|
|
||||||
help_texts = {
|
help_texts = {
|
||||||
'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!'),
|
'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!'),
|
||||||
'default_unit': _('Default Unit to be used when inserting a new ingredient into a recipe.'),
|
'default_unit': _('Default Unit to be used when inserting a new ingredient into a recipe.'),
|
||||||
'plan_share': _('Default user to share newly created meal plan entries with.'),
|
'plan_share': _('Default user to share newly created meal plan entries with.'),
|
||||||
'show_recent': _('Show recently viewed recipes on search page.'),
|
'show_recent': _('Show recently viewed recipes on search page.'),
|
||||||
'ingredient_decimals': _('Number of decimals to round ingredients.')
|
'ingredient_decimals': _('Number of decimals to round ingredients.'),
|
||||||
|
'comments': _('If you want to be able to create and see comments underneath recipes.')
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets = {
|
widgets = {
|
||||||
|
24
cookbook/migrations/0055_auto_20200616_1236.py
Normal file
24
cookbook/migrations/0055_auto_20200616_1236.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 3.0.7 on 2020-06-16 10:36
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cookbook', '0054_sharelink'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='userpreference',
|
||||||
|
name='comments',
|
||||||
|
field=models.BooleanField(default=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='sharelink',
|
||||||
|
name='uuid',
|
||||||
|
field=models.UUIDField(default=uuid.UUID('a6e8f192-cc03-4dd4-8a03-58d7ab6b7df7')),
|
||||||
|
),
|
||||||
|
]
|
@ -6,6 +6,8 @@ from django.contrib.auth.models import User
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
from recipes.settings import COMMENT_PREF_DEFAULT
|
||||||
|
|
||||||
|
|
||||||
def get_user_name(self):
|
def get_user_name(self):
|
||||||
if not (name := f"{self.first_name} {self.last_name}") == " ":
|
if not (name := f"{self.first_name} {self.last_name}") == " ":
|
||||||
@ -64,6 +66,7 @@ class UserPreference(models.Model):
|
|||||||
show_recent = models.BooleanField(default=True)
|
show_recent = models.BooleanField(default=True)
|
||||||
plan_share = models.ManyToManyField(User, blank=True, related_name='plan_share_default')
|
plan_share = models.ManyToManyField(User, blank=True, related_name='plan_share_default')
|
||||||
ingredient_decimals = models.IntegerField(default=2)
|
ingredient_decimals = models.IntegerField(default=2)
|
||||||
|
comments = models.BooleanField(default=COMMENT_PREF_DEFAULT)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.user)
|
return str(self.user)
|
||||||
|
@ -268,36 +268,39 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<br/>
|
{% if request.user.userpreference.comments %}
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<h5 {% if not comments %}class="d-print-none" {% endif %}><i class="far fa-comments"></i> {% trans 'Comments' %}
|
|
||||||
</h5>
|
|
||||||
{% for c in comments %}
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-body">
|
|
||||||
<small class="card-title">{{ c.updated_at }} {% trans 'by' %} {{ c.created_by.username }}</small> <a
|
|
||||||
href="{% url 'edit_comment' c.pk %}" class="d-print-none"><i class="fas fa-pencil-alt"></i></a><br/>
|
|
||||||
{{ c.text }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<br/>
|
<br/>
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% if request.user.is_authenticated %}
|
<h5 {% if not comments %}class="d-print-none" {% endif %}><i class="far fa-comments"></i> {% trans 'Comments' %}
|
||||||
<div class="d-print-none">
|
</h5>
|
||||||
|
{% for c in comments %}
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<small class="card-title">{{ c.updated_at }} {% trans 'by' %} {{ c.created_by.username }}</small> <a
|
||||||
|
href="{% url 'edit_comment' c.pk %}" class="d-print-none"><i
|
||||||
|
class="fas fa-pencil-alt"></i></a><br/>
|
||||||
|
{{ c.text }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
<form method="POST" class="post-form">
|
{% if request.user.is_authenticated %}
|
||||||
{% csrf_token %}
|
<div class="d-print-none">
|
||||||
<div class="input-group mb-3">
|
|
||||||
|
<form method="POST" class="post-form">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="input-group mb-3">
|
||||||
<textarea name="comment-text" cols="15" rows="2" class="textarea form-control" required
|
<textarea name="comment-text" cols="15" rows="2" class="textarea form-control" required
|
||||||
id="comment-id_text"></textarea>
|
id="comment-id_text"></textarea>
|
||||||
<div class="input-group-append">
|
<div class="input-group-append">
|
||||||
<input type="submit" value="{% trans 'Comment' %}" class="btn btn-success">
|
<input type="submit" value="{% trans 'Comment' %}" class="btn btn-success">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
</form>
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if recipe.storage %}
|
{% if recipe.storage %}
|
||||||
|
@ -215,6 +215,7 @@ def user_settings(request):
|
|||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
if not up:
|
if not up:
|
||||||
up = UserPreference(user=request.user)
|
up = UserPreference(user=request.user)
|
||||||
|
|
||||||
up.theme = form.cleaned_data['theme']
|
up.theme = form.cleaned_data['theme']
|
||||||
up.nav_color = form.cleaned_data['nav_color']
|
up.nav_color = form.cleaned_data['nav_color']
|
||||||
up.default_unit = form.cleaned_data['default_unit']
|
up.default_unit = form.cleaned_data['default_unit']
|
||||||
@ -223,6 +224,7 @@ def user_settings(request):
|
|||||||
up.search_style = form.cleaned_data['search_style']
|
up.search_style = form.cleaned_data['search_style']
|
||||||
up.plan_share.set(form.cleaned_data['plan_share'])
|
up.plan_share.set(form.cleaned_data['plan_share'])
|
||||||
up.ingredient_decimals = form.cleaned_data['ingredient_decimals']
|
up.ingredient_decimals = form.cleaned_data['ingredient_decimals']
|
||||||
|
up.comments = form.cleaned_data['comments']
|
||||||
up.save()
|
up.save()
|
||||||
|
|
||||||
if 'user_name_form' in request.POST:
|
if 'user_name_form' in request.POST:
|
||||||
|
@ -25,6 +25,8 @@ GUNICORN_MEDIA = bool(int(os.getenv('GUNICORN_MEDIA', True)))
|
|||||||
|
|
||||||
REVERSE_PROXY_AUTH = bool(int(os.getenv('REVERSE_PROXY_AUTH', False)))
|
REVERSE_PROXY_AUTH = bool(int(os.getenv('REVERSE_PROXY_AUTH', False)))
|
||||||
|
|
||||||
|
COMMENT_PREF_DEFAULT = bool(int(os.getenv('COMMENT_PREF_DEFAULT', True)))
|
||||||
|
|
||||||
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS').split(',') if os.getenv('ALLOWED_HOSTS') else ['*']
|
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS').split(',') if os.getenv('ALLOWED_HOSTS') else ['*']
|
||||||
|
|
||||||
CORS_ORIGIN_ALLOW_ALL = True
|
CORS_ORIGIN_ALLOW_ALL = True
|
||||||
|
Loading…
Reference in New Issue
Block a user