mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Add com app with first parametric texts
This commit is contained in:
0
com/__init__.py
Normal file
0
com/__init__.py
Normal file
8
com/admin.py
Normal file
8
com/admin.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from com.models import *
|
||||
|
||||
admin.site.register(Sith)
|
||||
|
||||
|
||||
|
22
com/migrations/0001_initial.py
Normal file
22
com/migrations/0001_initial.py
Normal file
@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Sith',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)),
|
||||
('alert_msg', models.TextField(default='', verbose_name='alert message', blank=True)),
|
||||
('info_msg', models.TextField(default='', verbose_name='info message', blank=True)),
|
||||
('index_page', models.TextField(default='', verbose_name='index page', blank=True)),
|
||||
],
|
||||
),
|
||||
]
|
0
com/migrations/__init__.py
Normal file
0
com/migrations/__init__.py
Normal file
15
com/models.py
Normal file
15
com/models.py
Normal file
@ -0,0 +1,15 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.conf import settings
|
||||
|
||||
class Sith(models.Model):
|
||||
alert_msg = models.TextField(_("alert message"), default="", blank=True)
|
||||
info_msg = models.TextField(_("info message"), default="", blank=True)
|
||||
index_page = models.TextField(_("index page"), default="", blank=True)
|
||||
|
||||
def is_owned_by(self, user):
|
||||
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
|
||||
|
||||
def __str__(self):
|
||||
return "⛩ Sith ⛩"
|
||||
|
35
com/tests.py
Normal file
35
com/tests.py
Normal file
@ -0,0 +1,35 @@
|
||||
from django.test import TestCase
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.management import call_command
|
||||
|
||||
from core.models import User, RealGroup
|
||||
from com.models import Sith
|
||||
|
||||
class ComTest(TestCase):
|
||||
def setUp(self):
|
||||
call_command("populate")
|
||||
self.skia = User.objects.filter(username="skia").first()
|
||||
self.com_group = RealGroup.objects.filter(id=settings.SITH_GROUP_COM_ADMIN_ID).first()
|
||||
self.skia.groups = [self.com_group]
|
||||
self.skia.save()
|
||||
self.client.login(username=self.skia.username, password='plop')
|
||||
|
||||
def test_alert_msg(self):
|
||||
response = self.client.post(reverse("com:alert_edit"), {"alert_msg": """
|
||||
### ALERTE!
|
||||
|
||||
**Caaaataaaapuuuulte!!!!**
|
||||
"""})
|
||||
r = self.client.get(reverse("core:index"))
|
||||
self.assertTrue(r.status_code == 200)
|
||||
self.assertTrue("""<div id="alert_box">\\n <h3>ALERTE!</h3>\\n<p><strong>Caaaataaaapuuuulte!!!!</strong></p>""" in str(r.content))
|
||||
|
||||
def test_info_msg(self):
|
||||
response = self.client.post(reverse("com:info_edit"), {"info_msg": """
|
||||
### INFO: **Caaaataaaapuuuulte!!!!**
|
||||
"""})
|
||||
r = self.client.get(reverse("core:index"))
|
||||
self.assertTrue(r.status_code == 200)
|
||||
self.assertTrue("""<div id="info_box">\\n <h3>INFO: <strong>Caaaataaaapuuuulte!!!!</strong></h3>""" in str(r.content))
|
||||
|
10
com/urls.py
Normal file
10
com/urls.py
Normal file
@ -0,0 +1,10 @@
|
||||
from django.conf.urls import url, include
|
||||
|
||||
from com.views import *
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^edit/alert$', AlertMsgEditView.as_view(), name='alert_edit'),
|
||||
url(r'^edit/info$', InfoMsgEditView.as_view(), name='info_edit'),
|
||||
url(r'^edit/index$', IndexEditView.as_view(), name='index_edit'),
|
||||
]
|
||||
|
55
com/views.py
Normal file
55
com/views.py
Normal file
@ -0,0 +1,55 @@
|
||||
from django.shortcuts import render
|
||||
from django.views.generic.edit import UpdateView
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.urlresolvers import reverse, reverse_lazy
|
||||
|
||||
from com.models import Sith
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
|
||||
|
||||
|
||||
sith = Sith.objects.first
|
||||
|
||||
class ComTabsMixin(TabedViewMixin):
|
||||
def get_tabs_title(self):
|
||||
return _("Communication administration")
|
||||
|
||||
def get_list_of_tabs(self):
|
||||
tab_list = []
|
||||
tab_list.append({
|
||||
'url': reverse('com:index_edit'),
|
||||
'slug': 'index',
|
||||
'name': _("Index page"),
|
||||
})
|
||||
tab_list.append({
|
||||
'url': reverse('com:info_edit'),
|
||||
'slug': 'info',
|
||||
'name': _("Info message"),
|
||||
})
|
||||
tab_list.append({
|
||||
'url': reverse('com:alert_edit'),
|
||||
'slug': 'alert',
|
||||
'name': _("Alert message"),
|
||||
})
|
||||
return tab_list
|
||||
|
||||
class ComEditView(ComTabsMixin, CanEditPropMixin, UpdateView):
|
||||
model = Sith
|
||||
template_name = 'core/edit.jinja'
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return Sith.objects.first()
|
||||
|
||||
class AlertMsgEditView(ComEditView):
|
||||
fields = ['alert_msg']
|
||||
current_tab = "alert"
|
||||
success_url = reverse_lazy('com:alert_edit')
|
||||
|
||||
class InfoMsgEditView(ComEditView):
|
||||
fields = ['info_msg']
|
||||
current_tab = "info"
|
||||
success_url = reverse_lazy('com:info_edit')
|
||||
|
||||
class IndexEditView(ComEditView):
|
||||
fields = ['index_page']
|
||||
current_tab = "index"
|
||||
success_url = reverse_lazy('com:index_edit')
|
Reference in New Issue
Block a user