mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 15:51:19 +00:00
Add gift function
This commit is contained in:
parent
9ab7cb98dc
commit
e3fd3b81ab
25
core/migrations/0027_gift.py
Normal file
25
core/migrations/0027_gift.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0026_auto_20170926_1512'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Gift',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)),
|
||||
('label', models.CharField(max_length=255, verbose_name='label')),
|
||||
('date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date')),
|
||||
('user', models.ForeignKey(related_name='gifts', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
@ -2,6 +2,7 @@
|
||||
#
|
||||
# Copyright 2016,2017
|
||||
# - Skia <skia@libskia.so>
|
||||
# - Sli <antoine@bartuccio.fr>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
@ -1109,3 +1110,15 @@ class Notification(models.Model):
|
||||
old_notif.save()
|
||||
return
|
||||
super(Notification, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class Gift(models.Model):
|
||||
label = models.CharField(_('label'), max_length=255)
|
||||
date = models.DateTimeField(_('date'), default=timezone.now)
|
||||
user = models.ForeignKey(User, related_name='gifts')
|
||||
|
||||
def __str__(self):
|
||||
return "%s - %s" % (self.label, self.date.strftime('%d %b %Y'))
|
||||
|
||||
def is_owned_by(self, user):
|
||||
return user.is_board_member or user.is_root
|
||||
|
@ -66,13 +66,39 @@
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% trans %}Not subscribed{% endtrans %}
|
||||
{% if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) %}
|
||||
{% if user.is_board_member %}
|
||||
<a href="{{ url('subscription:subscription') }}?member={{ profile.id }}">{% trans %}New subscription{% endtrans %}</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_root or user.is_board_member %}
|
||||
<hr>
|
||||
<form style="margin-left: 0px;" action="{{ url('core:user_gift_create', user_id=profile.id) }}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ gift_form.label }}
|
||||
{{ gift_form.user }}
|
||||
<input type="submit" value="{% trans %}Give gift{% endtrans %}">
|
||||
</form>
|
||||
{% if profile.gifts.exists() %}
|
||||
<br>
|
||||
<div id="drop_gifts">
|
||||
<h5>{% trans %}Last given gift :{% endtrans %} {{ profile.gifts.order_by('-date').first() }}</h5>
|
||||
<div>
|
||||
<ul>
|
||||
{% for gift in profile.gifts.all().order_by('-date') %}
|
||||
<li>{{ gift }} <a href="{{ url('core:user_gift_delete', user_id=profile.id, gift_id=gift.id) }}">{% trans %}Delete{% endtrans %}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
{% trans %}No gift given yet{% endtrans %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
@ -92,6 +118,13 @@ $( function() {
|
||||
}
|
||||
});
|
||||
} );
|
||||
$(function(){
|
||||
$("#drop_gifts").accordion({
|
||||
heightStyle: "content",
|
||||
collapsible: true,
|
||||
active: false
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#
|
||||
# Copyright 2016,2017
|
||||
# - Skia <skia@libskia.so>
|
||||
# - Sli <antoine@bartuccio.fr>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
@ -73,6 +74,8 @@ urlpatterns = [
|
||||
url(r'^user/(?P<user_id>[0-9]+)/account$', UserAccountView.as_view(), name='user_account'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/account/(?P<year>[0-9]+)/(?P<month>[0-9]+)$', UserAccountDetailView.as_view(), name='user_account_detail'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/stats$', UserStatsView.as_view(), name='user_stats'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/gift/create$', GiftCreateView.as_view(), name='user_gift_create'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/gift/delete/(?P<gift_id>[0-9]+)/$', GiftDeleteView.as_view(), name='user_gift_delete'),
|
||||
|
||||
# File views
|
||||
# url(r'^file/add/(?P<popup>popup)?$', FileCreateView.as_view(), name='file_new'),
|
||||
|
@ -2,6 +2,7 @@
|
||||
#
|
||||
# Copyright 2016,2017
|
||||
# - Skia <skia@libskia.so>
|
||||
# - Sli <antoine@bartuccio.fr>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
@ -35,7 +36,7 @@ from ajax_select.fields import AutoCompleteSelectField
|
||||
|
||||
import re
|
||||
|
||||
from core.models import User, Page, SithFile
|
||||
from core.models import User, Page, SithFile, Gift
|
||||
|
||||
from core.utils import resize_image
|
||||
from io import BytesIO
|
||||
@ -283,3 +284,18 @@ class PageForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(PageForm, self).__init__(*args, **kwargs)
|
||||
self.fields['parent'].queryset = self.fields['parent'].queryset.exclude(name=settings.SITH_CLUB_ROOT_PAGE).filter(club=None)
|
||||
|
||||
|
||||
class GiftForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Gift
|
||||
fields = ['label', 'user']
|
||||
|
||||
label = forms.ChoiceField(choices=settings.SITH_GIFT_LIST)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
user_id = kwargs.pop('user_id', None)
|
||||
super(GiftForm, self).__init__(*args, **kwargs)
|
||||
if user_id:
|
||||
self.fields['user'].queryset = self.fields['user'].queryset.filter(id=user_id)
|
||||
self.fields['user'].widget = forms.HiddenInput()
|
||||
|
@ -2,6 +2,7 @@
|
||||
#
|
||||
# Copyright 2016,2017
|
||||
# - Skia <skia@libskia.so>
|
||||
# - Sli <antoine@bartuccio.fr>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
@ -30,9 +31,10 @@ from django.core.urlresolvers import reverse
|
||||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.views.generic.edit import UpdateView
|
||||
from django.views.generic import ListView, DetailView, TemplateView
|
||||
from django.views.generic import ListView, DetailView, TemplateView, CreateView, DeleteView
|
||||
from django.forms.models import modelform_factory
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.template.response import TemplateResponse
|
||||
from django.conf import settings
|
||||
from django.views.generic.dates import YearMixin, MonthMixin
|
||||
@ -41,8 +43,8 @@ from datetime import timedelta, date
|
||||
import logging
|
||||
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, QuickNotifMixin
|
||||
from core.views.forms import RegisteringForm, UserProfileForm, LoginForm, UserGodfathersForm
|
||||
from core.models import User, SithFile, Preferences
|
||||
from core.views.forms import RegisteringForm, UserProfileForm, LoginForm, UserGodfathersForm, GiftForm
|
||||
from core.models import User, SithFile, Preferences, Gift
|
||||
from subscription.models import Subscription
|
||||
from trombi.views import UserTrombiForm
|
||||
|
||||
@ -232,6 +234,10 @@ class UserView(UserTabsMixin, CanViewMixin, DetailView):
|
||||
template_name = "core/user_detail.jinja"
|
||||
current_tab = 'infos'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(UserView, self).get_context_data(**kwargs)
|
||||
kwargs['gift_form'] = GiftForm(user_id=self.object.id, initial={'user': self.object})
|
||||
return kwargs
|
||||
|
||||
|
||||
class UserPicturesView(UserTabsMixin, CanViewMixin, DetailView):
|
||||
@ -690,3 +696,38 @@ class UserAccountDetailView(UserAccountBase, YearMixin, MonthMixin):
|
||||
pass
|
||||
kwargs['tab'] = "account"
|
||||
return kwargs
|
||||
|
||||
|
||||
class GiftCreateView(CreateView):
|
||||
form_class = GiftForm
|
||||
template_name = 'core/create.jinja'
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not (request.user.is_board_member or request.user.is_root):
|
||||
raise PermissionDenied
|
||||
self.user = get_object_or_404(User, pk=kwargs['user_id'])
|
||||
return super(GiftCreateView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_initial(self):
|
||||
return {'user': self.user}
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(GiftCreateView, self).get_form_kwargs()
|
||||
kwargs['user_id'] = self.user.id
|
||||
return kwargs
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('core:user_profile', kwargs={'user_id': self.user.id})
|
||||
|
||||
|
||||
class GiftDeleteView(CanEditPropMixin, DeleteView):
|
||||
model = Gift
|
||||
pk_url_kwarg = "gift_id"
|
||||
template_name = 'core/delete_confirm.jinja'
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.user = get_object_or_404(User, pk=kwargs['user_id'])
|
||||
return super(GiftDeleteView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('core:user_profile', kwargs={'user_id': self.user.id})
|
||||
|
@ -2,6 +2,7 @@
|
||||
#
|
||||
# Copyright 2016,2017
|
||||
# - Skia <skia@libskia.so>
|
||||
# - Sli <antoine@bartuccio.fr>
|
||||
#
|
||||
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||
# http://ae.utbm.fr.
|
||||
@ -592,6 +593,10 @@ SITH_QUICK_NOTIF = {
|
||||
SITH_MAILING_DOMAIN = 'utbm.fr'
|
||||
SITH_MAILING_FETCH_KEY = 'IloveMails'
|
||||
|
||||
SITH_GIFT_LIST = [
|
||||
('AE Tee-shirt', _("AE tee-shirt"))
|
||||
]
|
||||
|
||||
try:
|
||||
from .settings_custom import *
|
||||
print("Custom settings imported", file=sys.stderr)
|
||||
|
Loading…
Reference in New Issue
Block a user