mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 12:53:11 +00:00
Add the need_membership field to article
This field is a boolean indicating if the article can be purshased by nonmembers.
This commit is contained in:
parent
b317eceec3
commit
98639f54f0
3 changed files with 57 additions and 3 deletions
20
cotisations/migrations/0046_article_need_membership.py
Normal file
20
cotisations/migrations/0046_article_need_membership.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.29 on 2020-09-25 16:45
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cotisations', '0045_separation_membership_connection_p3'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='article',
|
||||||
|
name='need_membership',
|
||||||
|
field=models.BooleanField(default=True, verbose_name='can be purcharsed without membership'),
|
||||||
|
),
|
||||||
|
]
|
28
cotisations/migrations/0047_article_need_membership_init.py
Normal file
28
cotisations/migrations/0047_article_need_membership_init.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.29 on 2020-09-25 16:45
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cotisations', '0046_article_need_membership'),
|
||||||
|
]
|
||||||
|
|
||||||
|
def init_need_membership(apps, schema_editor):
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
article = apps.get_model("cotisations", "Article")
|
||||||
|
articles = article.objects.using(db_alias).all()
|
||||||
|
for art in articles:
|
||||||
|
v = False
|
||||||
|
v = v or bool(art.duration_membership)
|
||||||
|
v = v or bool(art.duration_days_membership)
|
||||||
|
v = v or not (bool(art.duration_connection) or bool(art.duration_days_connection))
|
||||||
|
art.need_membership = v
|
||||||
|
art.save()
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(init_need_membership, lambda *args, **kargs: None),
|
||||||
|
]
|
|
@ -678,6 +678,7 @@ class Article(RevMixin, AclMixin, models.Model):
|
||||||
* a price
|
* a price
|
||||||
* a duration for the membership
|
* a duration for the membership
|
||||||
* a duration for the connection
|
* a duration for the connection
|
||||||
|
* if the article can be purchased without membership
|
||||||
* a type of user (indicating what kind of user can buy this article)
|
* a type of user (indicating what kind of user can buy this article)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -718,6 +719,11 @@ class Article(RevMixin, AclMixin, models.Model):
|
||||||
verbose_name=_("duration of the connection (in days, will be added to duration in months)"),
|
verbose_name=_("duration of the connection (in days, will be added to duration in months)"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
need_membership = models.BooleanField(
|
||||||
|
default=True,
|
||||||
|
verbose_name=_("need membership to be purchased"),
|
||||||
|
)
|
||||||
|
|
||||||
type_user = models.CharField(
|
type_user = models.CharField(
|
||||||
choices=USER_TYPES,
|
choices=USER_TYPES,
|
||||||
default="All",
|
default="All",
|
||||||
|
@ -785,9 +791,9 @@ class Article(RevMixin, AclMixin, models.Model):
|
||||||
)
|
)
|
||||||
if target_user is not None and not target_user.is_adherent():
|
if target_user is not None and not target_user.is_adherent():
|
||||||
objects_pool = objects_pool.filter(
|
objects_pool = objects_pool.filter(
|
||||||
Q(type_cotisation="All")
|
Q(duration_membership__gt=0)
|
||||||
| Q(type_cotisation="Adhesion")
|
|Q(duration_days_membership__gt=0)
|
||||||
| Q(type_cotisation__isnull=True)
|
|Q(need_membership=False)
|
||||||
)
|
)
|
||||||
if user.has_perm("cotisations.buy_every_article"):
|
if user.has_perm("cotisations.buy_every_article"):
|
||||||
return objects_pool
|
return objects_pool
|
||||||
|
|
Loading…
Reference in a new issue