From a9318f7fd31eed8fa14d08a92277ba795efbb36c Mon Sep 17 00:00:00 2001 From: tr4ck3ur Date: Sun, 15 Feb 2015 18:10:48 +0100 Subject: Corrigé les images Ajouté la gestion de password Corrigé le slug des users à la création MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jm2l/__init__.py | 3 ++- jm2l/forms.py | 14 ++++++++++--- jm2l/static/css/jm2l.css | 7 ++++--- jm2l/static/js/jm2l.js | 17 ---------------- jm2l/static/js/plugins.js | 37 +++++++++++++++++++++++++++++++++++ jm2l/templates/Profil/Profil.mako | 37 +++-------------------------------- jm2l/templates/helpers.mako | 41 +++++++++++++++++++++++++++++++++++++-- jm2l/templates/layout.mako | 37 +++-------------------------------- jm2l/templates/modals.mako | 34 +++++++------------------------- jm2l/templates/modals_js.mako | 11 +++++++++++ jm2l/views.py | 21 ++++++++++++++++++-- 11 files changed, 136 insertions(+), 123 deletions(-) diff --git a/jm2l/__init__.py b/jm2l/__init__.py index c4ba2be..f5f3378 100644 --- a/jm2l/__init__.py +++ b/jm2l/__init__.py @@ -9,10 +9,10 @@ from .models import DBSession, get_user from .security import EntryFactory, groupfinder import locale - def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ + locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8") engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) @@ -82,6 +82,7 @@ def main(global_config, **settings): config.add_route('edit_entity_cat', '/categorie/entity') ## Users + config.add_route('pict_user', '/user_picture') config.add_route('show_user', '/user/{user_slug:([\w-]+)?}') # HTML Routes - Logged diff --git a/jm2l/forms.py b/jm2l/forms.py index 010cf28..acb60f1 100644 --- a/jm2l/forms.py +++ b/jm2l/forms.py @@ -1,5 +1,6 @@ # -*- coding: utf8 -*- -from wtforms import Form, BooleanField, TextField, TextAreaField, SelectField, SubmitField, validators, FieldList +from wtforms import Form, BooleanField, TextField, TextAreaField, SelectField +from wtforms import SubmitField, validators, FieldList, PasswordField #import .ExtWforms from .ExtWtforms import MySelectField from wtforms import HiddenField, DecimalField, DateTimeField, FormField, FileField, DateField @@ -181,8 +182,15 @@ def captcha_check(form, field): if form.meta.csrf_context.get('Captcha')!=field.data: raise ValidationError(u"la vérification captcha est invalide.") - - +class UserPasswordForm(MyBaseForm): + uid = HiddenField() + password = PasswordField("Mot de passe",[ + validators.Length(max=128, message=u"128 car. maximum"), + validators.required(message=u"Ce champ est obligatoire"), + validators.EqualTo('confirm', message=u'Les password ne sont pas équivalents') ], + filters=[strip_filter] + ) + confirm = PasswordField('Confirmez') class UserRegisterForm(MyBaseForm): nom = TextField(u'Nom', [ diff --git a/jm2l/static/css/jm2l.css b/jm2l/static/css/jm2l.css index de94fbf..016073c 100644 --- a/jm2l/static/css/jm2l.css +++ b/jm2l/static/css/jm2l.css @@ -44,13 +44,13 @@ a { height:100px; } .invalid { - background:url(../images/invalid.png) no-repeat 0 50%; + background:url(/img/invalid.png) no-repeat 0 50%; padding-left:22px; line-height:24px; color:#ec3f41; } .valid { - background:url(../images/valid.png) no-repeat 0 50%; + background:url(/img/valid.png) no-repeat 0 50%; padding-left:22px; line-height:24px; color:#3aba34; @@ -84,7 +84,8 @@ a { opacity: 0.5; position: absolute; text-align: center; - width: 15px; + width: 15px; + top: -20px; } .Ucarousel-control.left { right: auto; diff --git a/jm2l/static/js/jm2l.js b/jm2l/static/js/jm2l.js index e24c7d0..a700c4a 100644 --- a/jm2l/static/js/jm2l.js +++ b/jm2l/static/js/jm2l.js @@ -1,4 +1,3 @@ - function DoPost(TargetURL) { var Datas=$('#ModalForm').serialize(); $.ajax({ @@ -83,7 +82,6 @@ $(document).ready(function() { }); $('#AjaxModal').on('hidden', function(bla){ - //$(this).data('modal', null); if (bla.target.id.endsWith('-help')) return; if (bla.target.id=='AjaxModal') { @@ -98,7 +96,6 @@ $(document).ready(function() { $('#AjaxPlaceModal').on('hidden', function(bla){ $("#place_type").select2("destroy"); - //$(this).data('modal', null); if (bla.target.id.endsWith('-help')) return; if ($(this).children().length) @@ -152,20 +149,6 @@ $(document).ready(function() { $('a[href="' + SavHash + '"]').tab('show'); } } - - - if (0) { - var editor = CKEDITOR.replace( 'bio', { - saveSubmitURL:'/SaveFrontPage/?part=bio', - on : { blur: function( event ) { event.editor.getCommand( 'save' ).enable(); } - } - } ); - } else { - //CKEDITOR.disableAutoInline = true; - //var editor = CKEDITOR.inline( 'bio' ); - //var editor = CKEDITOR.replace( 'bio' ); - //var editor = CKEDITOR.replace( 'bio' ); - }; jQuery(function() { jQuery('.repeat').each(function() { diff --git a/jm2l/static/js/plugins.js b/jm2l/static/js/plugins.js index f887480..78eecbf 100644 --- a/jm2l/static/js/plugins.js +++ b/jm2l/static/js/plugins.js @@ -22,3 +22,40 @@ }()); // Place any jQuery/helper plugins in here. +function HandleControls() { +// Trig some javascript to handle New Dialog content + $.each( $('.fileupload'), + function( NumCtrl, Ctrl ) { + $("#"+Ctrl.id).fileupload({ + // Uncomment the following to send cross-domain cookies: + //xhrFields: {withCredentials: true}, + //url: '/uploader/proceed/' + url: this.action + }); + // Enable iframe cross-domain access via redirect option: + $("#"+Ctrl.id).fileupload( + 'option', + 'redirect', + window.location.href.replace( + /\/[^\/]*$/, + '/cors/result.html?%s' + ) + ); + $("#"+Ctrl.id).addClass('fileupload-processing'); + $.ajax({ + // Uncomment the following to send cross-domain cookies: + //xhrFields: {withCredentials: true}, + //url: this.action, + url: $("#"+Ctrl.id).fileupload('option', 'url'), + //url: "uploader/proceed/", + dataType: 'json', + context: $("#"+Ctrl.id)[0] + }).always(function () { + $(this).removeClass('fileupload-processing'); + }).done(function (result) { + $(this).fileupload('option', 'done') + .call(this, $.Event('done'), {result: result}); //$(this)}); + }); + } + ); +} \ No newline at end of file diff --git a/jm2l/templates/Profil/Profil.mako b/jm2l/templates/Profil/Profil.mako index 4a20282..f8dc229 100644 --- a/jm2l/templates/Profil/Profil.mako +++ b/jm2l/templates/Profil/Profil.mako @@ -1,40 +1,9 @@ <%namespace name="Modals" file="jm2l:templates/modals.mako"/> <%namespace name="helpers" file="jm2l:templates/helpers.mako"/> <%def name="profil_wrapper(uprofil, profil_form)"> -
- <% photos = uprofil.PhotosLinks %> - -
+
+ ${helpers.show_my_pictures(uprofil)} +
Mon lien

${profil_form.prenom.data} ${profil_form.nom.data}

diff --git a/jm2l/templates/helpers.mako b/jm2l/templates/helpers.mako index 5987a90..b1409b8 100644 --- a/jm2l/templates/helpers.mako +++ b/jm2l/templates/helpers.mako @@ -159,7 +159,7 @@ TabJs = {'select':[], 'desc':[]}
-
+
 
@@ -184,7 +184,7 @@ TabJs = {'select':[], 'desc':[]}

{%=file.name%}

Processing...

-
+
{% if (!i && !o.options.autoUpload) { %} @@ -395,6 +395,43 @@ plop ## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ## Wrapper pour les photos ## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +<%def name="show_my_pictures(uprofil)"> \ +
+ <% photos = uprofil.PhotosLinks %> +
+ Changer mon mot de passe +
+
+ Changer ma photo +
+ +
+ \ +## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <%def name="show_pictures(uprofil)"> \
<% photos = uprofil.PhotosLinks %> diff --git a/jm2l/templates/layout.mako b/jm2l/templates/layout.mako index 64b60a8..415b5a3 100644 --- a/jm2l/templates/layout.mako +++ b/jm2l/templates/layout.mako @@ -113,46 +113,15 @@ ${helpers.uploader_js()} + ${self.jsAddOn()} ## Then Handle Javascript diff --git a/jm2l/templates/modals.mako b/jm2l/templates/modals.mako index 6ee1556..5848be6 100644 --- a/jm2l/templates/modals.mako +++ b/jm2l/templates/modals.mako @@ -150,11 +150,10 @@ Les images de taille supérieure à 300x300 pixels seront redimensionnés.
${helpers.uploader("users", uid, "une Photo")} - ##${helpers.uploader_js()}
\ @@ -166,33 +165,12 @@

Changer mon mot de passe

\ @@ -284,4 +263,5 @@ context._kwargs['postpone_js']=[] % for jsitem in context._kwargs['postpone_js']: ${jsitem | n} % endfor +HandleControls(); diff --git a/jm2l/templates/modals_js.mako b/jm2l/templates/modals_js.mako index 6afb826..9e1395d 100644 --- a/jm2l/templates/modals_js.mako +++ b/jm2l/templates/modals_js.mako @@ -63,4 +63,15 @@ $.ajax({ alert(error); }, }); +% elif modtype=='UserPicture': +$.ajax({ + url:'/user_picture', + success:function(result, status, jqXHR){ + var pictureresult = $('
').append(result).find('#MyPictureCarousel').html(); + $('#MyPictureCarousel').html(pictureresult); + }, + error:function(result, error){ + alert(error); + }, +}); % endif diff --git a/jm2l/views.py b/jm2l/views.py index cd7586e..b0be0e0 100644 --- a/jm2l/views.py +++ b/jm2l/views.py @@ -348,7 +348,6 @@ def action_task(request): ## =-=- Here, We handle HTTP requests - User Logged Part -=-= - @view_config(route_name='exchange', renderer="jm2l:templates/Logistique/Logistique.mako") def exchange(request): modtype = request.matchdict.get('modtype', None) @@ -454,8 +453,22 @@ def Modal(request): modtype = request.matchdict.get('modtype', None) uid = int(request.matchdict.get('id', -1)) session = request.session + if modtype=='Password': + form = UserPasswordForm(request.POST, request.user, meta={'csrf_context': request.session}) + if request.method == 'POST' and form.validate(): + response = render_to_response('jm2l:templates/modals_js.mako', + {'modtype':modtype}, + request=request) + response.content_type = 'text/javascript' + return response if modtype=='UserPicture': form = None + if request.method == 'POST': + response = render_to_response('jm2l:templates/modals_js.mako', + {'modtype':modtype}, + request=request) + response.content_type = 'text/javascript' + return response if modtype=='Place': if uid>0: place = Place.by_id(uid) @@ -622,7 +635,7 @@ def participer(request): form.populate_obj(TmpUsr) TmpUsr.nom = TmpUsr.nom.capitalize() TmpUsr.prenom = TmpUsr.prenom.capitalize() - TmpUsr.slug = slugify(remove_accents('%s %s' % (form.prenom, form.nom)).lower().strip()) + TmpUsr.slug = slugify(remove_accents('%s %s' % (form.prenom.data, form.nom.data)).lower().strip()) TmpUsr.password = TmpUsr.my_hash if len(TmpUsr.slug): CheckExist = DBSession.query(User)\ @@ -650,6 +663,10 @@ def change_year(request): return HTTPFound(location='/%s/le-programme' % year) return HTTPFound(location=request.route_url('home')) +@view_config(route_name='pict_user', renderer="jm2l:templates/Profil/pict_user.mako") +def pict_user(request): + return {"uprofil":request.user} + @view_config(route_name='event', renderer="jm2l:templates/view_event.mako") def show_event(request): year = int(request.matchdict.get('year', -1)) -- cgit v1.2.3-70-g09d2