Commit 52153438 authored by Skia's avatar Skia
Browse files

Rename and refactor some settings

parent be826ed6
Pipeline #4 skipped
......@@ -31,7 +31,7 @@ class Club(models.Model):
address = models.CharField(_('address'), max_length=254)
# email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically
owner_group = models.ForeignKey(Group, related_name="owned_club",
default=settings.AE_GROUPS['root']['id'])
default=settings.SITH_GROUPS['root']['id'])
edit_groups = models.ManyToManyField(Group, related_name="editable_club", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_club", blank=True)
......@@ -50,8 +50,8 @@ class Club(models.Model):
def save(self):
super(Club, self).save()
MetaGroup(name=self.unix_name+"-board").save()
MetaGroup(name=self.unix_name+"-members").save()
MetaGroup(name=self.unix_name+settings.SITH_BOARD_SUFFIX).save()
MetaGroup(name=self.unix_name+settings.SITH_MEMBER_SUFFIX).save()
def __str__(self):
return self.name
......@@ -63,7 +63,7 @@ class Club(models.Model):
"""
Method to see if that object can be super edited by the given user
"""
if user.is_in_group(settings.AE_GROUPS['board']['name']):
if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP):
return True
return False
......
......@@ -41,10 +41,10 @@ class ClubTest(TestCase):
self.assertTrue(response.status_code == 200)
self.assertTrue("<li>Woenzel&#39;UT - rbatsbak - Vice-Pr" in str(response.content))
def test_create_add_user_to_club_from_skia_fail(self):
def test_create_add_user_to_club_from_richard_fail(self):
self.client.login(username='root', password='plop')
self.client.post(reverse("club:club_members", kwargs={"club_id":4}), {"user": 2, "role": 3})
self.client.login(username='skia', password='plop')
self.client.login(username='rbatsbak', password='plop')
response = self.client.post(reverse("club:club_members", kwargs={"club_id":4}), {"user": 4, "role": 10})
self.assertTrue(response.status_code == 200)
self.assertTrue("<li>You do not have the permission to do that</li>" in str(response.content))
......@@ -8,7 +8,7 @@ from django.core.exceptions import ValidationError
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from club.models import Club, Membership
from sith.settings import AE_GROUPS, MAXIMUM_FREE_ROLE
from sith.settings import MAXIMUM_FREE_ROLE, SITH_MAIN_BOARD_GROUP
class ClubListView(CanViewMixin, ListView):
"""
......@@ -44,7 +44,7 @@ class ClubMemberForm(forms.ModelForm):
ms = self.instance.club.get_membership_for(self._user)
if (self.cleaned_data['role'] <= MAXIMUM_FREE_ROLE or
(ms is not None and ms.role >= self.cleaned_data['role']) or
self._user.is_in_group(AE_GROUPS['board']['name']) or
self._user.is_in_group(SITH_MAIN_BOARD_GROUP) or
self._user.is_superuser):
return ret
raise ValidationError("You do not have the permission to do that")
......
......@@ -23,15 +23,15 @@ class Command(BaseCommand):
is_superuser=True, is_staff=True)
root.set_password("plop")
root.save()
ae = Club(name=settings.AE_MAIN_CLUB['name'], unix_name=settings.AE_MAIN_CLUB['unix_name'],
address=settings.AE_MAIN_CLUB['address'])
ae.save()
for g in settings.AE_GROUPS.values():
for g in settings.SITH_GROUPS.values():
Group(id=g['id'], name=g['name']).save()
ae = Club(name=settings.SITH_MAIN_CLUB['name'], unix_name=settings.SITH_MAIN_CLUB['unix_name'],
address=settings.SITH_MAIN_CLUB['address'])
ae.save()
p = Page(name='Index')
p.set_lock(root)
p.save()
p.view_groups=[settings.AE_GROUPS['public']['id']]
p.view_groups=[settings.SITH_GROUPS['public']['id']]
p.set_lock(root)
p.save()
PageRev(page=p, title="Wiki index", author=root, content="""
......@@ -47,7 +47,7 @@ Welcome to the wiki page!
date_of_birth="1942-06-12")
s.set_password("plop")
s.save()
s.view_groups=[settings.AE_GROUPS['members']['id']]
s.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id]
s.save()
# Adding user Guy
u = User(username='guy', last_name="Carlier", first_name="Guy",
......@@ -56,7 +56,7 @@ Welcome to the wiki page!
is_superuser=False, is_staff=False)
u.set_password("plop")
u.save()
u.view_groups=[settings.AE_GROUPS['members']['id']]
u.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id]
u.save()
# Adding user Richard Batsbak
r = User(username='rbatsbak', last_name="Batsbak", first_name="Richard",
......@@ -64,7 +64,7 @@ Welcome to the wiki page!
date_of_birth="1982-06-12")
r.set_password("plop")
r.save()
r.view_groups=[settings.AE_GROUPS['members']['id']]
r.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id]
r.save()
# Adding syntax help page
p = Page(name='Aide_sur_la_syntaxe')
......@@ -75,17 +75,19 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
# Adding README
p = Page(name='README')
p.save()
p.view_groups=[settings.AE_GROUPS['public']['id']]
p.view_groups=[settings.SITH_GROUPS['public']['id']]
p.set_lock(s)
p.save()
with open(os.path.join(root_path)+'/README.md', 'r') as rm:
PageRev(page=p, title="REAMDE", author=s, content=rm.read()).save()
# Subscription
Subscription(member=Subscriber.objects.filter(pk=s.pk).first(), subscription_type=list(settings.AE_SUBSCRIPTIONS.keys())[0],
payment_method=settings.AE_PAYMENT_METHOD[0]).save()
Subscription(member=Subscriber.objects.filter(pk=r.pk).first(), subscription_type=list(settings.AE_SUBSCRIPTIONS.keys())[0],
payment_method=settings.AE_PAYMENT_METHOD[0]).save()
## Skia
Subscription(member=Subscriber.objects.filter(pk=s.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_PAYMENT_METHOD[0]).save()
## Richard
Subscription(member=Subscriber.objects.filter(pk=r.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_PAYMENT_METHOD[0]).save()
# Clubs
Club(name="Bibo'UT", unix_name="bibout",
......
......@@ -91,7 +91,7 @@ class User(AbstractBaseUser, PermissionsMixin):
)
date_joined = models.DateField(_('date joined'), auto_now_add=True)
owner_group = models.ForeignKey(Group, related_name="owned_user",
default=settings.AE_GROUPS['root']['id'])
default=settings.SITH_GROUPS['root']['id'])
edit_groups = models.ManyToManyField(Group, related_name="editable_user", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_user", blank=True)
......@@ -125,9 +125,9 @@ class User(AbstractBaseUser, PermissionsMixin):
def is_in_group(self, group_name):
"""If the user is in the group passed in argument (as string)"""
if group_name == settings.AE_GROUPS['public']['name']:
if group_name == settings.SITH_GROUPS['public']['name']:
return True
if group_name == settings.AE_GROUPS['members']['name']: # We check the subscription if asked
if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked
try: # TODO: change for a test in settings.INSTALLED_APP
from subscription import Subscriber
s = Subscriber.objects.filter(pk=self.pk).first()
......@@ -138,7 +138,7 @@ class User(AbstractBaseUser, PermissionsMixin):
except Exception as e:
print(e)
return False
if group_name[-6:] == "-board":
if group_name[-6:] == settings.SITH_BOARD_SUFFIX:
try: # TODO: change for a test in settings.INSTALLED_APP
from club.models import Club
name = group_name[:-6]
......@@ -210,7 +210,7 @@ class User(AbstractBaseUser, PermissionsMixin):
return False
if (self.is_superuser or self.is_in_group(obj.owner_group.name) or
self.has_perm(obj.__class__.__module__.split('.')[0]+".change_prop_"+obj.__class__.__name__.lower()) or
self.groups.filter(id=settings.AE_GROUPS['root']['id']).exists()):
self.groups.filter(id=settings.SITH_GROUPS['root']['id']).exists()):
return True
if hasattr(obj, "is_owned_by") and obj.is_owned_by(self):
return True
......@@ -251,7 +251,7 @@ class User(AbstractBaseUser, PermissionsMixin):
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'])
return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_in_group(settings.SITH_GROUPS['root']['name'])
class AnonymousUser(AuthAnonymousUser):
......@@ -265,7 +265,7 @@ class AnonymousUser(AuthAnonymousUser):
return False
def can_view(self, obj):
if obj.view_groups.filter(pk=settings.AE_GROUPS['public']['id']).exists():
if obj.view_groups.filter(pk=settings.SITH_GROUPS['public']['id']).exists():
return True
return False
......@@ -298,7 +298,7 @@ class Page(models.Model):
# playing with a Page object, use get_full_name() instead!
_full_name = models.CharField(_('page name'), max_length=255, blank=True)
owner_group = models.ForeignKey(Group, related_name="owned_page",
default=settings.AE_GROUPS['root']['id'])
default=settings.SITH_GROUPS['root']['id'])
edit_groups = models.ManyToManyField(Group, related_name="editable_page", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_page", blank=True)
lock_mutex = {}
......
......@@ -9,10 +9,10 @@
<p><a href="{{ url('core:user_profile', user_id=request.user.id) }}">Back to profile</a></p>
<ul>
{% if user.is_in_group(settings.AE_GROUPS['root']['name']) %}
{% if user.is_in_group(settings.SITH_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']) %}
{% if user.is_in_group(settings.SITH_GROUPS['root']['name']) or user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) %}
<li><a href="{{ url('subscription:subscription') }}">Subscriptions</a></li>
<li><a href="{{ url('counter:admin_list') }}">Counters management</a></li>
{% endif %}
......
......@@ -13,13 +13,13 @@ class Counter(models.Model):
products = models.ManyToManyField(Product, related_name="counters", blank=True)
type = models.CharField(_('subscription type'),
max_length=255,
choices=[('BAR',_('Bar')), ('OFFICE',_('Office'))]) # TODO: add _ to translate
choices=[('BAR',_('Bar')), ('OFFICE',_('Office'))])
edit_groups = models.ManyToManyField(Group, related_name="editable_counters", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_counters", blank=True)
def __getattribute__(self, name):
if name == "owner_group":
return Group(name=self.club.unix_name+"-board")
return Group(name=self.club.unix_name+settings.SITH_BOARD_SUFFIX)
return object.__getattribute__(self, name)
def __str__(self):
......@@ -29,4 +29,4 @@ class Counter(models.Model):
return reverse('counter:details', kwargs={'counter_id': self.id})
def can_be_viewed_by(self, user):
return user.is_in_group(settings.AE_GROUPS['board']['name'])
return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP)
......@@ -4,6 +4,7 @@ from counter.views import *
urlpatterns = [
url(r'^(?P<counter_id>[0-9]+)$', CounterDetail.as_view(), name='details'),
url(r'^(?P<counter_id>[0-9]+)/login$', CounterLogin.as_view(), name='login'),
url(r'^admin/(?P<counter_id>[0-9]+)$', CounterEditView.as_view(), name='admin'),
url(r'^admin$', CounterListView.as_view(), name='admin_list'),
url(r'^admin/new$', CounterCreateView.as_view(), name='new'),
......
from django.shortcuts import render
from django.views.generic import ListView, DetailView
from django.views.generic import ListView, DetailView, RedirectView
from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.forms.models import modelform_factory
from django.forms import CheckboxSelectMultiple
from django.core.urlresolvers import reverse_lazy
from django.contrib.auth.forms import AuthenticationForm
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from counter.models import Counter
# Create your views here.
class CounterListView(CanViewMixin, ListView):
model = Counter
template_name = 'counter/counter_list.jinja'
class CounterDetail(CanViewMixin, DetailView):
"""
The public (barman) view
"""
model = Counter
template_name = 'counter/counter_detail.jinja'
pk_url_kwarg = "counter_id"
class CounterLogin(RedirectView):
permanent = False
def post(self): # TODO: finish that
print(self.request)
form = AuthenticationForm(self.request, data=self.request.POST)
if form.is_valid():
print("Barman logged")
class CounterListView(CanViewMixin, ListView):
"""
A list view for the admins
"""
model = Counter
template_name = 'counter/counter_list.jinja'
class CounterEditView(CanEditMixin, UpdateView):
"""
Edit a Counter's main informations (for the counter's members)
Edit a counter's main informations (for the counter's admin)
"""
model = Counter
form_class = modelform_factory(Counter, fields=['name', 'club', 'type', 'products'],
......@@ -30,7 +44,7 @@ class CounterEditView(CanEditMixin, UpdateView):
class CounterCreateView(CanEditMixin, CreateView):
"""
Edit a Counter's main informations (for the counter's members)
Create a counter (for the admins)
"""
model = Counter
form_class = modelform_factory(Counter, fields=['name', 'club', 'type', 'products'],
......@@ -39,9 +53,11 @@ class CounterCreateView(CanEditMixin, CreateView):
class CounterDeleteView(CanEditMixin, DeleteView):
"""
Edit a Counter's main informations (for the counter's members)
Delete a counter (for the admins)
"""
model = Counter
pk_url_kwarg = "counter_id"
template_name = 'core/delete_confirm.jinja'
success_url = reverse_lazy('counter:admin_list')
......@@ -176,40 +176,38 @@ EMAIL_HOST="localhost"
EMAIL_PORT=25
# AE configuration
AE_MAIN_CLUB = {
SITH_MAIN_CLUB = {
'name': "AE",
'unix_name': "ae",
'address': "6 Boulevard Anatole France, 90000 Belfort"
}
# Define the date in the year serving as reference for the subscriptions calendar
# (month, day)
AE_START_DATE = (8, 15) # 15th August
AE_GROUPS = {
SITH_START_DATE = (8, 15) # 15th August
SITH_GROUPS = {
'root': {
'id': 1,
'name': "root",
},
'board': {
'id': 2,
'name': "ae-board",
},
'members': {
'id': 3,
'name': "ae-members",
},
'public': {
'id': 4,
'id': 2,
'name': "not_registered_users",
},
}
AE_PAYMENT_METHOD = [('cheque', 'Chèque'),
SITH_BOARD_SUFFIX="-board"
SITH_MEMBER_SUFFIX="-members"
SITH_MAIN_BOARD_GROUP=SITH_MAIN_CLUB['unix_name']+SITH_BOARD_SUFFIX
SITH_MAIN_MEMBERS_GROUP=SITH_MAIN_CLUB['unix_name']+SITH_MEMBER_SUFFIX
SITH_PAYMENT_METHOD = [('cheque', 'Chèque'),
('cash', 'Espèce'),
('other', 'Autre'),
]
# Subscription durations are in semestres (should be settingized)
AE_SUBSCRIPTIONS = {
SITH_SUBSCRIPTIONS = {
'un-semestre': {
'name': 'Un semestre',
'price': 15,
......
......@@ -9,11 +9,11 @@ from django.core.urlresolvers import reverse
from core.models import User
def validate_type(value):
if value not in settings.AE_SUBSCRIPTIONS.keys():
if value not in settings.SITH_SUBSCRIPTIONS.keys():
raise ValidationError(_('Bad subscription type'))
def validate_payment(value):
if value not in settings.AE_PAYMENT_METHOD:
if value not in settings.SITH_PAYMENT_METHOD:
raise ValidationError(_('Bad payment method'))
class Subscriber(User):
......@@ -31,10 +31,10 @@ class Subscription(models.Model):
member = models.ForeignKey(Subscriber, related_name='subscriptions')
subscription_type = models.CharField(_('subscription type'),
max_length=255,
choices=((k, v['name']) for k,v in sorted(settings.AE_SUBSCRIPTIONS.items())))
choices=((k, v['name']) for k,v in sorted(settings.SITH_SUBSCRIPTIONS.items())))
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)
payment_method = models.CharField(_('payment method'), max_length=255, choices=settings.SITH_PAYMENT_METHOD)
# TODO add location!
class Meta:
......@@ -59,7 +59,7 @@ class Subscription(models.Model):
"""
self.subscription_start = self.compute_start()
self.subscription_end = self.compute_end(
duration=settings.AE_SUBSCRIPTIONS[self.subscription_type]['duration'],
duration=settings.SITH_SUBSCRIPTIONS[self.subscription_type]['duration'],
start=self.subscription_start)
super(Subscription, self).save(*args, **kwargs)
......@@ -76,16 +76,16 @@ class Subscription(models.Model):
def compute_start(d=date.today()):
"""
This function computes the start date of the subscription with respect to the given date (default is today),
and the start date given in settings.AE_START_DATE.
and the start date given in settings.SITH_START_DATE.
It takes the nearest past start date.
Exemples: with AE_START_DATE = (8, 15)
Exemples: with SITH_START_DATE = (8, 15)
Today -> Start date
2015-03-17 -> 2015-02-15
2015-01-11 -> 2014-08-15
"""
today = d
year = today.year
start = date(year, settings.AE_START_DATE[0], settings.AE_START_DATE[1])
start = date(year, settings.SITH_START_DATE[0], settings.SITH_START_DATE[1])
start2 = start.replace(month=(start.month+6)%12)
if start > start2:
start, start2 = start2, start
......@@ -114,7 +114,7 @@ class Subscription(models.Model):
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'])
return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_in_group(settings.SITH_GROUPS['root']['name'])
def is_valid_now(self):
return self.subscription_start <= date.today() and date.today() <= self.subscription_end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment