Commit 031be094 authored by guillaume-renaud's avatar guillaume-renaud
Browse files

merging

parents c7d17b52 7b6d858b
Pipeline #658 failed with stage
in 2 minutes and 18 seconds
...@@ -68,7 +68,7 @@ class BankAccount(models.Model): ...@@ -68,7 +68,7 @@ class BankAccount(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
m = self.club.get_membership_for(user) m = self.club.get_membership_for(user)
if m is not None and m.role >= 7: if m is not None and m.role >= 7:
...@@ -94,7 +94,7 @@ class ClubAccount(models.Model): ...@@ -94,7 +94,7 @@ class ClubAccount(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
return False return False
...@@ -155,7 +155,7 @@ class GeneralJournal(models.Model): ...@@ -155,7 +155,7 @@ class GeneralJournal(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
if self.club_account.can_be_edited_by(user): if self.club_account.can_be_edited_by(user):
return True return True
...@@ -260,7 +260,7 @@ class Operation(models.Model): ...@@ -260,7 +260,7 @@ class Operation(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
if self.journal.closed: if self.journal.closed:
return False return False
...@@ -308,7 +308,7 @@ class AccountingType(models.Model): ...@@ -308,7 +308,7 @@ class AccountingType(models.Model):
""" """
Method to see if that object can be edited by the given user Method to see if that object can be edited by the given user
""" """
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
return False return False
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<h4> <h4>
{% trans %}Accounting{% endtrans %} {% trans %}Accounting{% endtrans %}
</h4> </h4>
{% if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) %} {% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
<p><a href="{{ url('accounting:simple_type_list') }}">{% trans %}Manage simplified types{% endtrans %}</a></p> <p><a href="{{ url('accounting:simple_type_list') }}">{% trans %}Manage simplified types{% endtrans %}</a></p>
<p><a href="{{ url('accounting:type_list') }}">{% trans %}Manage accounting types{% endtrans %}</a></p> <p><a href="{{ url('accounting:type_list') }}">{% trans %}Manage accounting types{% endtrans %}</a></p>
<p><a href="{{ url('accounting:bank_new') }}">{% trans %}New bank account{% endtrans %}</a></p> <p><a href="{{ url('accounting:bank_new') }}">{% trans %}New bank account{% endtrans %}</a></p>
......
...@@ -367,11 +367,11 @@ class OperationPDFView(CanViewMixin, DetailView): ...@@ -367,11 +367,11 @@ class OperationPDFView(CanViewMixin, DetailView):
im = ImageReader("core/static/core/img/logo.jpg") im = ImageReader("core/static/core/img/logo.jpg")
iw, ih = im.getSize() iw, ih = im.getSize()
p.drawImage(im, 40, height - 50, width=iw/2, height=ih/2) p.drawImage(im, 40, height - 50, width=iw/2, height=ih/2)
labelStr = [["%s %s - %s %s" % (_("Journal"), ti, _("Operation"), num)]] labelStr = [["%s %s - %s %s" % (_("Journal"), ti, _("Operation"), num)]]
label = Table(labelStr, colWidths=[150], rowHeights=[20]) label = Table(labelStr, colWidths=[150], rowHeights=[20])
label.setStyle(TableStyle([ label.setStyle(TableStyle([
('ALIGN',(0,0),(-1,-1),'CENTER'), ('ALIGN',(0,0),(-1,-1),'CENTER'),
('BOX', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black),
...@@ -384,11 +384,11 @@ class OperationPDFView(CanViewMixin, DetailView): ...@@ -384,11 +384,11 @@ class OperationPDFView(CanViewMixin, DetailView):
p.drawString(90, height - 160, _("Label: %(op_label)s") % {"op_label": op_label if op_label != None else ""}) p.drawString(90, height - 160, _("Label: %(op_label)s") % {"op_label": op_label if op_label != None else ""})
data = [] data = []
data += [["%s" % (_("Credit").upper() if nature == 'CREDIT' else _("Debit").upper())]] data += [["%s" % (_("Credit").upper() if nature == 'CREDIT' else _("Debit").upper())]]
data += [[_("Amount: %(amount).2f €") % {"amount": amount}]] data += [[_("Amount: %(amount).2f €") % {"amount": amount}]]
payment_mode = "" payment_mode = ""
for m in settings.SITH_ACCOUNTING_PAYMENT_METHOD: for m in settings.SITH_ACCOUNTING_PAYMENT_METHOD:
if m[0] == mode: if m[0] == mode:
...@@ -398,11 +398,11 @@ class OperationPDFView(CanViewMixin, DetailView): ...@@ -398,11 +398,11 @@ class OperationPDFView(CanViewMixin, DetailView):
payment_mode += " %s\n" %(m[1]) payment_mode += " %s\n" %(m[1])
data += [[payment_mode]] data += [[payment_mode]]
data += [["%s : %s" % (_("Debtor") if nature == 'CREDIT' else _("Creditor"), target), ""]] data += [["%s : %s" % (_("Debtor") if nature == 'CREDIT' else _("Creditor"), target), ""]]
data += [["%s \n%s" % (_("Comment:"), remark)]] data += [["%s \n%s" % (_("Comment:"), remark)]]
t = Table(data, colWidths=[(width-90*2)/2]*2, rowHeights=[20, 20, 70, 20, 80]) t = Table(data, colWidths=[(width-90*2)/2]*2, rowHeights=[20, 20, 70, 20, 80])
t.setStyle(TableStyle([ t.setStyle(TableStyle([
('ALIGN',(0,0),(-1,-1),'CENTER'), ('ALIGN',(0,0),(-1,-1),'CENTER'),
...@@ -498,7 +498,7 @@ class RefoundAccountView(FormView): ...@@ -498,7 +498,7 @@ class RefoundAccountView(FormView):
form_class = CloseCustomerAccountForm form_class = CloseCustomerAccountForm
def permission(self, user): def permission(self, user):
if user.is_root or user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']): if user.is_root or user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True return True
else: else:
raise PermissionDenied raise PermissionDenied
......
...@@ -8,7 +8,6 @@ from django.core.urlresolvers import reverse ...@@ -8,7 +8,6 @@ from django.core.urlresolvers import reverse
from django.utils import timezone from django.utils import timezone
from core.models import User, MetaGroup, Group, SithFile from core.models import User, MetaGroup, Group, SithFile
from subscription.models import Subscriber
# Create your models here. # Create your models here.
...@@ -33,7 +32,7 @@ class Club(models.Model): ...@@ -33,7 +32,7 @@ class Club(models.Model):
address = models.CharField(_('address'), max_length=254) address = models.CharField(_('address'), max_length=254)
# email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically # email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically
owner_group = models.ForeignKey(Group, related_name="owned_club", owner_group = models.ForeignKey(Group, related_name="owned_club",
default=settings.SITH_GROUPS['root']['id']) default=settings.SITH_GROUP_ROOT_ID)
edit_groups = models.ManyToManyField(Group, related_name="editable_club", blank=True) edit_groups = models.ManyToManyField(Group, related_name="editable_club", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_club", blank=True) view_groups = models.ManyToManyField(Group, related_name="viewable_club", blank=True)
home = models.OneToOneField(SithFile, related_name='home_of_club', verbose_name=_("home"), null=True, blank=True, home = models.OneToOneField(SithFile, related_name='home_of_club', verbose_name=_("home"), null=True, blank=True,
...@@ -120,7 +119,7 @@ class Club(models.Model): ...@@ -120,7 +119,7 @@ class Club(models.Model):
""" """
Method to see if that object can be seen by the given user Method to see if that object can be seen by the given user
""" """
sub = Subscriber.objects.filter(pk=user.pk).first() sub = User.objects.filter(pk=user.pk).first()
if sub is None: if sub is None:
return False return False
return sub.is_subscribed() return sub.is_subscribed()
...@@ -151,7 +150,7 @@ class Membership(models.Model): ...@@ -151,7 +150,7 @@ class Membership(models.Model):
description = models.CharField(_('description'), max_length=128, null=False, blank=True) description = models.CharField(_('description'), max_length=128, null=False, blank=True)
def clean(self): def clean(self):
sub = Subscriber.objects.filter(pk=self.user.pk).first() sub = User.objects.filter(pk=self.user.pk).first()
if sub is None or not sub.is_subscribed(): if sub is None or not sub.is_subscribed():
raise ValidationError(_('User must be subscriber to take part to a club')) raise ValidationError(_('User must be subscriber to take part to a club'))
if Membership.objects.filter(user=self.user).filter(club=self.club).filter(end_date=None).exists(): if Membership.objects.filter(user=self.user).filter(club=self.club).filter(end_date=None).exists():
......
...@@ -12,7 +12,7 @@ from django.contrib.sites.models import Site ...@@ -12,7 +12,7 @@ from django.contrib.sites.models import Site
from core.models import Group, User, Page, PageRev, SithFile from core.models import Group, User, Page, PageRev, SithFile
from accounting.models import GeneralJournal, BankAccount, ClubAccount, Operation, AccountingType, Company from accounting.models import GeneralJournal, BankAccount, ClubAccount, Operation, AccountingType, Company
from club.models import Club, Membership from club.models import Club, Membership
from subscription.models import Subscription, Subscriber from subscription.models import Subscription
from counter.models import Customer, ProductType, Product, Counter from counter.models import Customer, ProductType, Product, Counter
class Command(BaseCommand): class Command(BaseCommand):
...@@ -31,8 +31,15 @@ class Command(BaseCommand): ...@@ -31,8 +31,15 @@ class Command(BaseCommand):
os.environ['DJANGO_COLORS'] = 'nocolor' os.environ['DJANGO_COLORS'] = 'nocolor'
Site(id=4000, domain=settings.SITH_URL, name=settings.SITH_NAME).save() Site(id=4000, domain=settings.SITH_URL, name=settings.SITH_NAME).save()
root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
for g in settings.SITH_GROUPS.values(): Group(name="Root").save()
Group(id=g['id'], name=g['name']).save() Group(name="Not registered users").save()
Group(name="Accounting admin").save()
Group(name="Communication admin").save()
Group(name="Counter admin").save()
Group(name="Banned from buying alcohol").save()
Group(name="Banned from counters").save()
Group(name="Banned to subscribe").save()
Group(name="SAS admin").save()
self.reset_index("core", "auth") self.reset_index("core", "auth")
root = User(id=0, username='root', last_name="", first_name="Bibou", root = User(id=0, username='root', last_name="", first_name="Bibou",
email="ae.info@utbm.fr", email="ae.info@utbm.fr",
...@@ -46,7 +53,6 @@ class Command(BaseCommand): ...@@ -46,7 +53,6 @@ class Command(BaseCommand):
club_root = SithFile(parent=None, name="clubs", is_folder=True, owner=root) club_root = SithFile(parent=None, name="clubs", is_folder=True, owner=root)
club_root.save() club_root.save()
SithFile(parent=None, name="SAS", is_folder=True, owner=root).save() SithFile(parent=None, name="SAS", is_folder=True, owner=root).save()
Group(name="SAS admin").save()
main_club = Club(id=1, name=settings.SITH_MAIN_CLUB['name'], unix_name=settings.SITH_MAIN_CLUB['unix_name'], main_club = Club(id=1, name=settings.SITH_MAIN_CLUB['name'], unix_name=settings.SITH_MAIN_CLUB['unix_name'],
address=settings.SITH_MAIN_CLUB['address']) address=settings.SITH_MAIN_CLUB['address'])
main_club.save() main_club.save()
...@@ -77,7 +83,7 @@ class Command(BaseCommand): ...@@ -77,7 +83,7 @@ class Command(BaseCommand):
p = Page(name='Index') p = Page(name='Index')
p.set_lock(root) p.set_lock(root)
p.save() p.save()
p.view_groups=[settings.SITH_GROUPS['public']['id']] p.view_groups=[settings.SITH_GROUP_PUBLIC_ID]
p.set_lock(root) p.set_lock(root)
p.save() p.save()
PageRev(page=p, title="Wiki index", author=root, content=""" PageRev(page=p, title="Wiki index", author=root, content="""
...@@ -87,7 +93,7 @@ Welcome to the wiki page! ...@@ -87,7 +93,7 @@ Welcome to the wiki page!
p = Page(name="services") p = Page(name="services")
p.set_lock(root) p.set_lock(root)
p.save() p.save()
p.view_groups=[settings.SITH_GROUPS['public']['id']] p.view_groups=[settings.SITH_GROUP_PUBLIC_ID]
p.set_lock(root) p.set_lock(root)
PageRev(page=p, title="Services", author=root, content=""" PageRev(page=p, title="Services", author=root, content="""
| | | | | | | |
...@@ -139,7 +145,7 @@ Welcome to the wiki page! ...@@ -139,7 +145,7 @@ Welcome to the wiki page!
counter.set_password("plop") counter.set_password("plop")
counter.save() counter.save()
counter.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id] counter.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id]
counter.groups=[Group.objects.filter(name=settings.SITH_GROUPS['counter-admin']['name']).first().id] counter.groups=[Group.objects.filter(id=settings.SITH_GROUP_COUNTER_ADMIN_ID).first().id]
counter.save() counter.save()
# Adding user Comptable # Adding user Comptable
comptable = User(username='comptable', last_name="Able", first_name="Compte", comptable = User(username='comptable', last_name="Able", first_name="Compte",
...@@ -149,7 +155,7 @@ Welcome to the wiki page! ...@@ -149,7 +155,7 @@ Welcome to the wiki page!
comptable.set_password("plop") comptable.set_password("plop")
comptable.save() comptable.save()
comptable.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id] comptable.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id]
comptable.groups=[Group.objects.filter(name=settings.SITH_GROUPS['accounting-admin']['name']).first().id] comptable.groups=[Group.objects.filter(id=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID).first().id]
comptable.save() comptable.save()
# Adding user Guy # Adding user Guy
u = User(username='guy', last_name="Carlier", first_name="Guy", u = User(username='guy', last_name="Carlier", first_name="Guy",
...@@ -176,7 +182,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. ...@@ -176,7 +182,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
""").save() """).save()
p = Page(name='Services') p = Page(name='Services')
p.save(force_lock=True) p.save(force_lock=True)
p.view_groups=[settings.SITH_GROUPS['public']['id']] p.view_groups=[settings.SITH_GROUP_PUBLIC_ID]
p.save(force_lock=True) p.save(force_lock=True)
PageRev(page=p, title="Services", author=skia, content=""" PageRev(page=p, title="Services", author=skia, content="""
| | | | | | | |
...@@ -188,14 +194,14 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. ...@@ -188,14 +194,14 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
# Adding README # Adding README
p = Page(name='README') p = Page(name='README')
p.save(force_lock=True) p.save(force_lock=True)
p.view_groups=[settings.SITH_GROUPS['public']['id']] p.view_groups=[settings.SITH_GROUP_PUBLIC_ID]
p.save(force_lock=True) p.save(force_lock=True)
with open(os.path.join(root_path)+'/README.md', 'r') as rm: with open(os.path.join(root_path)+'/README.md', 'r') as rm:
PageRev(page=p, title="README", author=skia, content=rm.read()).save() PageRev(page=p, title="README", author=skia, content=rm.read()).save()
# Subscription # Subscription
## Root ## Root
s = Subscription(member=Subscriber.objects.filter(pk=root.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], s = Subscription(member=User.objects.filter(pk=root.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start() s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end( s.subscription_end = s.compute_end(
...@@ -203,7 +209,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. ...@@ -203,7 +209,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
start=s.subscription_start) start=s.subscription_start)
s.save() s.save()
## Skia ## Skia
s = Subscription(member=Subscriber.objects.filter(pk=skia.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], s = Subscription(member=User.objects.filter(pk=skia.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start() s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end( s.subscription_end = s.compute_end(
...@@ -211,7 +217,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. ...@@ -211,7 +217,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
start=s.subscription_start) start=s.subscription_start)
s.save() s.save()
## Comptable ## Comptable
s = Subscription(member=Subscriber.objects.filter(pk=comptable.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], s = Subscription(member=User.objects.filter(pk=comptable.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start() s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end( s.subscription_end = s.compute_end(
...@@ -219,15 +225,15 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. ...@@ -219,15 +225,15 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
start=s.subscription_start) start=s.subscription_start)
s.save() s.save()
## Richard ## Richard
s = Subscription(member=Subscriber.objects.filter(pk=r.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], s = Subscription(member=User.objects.filter(pk=r.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start() s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end( s.subscription_end = s.compute_end(
duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'], duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'],
start=s.subscription_start) start=s.subscription_start)
s.save() s.save()
## Subscriber ## User
s = Subscription(member=Subscriber.objects.filter(pk=subscriber.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], s = Subscription(member=User.objects.filter(pk=subscriber.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start() s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end( s.subscription_end = s.compute_end(
......
# -*- 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', '0011_auto_20161124_0848'),
]
operations = [
migrations.CreateModel(
name='Notification',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('url', models.CharField(max_length=255, verbose_name='url')),
('text', models.CharField(max_length=512, verbose_name='text')),
('type', models.CharField(max_length=16, choices=[('FILE_MODERATION', 'File moderation'), ('SAS_MODERATION', 'SAS moderation'), ('NEW_PICTURES', 'New pictures')], verbose_name='text', null=True, blank=True)),
('date', models.DateTimeField(verbose_name='date', default=django.utils.timezone.now)),
('user', models.ForeignKey(related_name='notifications', to=settings.AUTH_USER_MODEL)),
],
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0012_notification'),
]
operations = [
migrations.RemoveField(
model_name='notification',
name='text',
),
migrations.AddField(
model_name='notification',
name='param',
field=models.CharField(verbose_name='param', default='', max_length=128),
),
migrations.AddField(
model_name='notification',
name='viewed',
field=models.BooleanField(verbose_name='viewed', default=False),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0013_auto_20161209_2338'),
]
operations = [
migrations.AlterField(
model_name='notification',
name='type',
field=models.CharField(verbose_name='type', max_length=32, default='GENERIC', choices=[('FILE_MODERATION', 'New files to be moderated'), ('SAS_MODERATION', 'New pictures/album to be moderated in the SAS'), ('NEW_PICTURES', "You've been identified on some pictures"), ('REFILLING', 'You just refilled of %s €'), ('SELLING', 'You just bought %s'), ('GENERIC', 'You have a notification')]),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('core', '0014_auto_20161210_0009'),
]
operations = [
migrations.AddField(
model_name='sithfile',
name='moderator',
field=models.ForeignKey(related_name='moderated_files', verbose_name='owner', default=0, to=settings.AUTH_USER_MODEL),
preserve_default=False,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('core', '0015_sithfile_moderator'),
]
operations = [
migrations.AlterField(
model_name='sithfile',
name='moderator',
field=models.ForeignKey(related_name='moderated_files', blank=True, null=True, to=settings.AUTH_USER_MODEL, verbose_name='owner'),
),
]
...@@ -182,26 +182,30 @@ class User(AbstractBaseUser): ...@@ -182,26 +182,30 @@ class User(AbstractBaseUser):
def to_dict(self): def to_dict(self):
return self.__dict__ return self.__dict__
def was_subscribed(self):
return self.subscriptions.exists()
def is_subscribed(self):
s = self.subscriptions.last()
return s.is_valid_now() if s is not None else False
def is_in_group(self, group_name): def is_in_group(self, group_name):
"""If the user is in the group passed in argument (as string or by id)""" """If the user is in the group passed in argument (as string or by id)"""
group_id = 0
g = None
if isinstance(group_name, int): # Handle the case where group_name is an ID if isinstance(group_name, int): # Handle the case where group_name is an ID
g = Group.objects.filter(id=group_name).first() g = Group.objects.filter(id=group_name).first()
if g: else:
group_name = g.name g = Group.objects.filter(name=group_name).first()
else: if g:
return False group_name = g.name
if group_name == settings.SITH_GROUPS['public']['name']: group_id = g.id
else:
return False
if group_id == settings.SITH_GROUP_PUBLIC_ID:
return True return True
if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked
if 'subscription' in settings.INSTALLED_APPS: return self.is_subscribed()
from subscription.models import Subscriber
s = Subscriber.objects.filter(pk=self.pk).first()
if s is not None and s.is_subscribed():
return True
else:
return False
else:
return False