Skip to content

Commit

Permalink
Suppression des fonctions des tutoriels du SdZ (#3674)
Browse files Browse the repository at this point in the history
* Suppression des fonction des tutoriels du SdZ

* Suppression des fonctions des tutoriels du SdZ

* Suppression d'un import inutilisé

* Suppression des fonctions des tutoriels du SdZ

* Suppression des fonctions des tutoriels du SdZ
  • Loading branch information
Emeric54 authored and gustavi committed Jun 20, 2016
1 parent 032b289 commit 693463f
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 241 deletions.
49 changes: 0 additions & 49 deletions templates/member/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,40 +165,6 @@ <h2 id="activity">{% trans "Activité" %}</h2>
</figure>
</section>
{% endif %}


{% if old_tutos and perms.member.change_profile %}
<hr class="clearfix" />
<section class="full-content-wrapper without-margin">
<h2 id="anciens-tutoriels-sdz">{% trans "Anciens tutoriels SdZ" %}</h2>
<table>
<thead>
<tr>
<th>{% trans "Tutoriel" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
{% for id, titre in old_tutos %}
<tr>
<td>{{ titre }}</td>
<td>
<a href="#delete-old-tutorial-{{ id }}" class="btn btn-submit open-modal">{% trans "Supprimer" %}</a>
<div class="modal modal-flex" id="delete-old-tutorial-{{ id }}">
<p>
{% blocktrans with tutotitle=titre%}
Attention ! Vous êtes sur le point de supprimer le tutoriel "<em>{{ tutotitle }}</em>".
{% endblocktrans %}
</p>
<a href="{% url "member-remove-oldtuto" %}?id={{ id }}&profile={{ profile.pk }}" class="btn btn-submit">{% trans "Confirmer" %}</a>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</section>
{% endif %}
{% endblock %}


Expand Down Expand Up @@ -234,14 +200,6 @@ <h3>{% trans "Actions" %}</h3>
</a>
</li>
{% endif %}
{% if perms.member.change_profile %}
<li>
<a href="#link-tuto-modal" class="open-modal ico-after tick green">
{% trans "Attribuer un tuto SdZ" %}
</a>
{% crispy form %}
</li>
{% endif %}
{% if profile.is_private and not perms.member.change_profile %}
<li class="inactive mobile-menu-link">
<span>{% trans "Aucune action possible" %}</span>
Expand Down Expand Up @@ -295,13 +253,6 @@ <h3>{% trans "Accès rapide" %}</h3>
</a>
</li>
{% endif %}
{% if old_tutos and perms.member.change_profile %}
<li>
<a href="#anciens-tutoriels-sdz">
{% trans "Anciens tutoriels SdZ" %}
</a>
</li>
{% endif %}
</ul>
</div>

Expand Down
30 changes: 1 addition & 29 deletions zds/member/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from crispy_forms.layout import HTML, Layout, \
Submit, Field, ButtonHolder, Hidden, Div

from zds.member.models import Profile, listing, KarmaNote
from zds.member.models import Profile, KarmaNote
from zds.member.validators import ProfileUsernameValidator, ProfileEmailValidator
from zds.utils.forms import CommonLayoutModalText

Expand All @@ -25,34 +25,6 @@
MIN_PASSWORD_LENGTH = 6


class OldTutoForm(forms.Form):
"""
This form to attributes "Old" tutorials to the current user.
"""
id = forms.ChoiceField(
label=_(u'Ancien Tutoriel'),
required=True,
choices=listing(),
)

def __init__(self, profile, *args, **kwargs):
super(OldTutoForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'modal modal-flex'
self.helper.form_id = 'link-tuto-modal'
self.helper.form_method = 'post'
self.helper.form_action = reverse('member-add-oldtuto')

self.helper.layout = Layout(
HTML(_(u'<p>Choisissez un tutoriel du SdZ à attribuer au membre</p>')),
Field('id'),
Hidden('profile_pk', '{{ profile.pk }}'),
ButtonHolder(
StrictButton(_(u'Attribuer'), type='submit'),
),
)


class LoginForm(forms.Form):
"""
The login form, including the "remember me" checkbox.
Expand Down
18 changes: 0 additions & 18 deletions zds/member/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,3 @@ def all_members_ordered_by_date_joined(self):
:rtype: QuerySet
"""
return super(ProfileManager, self).get_queryset().order_by('-user__date_joined').all()

def all_old_tutos_from_site_du_zero(self, profile):
"""
Gets all tutorials from Site du Zéro for a member if exist.
:param profile: the profile of a member
:type profile: QuerySet
:return: A list of tutorials from Site du Zéro for a member if exist.
:rtype: list
"""
from zds.member.models import get_info_old_tuto

if profile.sdz_tutorial:
olds = profile.sdz_tutorial.strip().split(':')
else:
olds = []
old_tutos = [get_info_old_tuto(old) for old in olds]
return old_tutos
53 changes: 0 additions & 53 deletions zds/member/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,56 +524,3 @@ def logout_user(username):
request.session = engine.SessionStore(session.session_key)
logout(request)
break


def listing():
"""
Lists all SdZ tutorials stored on the server at `settings.SDZ_TUTO_DIR` location.
:return: a list of tuples (tutorial ID, path)
"""
# TODO: French here. Improve the method name.
fichier = []
if os.path.isdir(settings.SDZ_TUTO_DIR):
for root in os.listdir(settings.SDZ_TUTO_DIR):
if os.path.isdir(os.path.join(settings.SDZ_TUTO_DIR, root)):
num = root.split('_')[0]
if num is not None and num.isdigit():
fichier.append((num, root))
return fichier
else:
return ()


def get_info_old_tuto(id):
"""
Retrieve data from SdZ tutorials.
:param id: The ID of the SdZ tutorial.
:return: ID, title, tutorial file path, image list file paths, and logo file path of this SdZ tutorial.
"""
# TODO: French here.
titre = ''
tuto = ''
images = ''
logo = ''
if os.path.isdir(settings.SDZ_TUTO_DIR):
for rep in os.listdir(settings.SDZ_TUTO_DIR):
if rep.startswith(str(id) + '_'):
if os.path.isdir(os.path.join(settings.SDZ_TUTO_DIR, rep)):
for root, dirs, files in os.walk(
os.path.join(
settings.SDZ_TUTO_DIR, rep
)):
for file in files:
if file.split('.')[-1] == 'tuto':
titre = os.path.splitext(file)[0]
tuto = os.path.join(root, file)
elif file.split('.')[-1] == 'zip':
images = os.path.join(root, file)
elif file.split('.')[-1] in ['png',
'jpg',
'ico',
'jpeg',
'gif']:
logo = os.path.join(root, file)

return id, titre, tuto, images, logo
22 changes: 0 additions & 22 deletions zds/member/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,25 +1007,3 @@ def tearDown(self):
shutil.rmtree(settings.ZDS_APP['content']['repo_public_path'])
if os.path.isdir(settings.MEDIA_ROOT):
shutil.rmtree(settings.MEDIA_ROOT)

def test_errors_assign_tuto_sdz(self):
"""
To test the errors of assigning a SdZ tutorial.
"""
# we need staff right for assign a tutorial
self.client.logout()
self.client.login(username=self.staff.username, password="hostel77")

# without the parameter "profile_pk" and "id"
result = self.client.post(
reverse('member-add-oldtuto'),
{},
follow=False)
self.assertEqual(result.status_code, 404)

# without the parameter "profile_pk"
result = self.client.post(
reverse('member-add-oldtuto'),
{'id': '1'},
follow=False)
self.assertEqual(result.status_code, 404)
6 changes: 1 addition & 5 deletions zds/member/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.conf.urls import url

from zds.member.views import MemberList, MemberDetail, UpdateMember, UpdateAvatarMember, UpdatePasswordMember, \
UpdateUsernameEmailMember, RegisterView, SendValidationEmailView, add_oldtuto, remove_oldtuto, modify_karma, \
UpdateUsernameEmailMember, RegisterView, SendValidationEmailView, modify_karma, \
modify_profile, settings_mini_profile, member_from_ip, tutorials, articles, settings_promote, login_view, \
logout_view, forgot_password, new_password, active_account, generate_token_account, unregister, warning_unregister

Expand All @@ -20,10 +20,6 @@
url(r'^parametres/compte/$', UpdatePasswordMember.as_view(), name='update-password-member'),
url(r'^parametres/user/$', UpdateUsernameEmailMember.as_view(), name='update-username-email-member'),

# old tuto
url(r'^profil/lier/$', add_oldtuto, name='member-add-oldtuto'),
url(r'^profil/delier/$', remove_oldtuto, name='member-remove-oldtuto'),

# moderation
url(r'^profil/karmatiser/$', modify_karma, name='member-modify-karma'),
url(r'^profil/modifier/(?P<user_pk>\d+)/$', modify_profile, name='member-modify-profile'),
Expand Down
66 changes: 1 addition & 65 deletions zds/member/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from django.utils.http import urlunquote
from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _
from django.utils.datastructures import MultiValueDictKeyError
from django.views.decorators.http import require_POST
from django.views.generic import DetailView, UpdateView, CreateView, FormView

Expand All @@ -33,7 +32,7 @@
from zds.member.decorator import can_write_and_read_now
from zds.member.forms import LoginForm, MiniProfileForm, ProfileForm, RegisterForm, \
ChangePasswordForm, ChangeUserForm, NewPasswordForm, \
OldTutoForm, PromoteMemberForm, KarmaForm, UsernameAndEmailForm
PromoteMemberForm, KarmaForm, UsernameAndEmailForm
from zds.member.models import Profile, TokenForgotPassword, TokenRegister, KarmaNote
from zds.mp.models import PrivatePost, PrivateTopic
from zds.tutorialv2.models.models_database import PublishableContent
Expand Down Expand Up @@ -87,10 +86,8 @@ def get_context_data(self, **kwargs):
context['topics'] = list(Topic.objects.last_topics_of_a_member(usr, self.request.user))
context['articles'] = PublishedContent.objects.last_articles_of_a_member_loaded(usr)
context['tutorials'] = PublishedContent.objects.last_tutorials_of_a_member_loaded(usr)
context['old_tutos'] = Profile.objects.all_old_tutos_from_site_du_zero(profile)
context['karmanotes'] = KarmaNote.objects.filter(user=usr).order_by('-create_at')
context['karmaform'] = KarmaForm(profile)
context['form'] = OldTutoForm(profile)
context['topic_read'] = TopicRead.objects.list_read_topic_pk(self.request.user, context['topics'])
return context

Expand Down Expand Up @@ -894,67 +891,6 @@ def date_to_chart(posts):
return lst


@login_required
@require_POST
def add_oldtuto(request):
try:
identifier = request.POST["id"]
profile_pk = request.POST["profile_pk"]
except MultiValueDictKeyError:
raise Http404

profile = get_object_or_404(Profile, pk=profile_pk)
if profile.sdz_tutorial:
olds = profile.sdz_tutorial.strip().split(":")
else:
olds = []
last = str(identifier)
for old in olds:
last += ":{0}".format(old)
profile.sdz_tutorial = last
profile.save()
messages.success(request,
_(u'Le tutoriel a bien été lié au '
u'membre {0}.').format(profile.user.username))
return redirect(reverse("member-detail",
args=[profile.user.username]))


@login_required
def remove_oldtuto(request):
if "id" in request.GET:
identifier = request.GET["id"]
else:
raise Http404

if "profile" in request.GET:
profile_pk = request.GET["profile"]
else:
raise Http404

profile = get_object_or_404(Profile, pk=profile_pk)
if profile.sdz_tutorial \
or not request.user.has_perm("member.change_profile"):
olds = profile.sdz_tutorial.strip().split(":")
olds.remove(str(identifier))
else:
raise PermissionDenied

last = ""
for i in range(len(olds)):
if i > 0:
last += ":"
last += "{0}".format(str(olds[i]))
profile.sdz_tutorial = last
profile.save()

messages.success(request,
_(u'Le tutoriel a bien été retiré '
u'au membre {0}.').format(profile.user.username))
return redirect(reverse("member-detail",
args=[profile.user.username]))


@login_required
def settings_promote(request, user_pk):
""" Manage the admin right of user. Only super user can access """
Expand Down

0 comments on commit 693463f

Please sign in to comment.