From 0b068d3e921528af78c414ea52632e56810321f3 Mon Sep 17 00:00:00 2001 From: Skia Date: Wed, 26 Oct 2016 19:21:19 +0200 Subject: [PATCH] Improve file moderation --- core/management/commands/populate.py | 9 +++++++++ core/models.py | 8 +++++++- core/views/files.py | 4 ++-- sith/settings.py | 25 ++++++++++++++----------- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 922a6eaf..09b122bc 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -45,6 +45,7 @@ class Command(BaseCommand): home_root.save() club_root = SithFile(parent=None, name="clubs", is_folder=True, owner=root) club_root.save() + SithFile(parent=None, name="SAS", is_folder=True, owner=root).save() 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']) main_club.save() @@ -191,6 +192,14 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. PageRev(page=p, title="README", author=skia, content=rm.read()).save() # Subscription + ## Root + s = Subscription(member=Subscriber.objects.filter(pk=root.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], + payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) + s.subscription_start = s.compute_start() + s.subscription_end = s.compute_end( + duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'], + start=s.subscription_start) + s.save() ## Skia s = Subscription(member=Subscriber.objects.filter(pk=skia.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) diff --git a/core/models.py b/core/models.py index f797e39e..5d63a966 100644 --- a/core/models.py +++ b/core/models.py @@ -195,7 +195,13 @@ class User(AbstractBaseUser): return self.__dict__ def is_in_group(self, group_name): - """If the user is in the group passed in argument (as string)""" + """If the user is in the group passed in argument (as string or by id)""" + if isinstance(group_name, int): # Handle the case where group_name is an ID + g = Group.objects.filter(id=group_name).first() + if g: + group_name = g.name + else: + return False if group_name == settings.SITH_GROUPS['public']['name']: return True if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked diff --git a/core/views/files.py b/core/views/files.py index 9640c4cb..69b42325 100644 --- a/core/views/files.py +++ b/core/views/files.py @@ -19,13 +19,13 @@ import os from core.models import SithFile from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, can_view, not_found -def send_file(request, file_id): +def send_file(request, file_id, file_class=SithFile): """ Send a file through Django without loading the whole file into memory at once. The FileWrapper will turn the file object into an iterator for chunks of 8KB. """ - f = SithFile.objects.filter(id=file_id).first() + f = file_class.objects.filter(id=file_id).first() if f is None or f.is_folder: return not_found(request) from counter.models import Counter diff --git a/sith/settings.py b/sith/settings.py index d90f166d..b65403b6 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -203,6 +203,19 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_HOST="localhost" EMAIL_PORT=25 +# Below this line, only Sith-specific variables are defined + +IS_OLD_MYSQL_PRESENT = False +OLD_MYSQL_INFOS = { + 'host': 'ae-db', + 'user': "my_user", + 'passwd': "password", + 'db': "ae2-db", + 'charset': 'utf8', + 'use_unicode': True, + } + + SITH_URL = "my.url.git.an" SITH_NAME = "Sith website" @@ -413,7 +426,7 @@ SITH_BARMAN_TIMEOUT=20 SITH_LAST_OPERATIONS_LIMIT=5 # Minutes for a counter to be inactive -SITH_COUNTER_MINUTE_INACTIVE=10 +SITH_COUNTER_MINUTE_INACTIVE=10 # ET variables SITH_EBOUTIC_ET_URL = "https://preprod-tpeweb.e-transactions.fr/cgi/MYchoix_pagepaiement.cgi" @@ -432,16 +445,6 @@ SITH_LAUNDERETTE_PRICES = { 'DRYING': 0.75, } -IS_OLD_MYSQL_PRESENT = False -OLD_MYSQL_INFOS = { - 'host': 'ae-db', - 'user': "my_user", - 'passwd': "password", - 'db': "ae2-db", - 'charset': 'utf8', - 'use_unicode': True, - } - try: from .settings_custom import * print("Custom settings imported")