mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 02:24:26 +00:00
Fix subscription and improve views
This commit is contained in:
parent
0dba76e02e
commit
2e84ee7d4f
@ -8,7 +8,6 @@ from django.core.exceptions import ValidationError
|
||||
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
|
||||
from club.models import Club, Membership
|
||||
from subscription.views import SubscriberMixin
|
||||
|
||||
class ClubListView(CanViewMixin, ListView):
|
||||
"""
|
||||
|
@ -201,6 +201,10 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
return True
|
||||
return False
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
return user.is_in_group(settings.AE_GROUPS['board']['name']) or user.is_in_group(settings.AE_GROUPS['root']['name'])
|
||||
|
||||
|
||||
class AnonymousUser(AuthAnonymousUser):
|
||||
def __init__(self, request):
|
||||
super(AnonymousUser, self).__init__()
|
||||
|
@ -24,8 +24,16 @@
|
||||
You're seeing the profile of <strong>{{ profile.get_full_name() }}</strong><br/>
|
||||
<strong>{{ profile.nick_name }}</strong><br/>
|
||||
<em>{{ profile.date_of_birth|date("d/m/Y") }}</em>
|
||||
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{% if get_subscriber(profile).is_subscribed() %}
|
||||
User is subscriber until {{ get_subscriber(profile).subscriptions.last().subscription_end }}
|
||||
{% else %}
|
||||
User is not subscribed. <a href="{{ url('subscription:subscription') }}?member={{ profile.id }}">New subscription</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -9,9 +9,12 @@
|
||||
<p><a href="{{ url('core:user_profile', user_id=request.user.id) }}">Back to profile</a></p>
|
||||
|
||||
<ul>
|
||||
{% if user.has_perms('core.add_group') %}
|
||||
{% if user.is_in_group(settings.AE_GROUPS['root']['name']) %}
|
||||
<li><a href="{{ url('core:group_list') }}">Groups</a></li>
|
||||
{% endif %}
|
||||
{% if user.is_in_group(settings.AE_GROUPS['root']['name']) or user.is_in_group(settings.AE_GROUPS['board']['name']) %}
|
||||
<li><a href="{{ url('subscription:subscription') }}">Subscriptions</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -97,6 +97,8 @@ TEMPLATES = [
|
||||
"can_edit_prop": "core.views.can_edit_prop",
|
||||
"can_edit": "core.views.can_edit",
|
||||
"can_view": "core.views.can_view",
|
||||
"get_subscriber": "subscription.views.get_subscriber",
|
||||
"settings": "sith.settings",
|
||||
},
|
||||
"bytecode_cache": {
|
||||
"name": "default",
|
||||
|
@ -35,6 +35,7 @@ class Subscription(models.Model):
|
||||
subscription_start = models.DateField(_('subscription start'))
|
||||
subscription_end = models.DateField(_('subscription end'))
|
||||
payment_method = models.CharField(_('payment method'), max_length=255, choices=settings.AE_PAYMENT_METHOD)
|
||||
# TODO add location!
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
@ -112,6 +113,9 @@ class Subscription(models.Model):
|
||||
return start.replace(month=(start.month+6*duration)%12,
|
||||
year=start.year+int(duration/2)+(1 if start.month > 6 and duration%2 == 1 else 0))
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
return user.is_in_group(settings.AE_GROUPS['board']['name']) or user.is_in_group(settings.AE_GROUPS['root']['name'])
|
||||
|
||||
def is_valid_now(self):
|
||||
return self.subscription_start <= date.today() and date.today() <= self.subscription_end
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
{% extends "core/base.html" %}
|
||||
|
||||
{% block title %}
|
||||
{% if profile %}
|
||||
Edit {{ member.user.get_display_name }}'s subscription
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>Edit subscription</h3>
|
||||
{# <p><a href="{% url 'core:user_profile' object.member.user.id %}">Go to profile</a></p> #}
|
||||
{# <p>You're editing the subscription of <strong>{{ member.user.get_display_name }}</strong></p>#}
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<p><input type="submit" value="Save!" /></p>
|
||||
</form>
|
||||
{% endblock %}
|
14
subscription/templates/subscription/subscription.jinja
Normal file
14
subscription/templates/subscription/subscription.jinja
Normal file
@ -0,0 +1,14 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
New subscription
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>New subscription</h3>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p() }}
|
||||
<p><input type="submit" value="Save!" /></p>
|
||||
</form>
|
||||
{% endblock %}
|
@ -10,23 +10,20 @@ from subscription.models import Subscriber, Subscription
|
||||
from core.views import CanEditMixin, CanEditPropMixin, CanViewMixin
|
||||
from core.models import User
|
||||
|
||||
class SubscriberMixin(View):
|
||||
def dispatch(self, request, *arg, **kwargs):
|
||||
res = super(SubscriberMixin, self).dispatch(request, *arg, **kwargs)
|
||||
subscriber = Subscriber.objects.filter(pk=request.user.pk).first()
|
||||
if subscriber is not None and subscriber.is_subscribed():
|
||||
return ret
|
||||
raise PermissionDenied
|
||||
def get_subscriber(user):
|
||||
s = Subscriber.objects.filter(pk=user.pk).first()
|
||||
return s
|
||||
|
||||
class SubscriptionForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Subscription
|
||||
fields = ['member', 'subscription_type', 'payment_method']
|
||||
#widgets = {
|
||||
# 'subscription_type': Select(choices={(k.lower(), k+" - "+str(v['price'])+"€"+str(Subscription.compute_end(2))) for k,v in settings.AE_SUBSCRIPTIONS.items()}),
|
||||
#}
|
||||
|
||||
|
||||
class NewSubscription(CanEditMixin, CreateView):
|
||||
template_name = 'subscription/subscription.html'
|
||||
template_name = 'subscription/subscription.jinja'
|
||||
form_class = SubscriptionForm
|
||||
|
||||
def get_initial(self):
|
||||
if 'member' in self.request.GET.keys():
|
||||
return {'member': self.request.GET['member']}
|
||||
return {}
|
||||
|
Loading…
Reference in New Issue
Block a user