Commit e7de8b2a authored by Krophil's avatar Krophil

Format core

parent 4f4ea5dd
...@@ -33,8 +33,9 @@ admin.site.unregister(AuthGroup) ...@@ -33,8 +33,9 @@ admin.site.unregister(AuthGroup)
admin.site.register(RealGroup) admin.site.register(RealGroup)
admin.site.register(Page) admin.site.register(Page)
@admin.register(SithFile) @admin.register(SithFile)
class SithFileAdmin(admin.ModelAdmin): class SithFileAdmin(admin.ModelAdmin):
form = make_ajax_form(SithFile, { form = make_ajax_form(SithFile, {
'parent': 'files', # ManyToManyField 'parent': 'files', # ManyToManyField
}) })
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
# #
from django.apps import AppConfig from django.apps import AppConfig
from django.dispatch import receiver
from django.core.signals import request_started from django.core.signals import request_started
class SithConfig(AppConfig): class SithConfig(AppConfig):
name = 'core' name = 'core'
verbose_name = "Core app of the Sith" verbose_name = "Core app of the Sith"
...@@ -48,4 +48,3 @@ class SithConfig(AppConfig): ...@@ -48,4 +48,3 @@ class SithConfig(AppConfig):
request_started.connect(clear_cached_groups, weak=False, dispatch_uid="clear_cached_groups") request_started.connect(clear_cached_groups, weak=False, dispatch_uid="clear_cached_groups")
request_started.connect(clear_cached_memberships, weak=False, dispatch_uid="clear_cached_memberships") request_started.connect(clear_cached_memberships, weak=False, dispatch_uid="clear_cached_memberships")
# TODO: there may be a need to add more cache clearing # TODO: there may be a need to add more cache clearing
...@@ -31,16 +31,19 @@ from club.models import Club ...@@ -31,16 +31,19 @@ from club.models import Club
from counter.models import Product, Counter from counter.models import Product, Counter
from accounting.models import ClubAccount, Company from accounting.models import ClubAccount, Company
def check_token(request): def check_token(request):
return ('counter_token' in request.session.keys() and return ('counter_token' in request.session.keys() and
request.session['counter_token'] and request.session['counter_token'] and
Counter.objects.filter(token=request.session['counter_token']).exists()) Counter.objects.filter(token=request.session['counter_token']).exists())
class RightManagedLookupChannel(LookupChannel): class RightManagedLookupChannel(LookupChannel):
def check_auth(self, request): def check_auth(self, request):
if not request.user.was_subscribed and not check_token(request): if not request.user.was_subscribed and not check_token(request):
raise PermissionDenied raise PermissionDenied
@register('users') @register('users')
class UsersLookup(RightManagedLookupChannel): class UsersLookup(RightManagedLookupChannel):
model = User model = User
...@@ -54,6 +57,7 @@ class UsersLookup(RightManagedLookupChannel): ...@@ -54,6 +57,7 @@ class UsersLookup(RightManagedLookupChannel):
def format_item_display(self, item): def format_item_display(self, item):
return item.get_display_name() return item.get_display_name()
@register('groups') @register('groups')
class GroupsLookup(RightManagedLookupChannel): class GroupsLookup(RightManagedLookupChannel):
model = Group model = Group
...@@ -67,6 +71,7 @@ class GroupsLookup(RightManagedLookupChannel): ...@@ -67,6 +71,7 @@ class GroupsLookup(RightManagedLookupChannel):
def format_item_display(self, item): def format_item_display(self, item):
return item.name return item.name
@register('clubs') @register('clubs')
class ClubLookup(RightManagedLookupChannel): class ClubLookup(RightManagedLookupChannel):
model = Club model = Club
...@@ -80,6 +85,7 @@ class ClubLookup(RightManagedLookupChannel): ...@@ -80,6 +85,7 @@ class ClubLookup(RightManagedLookupChannel):
def format_item_display(self, item): def format_item_display(self, item):
return item.name return item.name
@register('counters') @register('counters')
class CountersLookup(RightManagedLookupChannel): class CountersLookup(RightManagedLookupChannel):
model = Counter model = Counter
...@@ -90,6 +96,7 @@ class CountersLookup(RightManagedLookupChannel): ...@@ -90,6 +96,7 @@ class CountersLookup(RightManagedLookupChannel):
def format_item_display(self, item): def format_item_display(self, item):
return item.name return item.name
@register('products') @register('products')
class ProductsLookup(RightManagedLookupChannel): class ProductsLookup(RightManagedLookupChannel):
model = Product model = Product
...@@ -101,6 +108,7 @@ class ProductsLookup(RightManagedLookupChannel): ...@@ -101,6 +108,7 @@ class ProductsLookup(RightManagedLookupChannel):
def format_item_display(self, item): def format_item_display(self, item):
return "%s (%s)" % (item.name, item.code) return "%s (%s)" % (item.name, item.code)
@register('files') @register('files')
class SithFileLookup(RightManagedLookupChannel): class SithFileLookup(RightManagedLookupChannel):
model = SithFile model = SithFile
...@@ -108,6 +116,7 @@ class SithFileLookup(RightManagedLookupChannel): ...@@ -108,6 +116,7 @@ class SithFileLookup(RightManagedLookupChannel):
def get_query(self, q, request): def get_query(self, q, request):
return self.model.objects.filter(name__icontains=q)[:50] return self.model.objects.filter(name__icontains=q)[:50]
@register('club_accounts') @register('club_accounts')
class ClubAccountLookup(RightManagedLookupChannel): class ClubAccountLookup(RightManagedLookupChannel):
model = ClubAccount model = ClubAccount
...@@ -118,6 +127,7 @@ class ClubAccountLookup(RightManagedLookupChannel): ...@@ -118,6 +127,7 @@ class ClubAccountLookup(RightManagedLookupChannel):
def format_item_display(self, item): def format_item_display(self, item):
return item.name return item.name
@register('companies') @register('companies')
class CompaniesLookup(RightManagedLookupChannel): class CompaniesLookup(RightManagedLookupChannel):
model = Company model = Company
......
...@@ -21,4 +21,3 @@ ...@@ -21,4 +21,3 @@
# Place - Suite 330, Boston, MA 02111-1307, USA. # Place - Suite 330, Boston, MA 02111-1307, USA.
# #
# #
...@@ -44,7 +44,6 @@ class Command(BaseCommand): ...@@ -44,7 +44,6 @@ class Command(BaseCommand):
args['precision'] = settings.SASS_PRECISION args['precision'] = settings.SASS_PRECISION
return sass.compile(**args) return sass.compile(**args)
def is_compilable(self, file, ext_list): def is_compilable(self, file, ext_list):
path, ext = os.path.splitext(file) path, ext = os.path.splitext(file)
return ext in ext_list return ext in ext_list
......
This diff is collapsed.
...@@ -23,9 +23,8 @@ ...@@ -23,9 +23,8 @@
# #
import os import os
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand
from django.core.management import call_command from django.core.management import call_command
from django.conf import settings
class Command(BaseCommand): class Command(BaseCommand):
...@@ -37,7 +36,7 @@ class Command(BaseCommand): ...@@ -37,7 +36,7 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
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__))))
try: try:
os.mkdir(os.path.join(root_path)+'/data') os.mkdir(os.path.join(root_path) + '/data')
print("Data dir created") print("Data dir created")
except Exception as e: except Exception as e:
repr(e) repr(e)
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
import re import re
from mistune import Renderer, InlineGrammar, InlineLexer, Markdown, escape, escape_link from mistune import Renderer, InlineGrammar, InlineLexer, Markdown, escape, escape_link
from django.core.urlresolvers import reverse_lazy, reverse from django.core.urlresolvers import reverse
class SithRenderer(Renderer): class SithRenderer(Renderer):
...@@ -54,13 +54,16 @@ class SithRenderer(Renderer): ...@@ -54,13 +54,16 @@ class SithRenderer(Renderer):
src = original_src src = original_src
else: else:
width = m.group(1) width = m.group(1)
if not width.endswith('%'): width += "px" if not width.endswith('%'):
width += "px"
style = "width: %s; " % width style = "width: %s; " % width
try: try:
height = m.group(3) height = m.group(3)
if not height.endswith('%'): height += "px" if not height.endswith('%'):
height += "px"
style += "height: %s; " % height style += "height: %s; " % height
except: pass except:
pass
else: else:
params = None params = None
src = original_src src = original_src
...@@ -77,6 +80,7 @@ class SithRenderer(Renderer): ...@@ -77,6 +80,7 @@ class SithRenderer(Renderer):
return '%s />' % html return '%s />' % html
return '%s>' % html return '%s>' % html
class SithInlineGrammar(InlineGrammar): class SithInlineGrammar(InlineGrammar):
double_emphasis = re.compile( double_emphasis = re.compile(
r'^\*{2}([\s\S]+?)\*{2}(?!\*)' # **word** r'^\*{2}([\s\S]+?)\*{2}(?!\*)' # **word**
...@@ -94,6 +98,7 @@ class SithInlineGrammar(InlineGrammar): ...@@ -94,6 +98,7 @@ class SithInlineGrammar(InlineGrammar):
r'^<sub>([\s\S]+?)</sub>' # <sub>text</sub> r'^<sub>([\s\S]+?)</sub>' # <sub>text</sub>
) )
class SithInlineLexer(InlineLexer): class SithInlineLexer(InlineLexer):
grammar_class = SithInlineGrammar grammar_class = SithInlineGrammar
...@@ -159,15 +164,16 @@ class SithInlineLexer(InlineLexer): ...@@ -159,15 +164,16 @@ class SithInlineLexer(InlineLexer):
return self.renderer.emphasis(text) return self.renderer.emphasis(text)
def _process_link(self, m, link, title=None): def _process_link(self, m, link, title=None):
try: # Add page:// support for links try: # Add page:// support for links
page = re.compile( page = re.compile(
r'^page://(\S*)' # page://nom_de_ma_page r'^page://(\S*)' # page://nom_de_ma_page
) )
match = page.search(link) match = page.search(link)
page = match.group(1) or "" page = match.group(1) or ""
link = reverse('core:page', kwargs={'page_name': page}) link = reverse('core:page', kwargs={'page_name': page})
except: pass except:
try: # Add file:// support for links pass
try: # Add file:// support for links
file_link = re.compile( file_link = re.compile(
r'^file://(\d*)/?(\S*)?' # file://4000/download r'^file://(\d*)/?(\S*)?' # file://4000/download
) )
...@@ -175,9 +181,11 @@ class SithInlineLexer(InlineLexer): ...@@ -175,9 +181,11 @@ class SithInlineLexer(InlineLexer):
id = match.group(1) id = match.group(1)
suffix = match.group(2) or "" suffix = match.group(2) or ""
link = reverse('core:file_detail', kwargs={'file_id': id}) + suffix link = reverse('core:file_detail', kwargs={'file_id': id}) + suffix
except: pass except:
pass
return super(SithInlineLexer, self)._process_link(m, link, title) return super(SithInlineLexer, self)._process_link(m, link, title)
renderer = SithRenderer(escape=True) renderer = SithRenderer(escape=True)
inline = SithInlineLexer(renderer) inline = SithInlineLexer(renderer)
...@@ -222,4 +230,3 @@ Petit *test* _sur_ ^une^ **seule** ^ligne pour voir^ ...@@ -222,4 +230,3 @@ Petit *test* _sur_ ^une^ **seule** ^ligne pour voir^
""" """
print(markdown(text)) print(markdown(text))
...@@ -52,4 +52,3 @@ class AuthenticationMiddleware(DjangoAuthenticationMiddleware): ...@@ -52,4 +52,3 @@ class AuthenticationMiddleware(DjangoAuthenticationMiddleware):
"'account.middleware.AuthenticationMiddleware'." "'account.middleware.AuthenticationMiddleware'."
) )
request.user = SimpleLazyObject(lambda: get_cached_user(request)) request.user = SimpleLazyObject(lambda: get_cached_user(request))
This diff is collapsed.
...@@ -27,30 +27,32 @@ from django import template ...@@ -27,30 +27,32 @@ from django import template
from django.template.defaultfilters import stringfilter from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from core.scss.processor import ScssProcessor from core.scss.processor import ScssProcessor
from django.utils.html import escape
from core.markdown import markdown as md from core.markdown import markdown as md
register = template.Library() register = template.Library()
@register.filter(is_safe=False) @register.filter(is_safe=False)
@stringfilter @stringfilter
def markdown(text): def markdown(text):
return mark_safe("<div class=\"markdown\">%s</div>" % md(text)) return mark_safe("<div class=\"markdown\">%s</div>" % md(text))
@register.filter() @register.filter()
@stringfilter @stringfilter
def datetime_format_python_to_PHP(python_format_string): def datetime_format_python_to_PHP(python_format_string):
""" """
Given a python datetime format string, attempts to convert it to the nearest PHP datetime format string possible. Given a python datetime format string, attempts to convert it to the nearest PHP datetime format string possible.
""" """
python2PHP = {"%a": "D", "%a": "D", "%A": "l", "%b": "M", "%B": "F", "%c": "", "%d": "d", "%H": "H", "%I": "h", "%j": "z", "%m": "m", "%M": "i", "%p": "A", "%S": "s", "%U": "", "%w": "w", "%W": "W", "%x": "", "%X": "", "%y": "y", "%Y": "Y", "%Z": "e" } python2PHP = {"%a": "D", "%a": "D", "%A": "l", "%b": "M", "%B": "F", "%c": "", "%d": "d", "%H": "H", "%I": "h", "%j": "z", "%m": "m", "%M": "i", "%p": "A", "%S": "s", "%U": "", "%w": "w", "%W": "W", "%x": "", "%X": "", "%y": "y", "%Y": "Y", "%Z": "e"}
php_format_string = python_format_string php_format_string = python_format_string
for py, php in python2PHP.items(): for py, php in python2PHP.items():
php_format_string = php_format_string.replace(py, php) php_format_string = php_format_string.replace(py, php)
return php_format_string return php_format_string
@register.simple_tag() @register.simple_tag()
def scss(path): def scss(path):
""" """
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
from django.test import Client, TestCase from django.test import Client, TestCase
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.models import Group
from django.core.management import call_command from django.core.management import call_command
from core.models import User, Group, Page from core.models import User, Group, Page
...@@ -34,6 +33,7 @@ to run these tests : ...@@ -34,6 +33,7 @@ to run these tests :
python3 manage.py test python3 manage.py test
""" """
class UserRegistrationTest(TestCase): class UserRegistrationTest(TestCase):
def setUp(self): def setUp(self):
try: try:
...@@ -52,7 +52,7 @@ class UserRegistrationTest(TestCase): ...@@ -52,7 +52,7 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_OK' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_OK' in str(response.content))
...@@ -67,7 +67,7 @@ class UserRegistrationTest(TestCase): ...@@ -67,7 +67,7 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop2', 'password2': 'plop2',
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -82,7 +82,7 @@ class UserRegistrationTest(TestCase): ...@@ -82,7 +82,7 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -97,7 +97,7 @@ class UserRegistrationTest(TestCase): ...@@ -97,7 +97,7 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -112,7 +112,7 @@ class UserRegistrationTest(TestCase): ...@@ -112,7 +112,7 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '', 'date_of_birth': '',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -127,7 +127,7 @@ class UserRegistrationTest(TestCase): ...@@ -127,7 +127,7 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -142,14 +142,14 @@ class UserRegistrationTest(TestCase): ...@@ -142,14 +142,14 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
}) })
response = c.post(reverse('core:register'), {'first_name': 'Bibou', response = c.post(reverse('core:register'), {'first_name': 'Bibou',
'last_name': 'Carlier', 'last_name': 'Carlier',
'email': 'bibou@git.an', 'email': 'bibou@git.an',
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
}) })
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content)) self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
...@@ -164,7 +164,7 @@ class UserRegistrationTest(TestCase): ...@@ -164,7 +164,7 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
}) })
response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'plop'}) response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'plop'})
self.assertTrue(response.status_code == 302) self.assertTrue(response.status_code == 302)
#self.assertTrue('Hello, world' in str(response.content)) #self.assertTrue('Hello, world' in str(response.content))
...@@ -180,11 +180,12 @@ class UserRegistrationTest(TestCase): ...@@ -180,11 +180,12 @@ class UserRegistrationTest(TestCase):
'date_of_birth': '12/6/1942', 'date_of_birth': '12/6/1942',
'password1': 'plop', 'password1': 'plop',
'password2': 'plop', 'password2': 'plop',
}) })
response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'guy'}) response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'guy'})
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue("""<p>Votre nom d\\'utilisateur et votre mot de passe ne correspondent pas. Merci de r\\xc3\\xa9essayer.</p>""" in str(response.content)) self.assertTrue("""<p>Votre nom d\\'utilisateur et votre mot de passe ne correspondent pas. Merci de r\\xc3\\xa9essayer.</p>""" in str(response.content))
class PageHandlingTest(TestCase): class PageHandlingTest(TestCase):
def setUp(self): def setUp(self):
try: try:
...@@ -207,7 +208,7 @@ class PageHandlingTest(TestCase): ...@@ -207,7 +208,7 @@ class PageHandlingTest(TestCase):
'parent': '', 'parent': '',
'name': 'guy', 'name': 'guy',
'owner_group': 1, 'owner_group': 1,
}) })
response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy'})) response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy'}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('<a href="/page/guy/hist">' in str(response.content)) self.assertTrue('<a href="/page/guy/hist">' in str(response.content))
...@@ -220,12 +221,12 @@ class PageHandlingTest(TestCase): ...@@ -220,12 +221,12 @@ class PageHandlingTest(TestCase):
'parent': '', 'parent': '',
'name': 'guy', 'name': 'guy',
'owner_group': '1', 'owner_group': '1',
}) })
response = self.client.post(reverse('core:page_new'), { response = self.client.post(reverse('core:page_new'), {
'parent': '1', 'parent': '1',
'name': 'bibou', 'name': 'bibou',
'owner_group': '1', 'owner_group': '1',
}) })
response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy/bibou'})) response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy/bibou'}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('<a href="/page/guy/bibou/">' in str(response.content)) self.assertTrue('<a href="/page/guy/bibou/">' in str(response.content))
...@@ -259,11 +260,11 @@ class PageHandlingTest(TestCase): ...@@ -259,11 +260,11 @@ class PageHandlingTest(TestCase):
'parent': '', 'parent': '',
'name': 'guy', 'name': 'guy',
'owner_group': '1', 'owner_group': '1',
}) })
r = self.client.post(reverse('core:page_edit', kwargs={'page_name': 'guy'}), { self.client.post(reverse('core:page_edit', kwargs={'page_name': 'guy'}), {
'title': 'Bibou', 'title': 'Bibou',
'content': 'content':
'''Guy *bibou* '''Guy *bibou*
http://git.an http://git.an
...@@ -273,18 +274,19 @@ http://git.an ...@@ -273,18 +274,19 @@ http://git.an
<script>alert('Guy');</script> <script>alert('Guy');</script>
''', ''',
}) })
response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy'})) response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy'}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('<p>Guy <em>bibou</em></p>\\n<p><a href="http://git.an">http://git.an</a></p>\\n' + self.assertTrue('<p>Guy <em>bibou</em></p>\\n<p><a href="http://git.an">http://git.an</a></p>\\n' +
'<h1>Swag</h1>\\n&lt;guy&gt;Bibou&lt;/guy&gt;' + '<h1>Swag</h1>\\n&lt;guy&gt;Bibou&lt;/guy&gt;' +
"&lt;script&gt;alert(\\'Guy\\');&lt;/script&gt;" in str(response.content)) "&lt;script&gt;alert(\\'Guy\\');&lt;/script&gt;" in str(response.content))
#TODO: many tests on the pages: # TODO: many tests on the pages:
# - renaming a page # - renaming a page
# - changing a page's parent --> check that page's children's full_name # - changing a page's parent --> check that page's children's full_name
# - changing the different groups of the page # - changing the different groups of the page
class FileHandlingTest(TestCase): class FileHandlingTest(TestCase):
def setUp(self): def setUp(self):
try: try:
...@@ -295,19 +297,18 @@ class FileHandlingTest(TestCase): ...@@ -295,19 +297,18 @@ class FileHandlingTest(TestCase):
print(e) print(e)
def test_create_folder_home(self): def test_create_folder_home(self):
response = self.client.post(reverse("core:file_detail", kwargs={"file_id":self.subscriber.home.id}), response = self.client.post(reverse("core:file_detail", kwargs={"file_id": self.subscriber.home.id}),
{"folder_name": "GUY_folder_test"}) {"folder_name": "GUY_folder_test"})
self.assertTrue(response.status_code == 302) self.assertTrue(response.status_code == 302)
response = self.client.get(reverse("core:file_detail", kwargs={"file_id":self.subscriber.home.id})) response = self.client.get(reverse("core:file_detail", kwargs={"file_id": self.subscriber.home.id}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue("GUY_folder_test</a>" in str(response.content)) self.assertTrue("GUY_folder_test</a>" in str(response.content))
def test_upload_file_home(self): def test_upload_file_home(self):
with open("/bin/ls", "rb") as f: with open("/bin/ls", "rb") as f:
response = self.client.post(reverse("core:file_detail", kwargs={"file_id":self.subscriber.home.id}), response = self.client.post(reverse("core:file_detail", kwargs={"file_id": self.subscriber.home.id}),
{"file_field": f}) {"file_field": f})
self.assertTrue(response.status_code == 302) self.assertTrue(response.status_code == 302)
response = self.client.get(reverse("core:file_detail", kwargs={"file_id":self.subscriber.home.id})) response = self.client.get(reverse("core:file_detail", kwargs={"file_id": self.subscriber.home.id}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue("ls</a>" in str(response.content)) self.assertTrue("ls</a>" in str(response.content))
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
# #
# #
from django.conf.urls import url, include from django.conf.urls import url
from core.views import * from core.views import *
......
This diff is collapsed.
...@@ -23,29 +23,28 @@ ...@@ -23,29 +23,28 @@
# #
# This file contains all the views that concern the page model # This file contains all the views that concern the page model
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import redirect
from django.views.generic import ListView, DetailView, TemplateView from django.views.generic import ListView, DetailView, TemplateView
from django.views.generic.edit import UpdateView, CreateView, FormMixin, DeleteView from django.views.generic.edit import UpdateView, FormMixin, DeleteView
from django.views.generic.detail import SingleObjectMixin from django.views.generic.detail import SingleObjectMixin
from django.contrib.auth.decorators import login_required, permission_required
from django.forms.models import modelform_factory from django.forms.models import modelform_factory
from django.forms import CheckboxSelectMultiple
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse