mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Rename Matmat to Trombi
This commit is contained in:
@ -1,24 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2017
|
||||
# - Skia <skia@libskia.so>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License a published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
@ -1,29 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2017
|
||||
# - Skia <skia@libskia.so>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License a published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
from matmat.models import Matmat
|
||||
|
||||
admin.site.register(Matmat)
|
@ -1,42 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('club', '0007_auto_20170324_0917'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Matmat',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
|
||||
('subscription_deadline', models.DateField(verbose_name='subscription deadline', default=django.utils.timezone.now, help_text='Before this date, users are allowed to subscribe to this Matmatronch. After this date, users subscribed will be allowed to comment on each other.')),
|
||||
('comments_deadline', models.DateField(verbose_name='comments deadline', default=django.utils.timezone.now, help_text="After this date, users won't be able to make comments anymore")),
|
||||
('club', models.OneToOneField(related_name='matmat', to='club.Club')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='MatmatComment',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, blank=True, verbose_name='matmat', to=settings.AUTH_USER_MODEL, related_name='users', null=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='MatmatUser',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
|
||||
('matmat', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, blank=True, verbose_name='matmat', to='matmat.Matmat', related_name='users', null=True)),
|
||||
('user', models.OneToOneField(related_name='matmat_user', verbose_name='matmat user', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
@ -1,41 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('matmat', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='matmat',
|
||||
name='max_chars',
|
||||
field=models.IntegerField(help_text='maximum number of characters allowed in a comment', default=400, verbose_name='maximum characters'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='matmatcomment',
|
||||
name='content',
|
||||
field=models.TextField(default='', verbose_name='content'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='matmatcomment',
|
||||
name='is_moderated',
|
||||
field=models.BooleanField(default=False, verbose_name='is moderated'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='matmatcomment',
|
||||
name='target',
|
||||
field=models.ForeignKey(verbose_name='target', to='matmat.MatmatUser', related_name='received_comments', default=0),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='matmatcomment',
|
||||
name='author',
|
||||
field=models.ForeignKey(verbose_name='author', to='matmat.MatmatUser', related_name='given_comments', default=0),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -1,18 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('matmat', '0002_auto_20170510_1754'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='matmatcomment',
|
||||
name='is_moderated',
|
||||
),
|
||||
]
|
107
matmat/models.py
107
matmat/models.py
@ -1,107 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2017
|
||||
# - Skia <skia@libskia.so>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License a published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from datetime import timedelta, date
|
||||
|
||||
from core.models import User
|
||||
from club.models import Club
|
||||
|
||||
class MatmatManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super(MatmatManager, self).get_queryset()
|
||||
|
||||
class AvailableMatmatManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super(AvailableMatmatManager,
|
||||
self).get_queryset().filter(subscription_deadline__gte=date.today())
|
||||
|
||||
class Matmat(models.Model):
|
||||
"""
|
||||
This is the main class, the Matmat itself.
|
||||
It contains the deadlines for the users, and the link to the club that makes
|
||||
its Matmatronch.
|
||||
"""
|
||||
subscription_deadline = models.DateField(_('subscription deadline'),
|
||||
default=timezone.now, help_text=_("Before this date, users are "
|
||||
"allowed to subscribe to this Matmatronch. "
|
||||
"After this date, users subscribed will be allowed to comment on each other."))
|
||||
comments_deadline = models.DateField(_('comments deadline'),
|
||||
default=timezone.now, help_text=_("After this date, users won't be "
|
||||
"able to make comments anymore"))
|
||||
max_chars = models.IntegerField(_('maximum characters'), default=400,
|
||||
help_text=_('maximum number of characters allowed in a comment'))
|
||||
club = models.OneToOneField(Club, related_name='matmat')
|
||||
|
||||
objects = MatmatManager()
|
||||
availables = AvailableMatmatManager()
|
||||
|
||||
def __str__(self):
|
||||
return str(self.club.name)
|
||||
|
||||
def clean(self):
|
||||
if self.subscription_deadline > self.comments_deadline:
|
||||
raise ValidationError(_("Closing the subscriptions after the "
|
||||
"comments is definitively not a good idea."))
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('matmat:detail', kwargs={'matmat_id': self.id})
|
||||
|
||||
def is_owned_by(self, user):
|
||||
return user.is_owner(self.club)
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
return user.can_edit(self.club)
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
return user.id in [u.user.id for u in self.users.all()]
|
||||
|
||||
class MatmatUser(models.Model):
|
||||
"""
|
||||
This class is only here to avoid cross references between the core, club,
|
||||
and matmat modules. It binds a User to a Matmat without needing to import
|
||||
Matmat into the core.
|
||||
"""
|
||||
user = models.OneToOneField(User, verbose_name=_("matmat user"), related_name='matmat_user')
|
||||
matmat = models.ForeignKey(Matmat, verbose_name=_("matmat"), related_name='users', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
|
||||
class MatmatComment(models.Model):
|
||||
"""
|
||||
This represent a comment given by someone to someone else in the same Matmat
|
||||
instance.
|
||||
"""
|
||||
author = models.ForeignKey(MatmatUser, verbose_name=_("author"), related_name='given_comments')
|
||||
target = models.ForeignKey(MatmatUser, verbose_name=_("target"), related_name='received_comments')
|
||||
content = models.TextField(_("content"), default="")
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
if user.id == self.target.user.id:
|
||||
return False
|
||||
return user.id == self.author.user.id or user.can_edit(self.author.matmat)
|
@ -1,19 +0,0 @@
|
||||
{% extends 'core/base.jinja' %}
|
||||
|
||||
{% block title %}
|
||||
{% trans club=object.club %}{{ club }}'s Matmatronch{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{% trans club=object.club %}{{ club }}'s Matmatronch{% endtrans %}</h2>
|
||||
<a href="{{ url('matmat:edit', matmat_id=object.id) }}">Edit</a>
|
||||
<p>Subscription deadline: {{ object.subscription_deadline|date(DATETIME_FORMAT) }}</p>
|
||||
<p>Comment deadline: {{ object.comments_deadline|date(DATETIME_FORMAT) }}</p>
|
||||
<a href="#">Export</a>
|
||||
<p>People:</p>
|
||||
<ul>
|
||||
{% for u in object.users.all() %}
|
||||
<li>{{ u.user.get_display_name() }} - <a href="{{ url('matmat:delete_user', matmat_id=object.id, user_id=u.id) }}">Delete</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
@ -1,34 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans user_name=user.get_display_name() %}{{ user_name }}'s Matmat{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>{% trans%}Matmatronch'{% endtrans %}</h3>
|
||||
{% if subscribe_form %}
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ subscribe_form.as_p() }}
|
||||
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
||||
</form>
|
||||
{% else %}
|
||||
<p>{% trans matmat = user.matmat_user.matmat %}You are subscribed to the Matmatronch {{ matmat }}{% endtrans %}</p>
|
||||
<p><a href="{{ url("matmat:profile") }}">Edit my profile</a></p>
|
||||
<hr>
|
||||
<div>
|
||||
{% for u in user.matmat_user.matmat.users.exclude(id=user.matmat_user.id) %}
|
||||
<div class="ib">
|
||||
<div>{{ u.user.get_display_name() }}</div>
|
||||
{% set comment = u.received_comments.filter(author__id=user.matmat_user.id).first() %}
|
||||
{% if comment %}
|
||||
<a href="{{ url("matmat:edit_comment", comment_id=comment.id) }}">Edit comment</a>
|
||||
{% else %}
|
||||
<a href="{{ url("matmat:new_comment", user_id=u.id) }}">Comment</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
@ -1,27 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2017
|
||||
# - Skia <skia@libskia.so>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License a published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -1,39 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2017
|
||||
# - Skia <skia@libskia.so>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License a published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
||||
from django.conf.urls import url, include
|
||||
|
||||
from matmat.views import *
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^(?P<club_id>[0-9]+)/new$', MatmatCreateView.as_view(), name='create'),
|
||||
url(r'^(?P<matmat_id>[0-9]+)/edit$', MatmatEditView.as_view(), name='edit'),
|
||||
url(r'^(?P<matmat_id>[0-9]+)/delete/(?P<user_id>[0-9]+)$', MatmatDeleteUserView.as_view(), name='delete_user'),
|
||||
url(r'^(?P<matmat_id>[0-9]+)$', MatmatDetailView.as_view(), name='detail'),
|
||||
url(r'^(?P<user_id>[0-9]+)/new_comment$', MatmatCommentCreateView.as_view(), name='new_comment'),
|
||||
url(r'^comment/(?P<comment_id>[0-9]+)/edit$', MatmatCommentEditView.as_view(), name='edit_comment'),
|
||||
url(r'^tools$', UserMatmatToolsView.as_view(), name='user_tools'),
|
||||
url(r'^profile$', UserMatmatEditProfileView.as_view(), name='profile'),
|
||||
]
|
||||
|
170
matmat/views.py
170
matmat/views.py
@ -1,170 +0,0 @@
|
||||
# -*- coding:utf-8 -*
|
||||
#
|
||||
# Copyright 2017
|
||||
# - Skia <skia@libskia.so>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License a published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.core.urlresolvers import reverse_lazy, reverse
|
||||
from django.views.generic import ListView, DetailView, RedirectView, TemplateView
|
||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView, FormView, SingleObjectMixin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django import forms
|
||||
from django.forms.models import modelform_factory
|
||||
|
||||
from matmat.models import Matmat, MatmatUser, MatmatComment
|
||||
from core.views.forms import SelectFile, SelectDate
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, CanCreateMixin, QuickNotifMixin
|
||||
from core.models import User
|
||||
from club.models import Club
|
||||
|
||||
class MatmatForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Matmat
|
||||
fields = ['subscription_deadline', 'comments_deadline', 'max_chars']
|
||||
widgets = {
|
||||
'subscription_deadline': SelectDate,
|
||||
'comments_deadline': SelectDate,
|
||||
}
|
||||
|
||||
class MatmatCreateView(CanEditPropMixin, CreateView):
|
||||
"""
|
||||
Create a matmat for a club
|
||||
"""
|
||||
model = Matmat
|
||||
form_class = MatmatForm
|
||||
template_name = 'core/create.jinja'
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""
|
||||
Affect club
|
||||
"""
|
||||
form = self.get_form()
|
||||
if form.is_valid():
|
||||
club = get_object_or_404(Club, id=self.kwargs['club_id'])
|
||||
form.instance.club = club
|
||||
ret = self.form_valid(form)
|
||||
return ret
|
||||
else:
|
||||
return self.form_invalid(form)
|
||||
|
||||
class MatmatEditView(CanEditPropMixin, UpdateView):
|
||||
model = Matmat
|
||||
form_class = MatmatForm
|
||||
template_name = 'core/edit.jinja'
|
||||
pk_url_kwarg = 'matmat_id'
|
||||
|
||||
class MatmatDetailView(CanEditMixin, DetailView):
|
||||
model = Matmat
|
||||
template_name = 'matmat/detail.jinja'
|
||||
pk_url_kwarg = 'matmat_id'
|
||||
|
||||
class MatmatDeleteUserView(CanEditPropMixin, SingleObjectMixin, RedirectView):
|
||||
model = Matmat
|
||||
pk_url_kwarg = 'matmat_id'
|
||||
permanent = False
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
user = get_object_or_404(MatmatUser, id=self.kwargs['user_id'])
|
||||
user.delete()
|
||||
# See if we need to also delete the comments on the user, or if we keep them
|
||||
return redirect(self.object.get_absolute_url())
|
||||
|
||||
# User side
|
||||
class UserMatmatForm(forms.Form):
|
||||
matmat = forms.ModelChoiceField(Matmat.availables.all(), required=False, label=_("Select matmatronch"),
|
||||
help_text=_("This allows you to subscribe to a Matmatronch. "
|
||||
"Be aware that you can subscribe only once, so don't play with that, "
|
||||
"or you will expose yourself to the admins' wrath!"))
|
||||
|
||||
class UserMatmatToolsView(QuickNotifMixin, TemplateView):
|
||||
"""
|
||||
Display a user's matmat tools
|
||||
"""
|
||||
template_name = "matmat/user_tools.jinja"
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.form = UserMatmatForm(request.POST)
|
||||
if self.form.is_valid():
|
||||
matmat_user = MatmatUser(user=request.user,
|
||||
matmat=self.form.cleaned_data['matmat'])
|
||||
matmat_user.save()
|
||||
self.quick_notif_list += ['qn_success']
|
||||
return super(UserMatmatToolsView, self).get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(UserMatmatToolsView, self).get_context_data(**kwargs)
|
||||
kwargs['user'] = self.request.user
|
||||
if not hasattr(self.request.user, 'matmat_user'):
|
||||
kwargs['subscribe_form'] = UserMatmatForm()
|
||||
return kwargs
|
||||
|
||||
class UserMatmatEditProfileView(UpdateView):
|
||||
model = User
|
||||
form_class = modelform_factory(User,
|
||||
fields=['second_email', 'phone', 'department', 'dpt_option',
|
||||
'quote', 'parent_address'],
|
||||
labels={
|
||||
'second_email': _("Personal email (not UTBM)"),
|
||||
'phone': _("Phone"),
|
||||
'parent_address': _("Native town"),
|
||||
})
|
||||
template_name = "core/edit.jinja"
|
||||
success_url = reverse_lazy('matmat:user_tools')
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
class MatmatCommentFormView():
|
||||
"""
|
||||
Create/edit a matmat comment
|
||||
"""
|
||||
model = MatmatComment
|
||||
fields = ['content']
|
||||
|
||||
def get_form_class(self):
|
||||
self.matmat = self.request.user.matmat_user.matmat
|
||||
return modelform_factory(self.model, fields=self.fields,
|
||||
widgets={
|
||||
'content': forms.widgets.Textarea(attrs={'maxlength': self.matmat.max_chars})
|
||||
},
|
||||
help_texts={
|
||||
'content': _("Maximum characters: %(max_length)s") % {'max_length': self.matmat.max_chars}
|
||||
})
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('matmat:user_tools')
|
||||
|
||||
class MatmatCommentCreateView(MatmatCommentFormView, CreateView):
|
||||
template_name = 'core/create.jinja'
|
||||
|
||||
def form_valid(self, form):
|
||||
target = get_object_or_404(MatmatUser, id=self.kwargs['user_id'])
|
||||
form.instance.author = self.request.user.matmat_user
|
||||
form.instance.target = target
|
||||
return super(MatmatCommentCreateView, self).form_valid(form)
|
||||
|
||||
class MatmatCommentEditView(MatmatCommentFormView, CanViewMixin, UpdateView):
|
||||
pk_url_kwarg = "comment_id"
|
||||
template_name = 'core/edit.jinja'
|
||||
|
||||
|
Reference in New Issue
Block a user