Skip to content

Commit

Permalink
Merge pull request #3074 from pierre-24/betafix_zep12_typos_and_stuffs
Browse files Browse the repository at this point in the history
[beta 15.9] corrige plusieurs remarques sur le code
  • Loading branch information
Eskimon committed Oct 14, 2015
2 parents 0f4d66f + 8c7f3c3 commit 563a39b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 49 deletions.
29 changes: 3 additions & 26 deletions zds/tutorialv2/models/models_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def insert_data_in_versioned(self, versioned):
"""

attrs = [
'pk', 'authors', 'authors', 'subcategory', 'image', 'creation_date', 'pubdate', 'update_date', 'source',
'pk', 'authors', 'subcategory', 'image', 'creation_date', 'pubdate', 'update_date', 'source',
'sha_draft', 'sha_beta', 'sha_validation', 'sha_public'
]

Expand Down Expand Up @@ -491,17 +491,6 @@ def antispam(self, user=None):
if t.total_seconds() < settings.ZDS_APP['forum']['spam_limit_seconds']:
return True

return False

def change_type(self, new_type):
"""Allow someone to change the content type, basically from tutorial to article
:param new_type: the new type, either `"ARTICLE"` or `"TUTORIAL"`
"""
if new_type not in TYPE_CHOICES:
raise ValueError("This type of content does not exist")
self.type = new_type

def repo_delete(self):
"""
Delete the entities and their filesystem counterparts
Expand Down Expand Up @@ -536,8 +525,6 @@ class PublishedContent(models.Model):
Linked to a ``PublishableContent`` for the rest. Don't forget to add a ``.prefetch_related("content")`` !!
"""

# TODO: by playing with this class, it may solve most of the SEO problems !!

class Meta:
verbose_name = 'Contenu publié'
verbose_name_plural = 'Contenus publiés'
Expand Down Expand Up @@ -571,12 +558,7 @@ def get_absolute_url_online(self):
:return: the URL of the published content
:rtype: str
"""
reversed_ = ''

if self.is_article():
reversed_ = 'article'
elif self.is_tutorial():
reversed_ = 'tutorial'
reversed_ = self.content_type.lower()

return reverse(reversed_ + ':view', kwargs={'pk': self.content_pk, 'slug': self.content_public_slug})

Expand Down Expand Up @@ -685,12 +667,7 @@ def get_absolute_url_to_extra_content(self, type_):
allowed_types = ['pdf', 'md', 'html', 'epub', 'zip']

if type_ in allowed_types:
reversed_ = ''

if self.is_article():
reversed_ = 'article'
elif self.is_tutorial():
reversed_ = 'tutorial'
reversed_ = self.content_type.lower()

return reverse(
reversed_ + ':download-' + type_, kwargs={'pk': self.content_pk, 'slug': self.content_public_slug})
Expand Down
3 changes: 0 additions & 3 deletions zds/tutorialv2/models/models_versioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class Container:
children_dict = {}
slug_pool = {}

# TODO: thumbnails ?

def __init__(self, title, slug='', parent=None, position_in_parent=1):
"""Initialize the data model that will handle the dialog with raw versionned data at level container
Expand Down Expand Up @@ -278,7 +276,6 @@ def update_children(self):
child.update_children()
elif isinstance(child, Extract):
child.text = child.get_path(relative=True)
# TODO : does this function should also rewrite `slug_pool` ?

def get_path(self, relative=False):
"""Get the physical path to the draft version of the container.
Expand Down
5 changes: 4 additions & 1 deletion zds/tutorialv2/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3268,15 +3268,18 @@ def test_publication_make_extra_contents(self):
self.assertTrue(published.have_type(extra))
result = self.client.get(published.get_absolute_url_to_extra_content(extra))
self.assertEqual(result.status_code, 200)

# test that deletion give a 404
markdown_url = published.get_absolute_url_md()
md_path = os.path.join(published.get_extra_contents_directory(), published.content_public_slug + '.md')
os.remove(md_path)
self.assertEqual(404, self.client.get(markdown_url).status_code)
self.assertEqual('', published.get_absolute_url_to_extra_content('kboom'))
self.client.logout()

with open(md_path, "w") as f:
with open(md_path, "w") as f: # remake a .md file, whatever the content
f.write("I rebuilt it to finish the test. Perhaps a funny quote would be a good thing?")

# same test with author:
self.assertEqual(
self.client.login(
Expand Down
2 changes: 0 additions & 2 deletions zds/tutorialv2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,6 @@ def publish_container(db_object, base_dir, container):
if not isinstance(container, Container):
raise FailureDuringPublication(_(u'Le conteneur n\'en est pas un !'))

# TODO: images stuff !!

template = 'tutorialv2/export/chapter.html'

# jsFiddle support
Expand Down
26 changes: 13 additions & 13 deletions zds/tutorialv2/views/views_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ def delete(self, request, *args, **kwargs):

if self.object.authors.count() > 1: # if more than one author, just remove author from list
RemoveAuthorFromContent.remove_author(self.object, self.request.user)
messages.success(self.request, _(u'Vous avez quitté la rédaction de {}').format(_type))
messages.success(self.request, _(u'Vous avez quitté la rédaction de {}.').format(_type))

else:
validation = Validation.objects.filter(content=self.object).order_by("-date_proposition").first()

if validation and validation.status == 'PENDING_V': # if the validation have a validator, warn him by PM
if 'text' not in self.request.POST or len(self.request.POST['text'].strip()) < 3:
messages.error(self.request, 'Merci de fournir une raison à la suppression.')
messages.error(self.request, _(u'Merci de fournir une raison à la suppression.'))
return redirect(self.object.get_absolute_url())
else:
bot = get_object_or_404(User, username=settings.ZDS_APP['member']['bot_account'])
Expand Down Expand Up @@ -388,7 +388,7 @@ def delete(self, request, *args, **kwargs):

self.object.delete()

messages.success(self.request, _(u'Vous avez bien supprimé {}').format(_type))
messages.success(self.request, _(u'Vous avez bien supprimé {}.').format(_type))

return redirect(reverse('content:find-' + object_type, args=[request.user.pk]))

Expand Down Expand Up @@ -679,7 +679,7 @@ def form_valid(self, form):
try:
zfile = zipfile.ZipFile(self.request.FILES['archive'], "r")
except zipfile.BadZipfile:
messages.error(self.request, _(u'Cette archive n\'est pas au format ZIP'))
messages.error(self.request, _(u'Cette archive n\'est pas au format ZIP.'))
return super(UpdateContentWithArchive, self).form_invalid(form)

try:
Expand All @@ -693,7 +693,7 @@ def form_valid(self, form):
manifest = json_reader.loads(unicode(zfile.read('manifest.json'), 'utf-8'))
if 'licence' not in manifest or manifest['licence'] != new_version.licence.code:
messages.info(
self.request, _(u'la licence « {} » a été appliquée'.format(new_version.licence.code)))
self.request, _(u'la licence « {} » a été appliquée.').format(new_version.licence.code))

# first, update DB object (in order to get a new slug if needed)
self.object.title = new_version.title
Expand Down Expand Up @@ -752,7 +752,7 @@ def form_valid(self, form):
try:
zfile = zipfile.ZipFile(self.request.FILES["image_archive"], "r")
except zipfile.BadZipfile:
messages.error(self.request, _(u'L\'archive contenant les images n\'est pas au format ZIP'))
messages.error(self.request, _(u'L\'archive contenant les images n\'est pas au format ZIP.'))
return self.form_invalid(form)

UpdateContentWithArchive.use_images_from_archive(
Expand Down Expand Up @@ -787,7 +787,7 @@ def form_valid(self, form):
try:
zfile = zipfile.ZipFile(self.request.FILES['archive'], "r")
except zipfile.BadZipfile:
messages.error(self.request, _(u'Cette archive n\'est pas au format ZIP'))
messages.error(self.request, _(u'Cette archive n\'est pas au format ZIP.'))
return self.form_invalid(form)

try:
Expand All @@ -804,7 +804,7 @@ def form_valid(self, form):
manifest = json_reader.loads(unicode(zfile.read('manifest.json'), 'utf-8'))
if 'licence' not in manifest or manifest['licence'] != new_content.licence.code:
messages.info(
self.request, _(u'la licence « {} » a été appliquée'.format(new_content.licence.code)))
self.request, _(u'la licence « {} » a été appliquée.'.format(new_content.licence.code)))

# first, create DB object (in order to get a slug)
self.object = PublishableContent()
Expand Down Expand Up @@ -875,7 +875,7 @@ def form_valid(self, form):
try:
zfile = zipfile.ZipFile(self.request.FILES["image_archive"], "r")
except zipfile.BadZipfile:
messages.error(self.request, _(u'L\'archive contenant les images n\'est pas au format ZIP'))
messages.error(self.request, _(u'L\'archive contenant les images n\'est pas au format ZIP.'))
return self.form_invalid(form)

UpdateContentWithArchive.use_images_from_archive(
Expand Down Expand Up @@ -913,7 +913,7 @@ def get_context_data(self, **kwargs):
def render_to_response(self, context, **response_kwargs):
parent = context['container']
if not parent.can_add_container():
messages.error(self.request, _(u'Vous ne pouvez plus ajouter de conteneur à « {} »').format(parent.title))
messages.error(self.request, _(u'Vous ne pouvez plus ajouter de conteneur à « {} ».').format(parent.title))
return redirect(parent.get_absolute_url())

return super(CreateContainer, self).render_to_response(context, **response_kwargs)
Expand Down Expand Up @@ -1092,7 +1092,7 @@ def get_context_data(self, **kwargs):
def render_to_response(self, context, **response_kwargs):
parent = context['container']
if not parent.can_add_extract():
messages.error(self.request, _(u'Vous ne pouvez plus ajouter de section à « {} »').format(parent.title))
messages.error(self.request, _(u'Vous ne pouvez plus ajouter de section à « {} ».').format(parent.title))
return redirect(parent.get_absolute_url())

return super(CreateExtract, self).render_to_response(context, **response_kwargs)
Expand Down Expand Up @@ -1787,10 +1787,10 @@ def form_valid(self, form):

if not current_user: # if the removed author is not current user
messages.success(
self.request, _(u'Vous avez enlevé {} de la liste des auteurs de {}').format(authors_list, _type))
self.request, _(u'Vous avez enlevé {} de la liste des auteurs de « {} ».').format(authors_list, _type))
self.success_url = self.object.get_absolute_url()
else: # if current user is leaving the content's redaction, redirect him to a more suitable page
messages.success(self.request, _(u'Vous avez bien quitté la rédaction de {}').format(_type))
messages.success(self.request, _(u'Vous avez bien quitté la rédaction de « {} ».').format(_type))
self.success_url = reverse('content:find-' + self.object.type.lower(), args=[self.request.user.pk])
self.already_finished = True # this one is kind of tricky : because of inheritance we used to force redirection
# to the content itself. This does not please me but I think it is better to do that like that instead of
Expand Down
4 changes: 1 addition & 3 deletions zds/tutorialv2/views/views_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ def get_context_data(self, **kwargs):
"""Show the given tutorial if exists."""
context = super(DisplayOnlineContent, self).get_context_data(**kwargs)

# TODO: deal with messaging and stuff like this !!

if context['is_staff']:
context['formRevokeValidation'] = RevokeValidationForm(
self.versioned_object, initial={'version': self.versioned_object.sha_public})
Expand Down Expand Up @@ -630,7 +628,7 @@ def post(self, request, *args, **kwargs):
alert.pubdate = datetime.now()
alert.save()

messages.success(self.request, _(u"Ce commentaire a bien été signalé aux modérateurs"))
messages.success(self.request, _(u"Ce commentaire a bien été signalé aux modérateurs."))
return redirect(note.get_absolute_url())


Expand Down
1 change: 0 additions & 1 deletion zds/tutorialv2/views/views_validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def form_valid(self, form):
# warn the former validator that an update has been made, if any
if old_validator:
validation.validator = old_validator
# TODO: why not let the validator be the same using PENDING_V ?

bot = get_object_or_404(User, username=settings.ZDS_APP['member']['bot_account'])
msg = render_to_string(
Expand Down

0 comments on commit 563a39b

Please sign in to comment.