From a1955fd27f5bb2d46a032bfd84b2924b0f4b6e0b Mon Sep 17 00:00:00 2001 From: tr4ck3ur Date: Wed, 18 Nov 2015 13:45:33 +0100 Subject: [PATCH] Added wifi identifiers --- jm2l/__init__.py | 2 + jm2l/badge.py | 84 ------------------- jm2l/models.py | 4 + jm2l/static/img/wifi.png | Bin 0 -> 3361 bytes jm2l/templates/Profil/Profil.mako | 17 +++- jm2l/to_print.py | 135 ++++++++++++++++++++++++++++++ jm2l/views.py | 43 +++++++++- 7 files changed, 197 insertions(+), 88 deletions(-) create mode 100644 jm2l/static/img/wifi.png create mode 100644 jm2l/to_print.py diff --git a/jm2l/__init__.py b/jm2l/__init__.py index 1e04d5d..6769e3d 100644 --- a/jm2l/__init__.py +++ b/jm2l/__init__.py @@ -95,6 +95,7 @@ def main(global_config, **settings): # ICal Routes config.add_route('progr_iCal', '/{year:\d+}/JM2L.ics') + config.add_route('progr_dyn_iCal', '/{year:\d+}/JM2L_dyn.ics') # JSON Routes config.add_route('users_json', '/json-users') @@ -154,6 +155,7 @@ def main(global_config, **settings): config.add_route('show_user', '/user/{user_slug:([\w-]+)?}') config.add_route('badge_user', '/user/{user_slug:([\w-]+)?}/badge') config.add_route('all_badges', '/badges') + config.add_route('place_print', '/place_print') # HTML Routes - Logged #config.add_route('profil', 'MesJM2L') diff --git a/jm2l/badge.py b/jm2l/badge.py index 7c9c06c..c4e723d 100644 --- a/jm2l/badge.py +++ b/jm2l/badge.py @@ -17,90 +17,6 @@ WIDTH = 85 * mm HEIGHT = 60 * mm ICONSIZE = 10 * mm -def Ribbon35(DispUser, canvas): - canvas.saveState() - canvas.rotate(35) - offset_u=0 - if DispUser.Staff: - # Staff - canvas.setFillColorRGB(1,.2,.2) - canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) - canvas.setFillColorRGB(1,1,1) - canvas.setFont('Liberation', 20) - canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF") - elif DispUser.is_Intervenant: - # Intervenant - canvas.setFillColorRGB(.3,.3,1) - canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) - canvas.setFillColorRGB(1,1,1) - canvas.setFont('Liberation', 15) - canvas.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant") - else: - # Visiteur - canvas.setFillColorRGB(.8,.8,.8) - canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) - canvas.setFillColorRGB(0,0,0) - canvas.setFont('Liberation', 12) - canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur") - canvas.restoreState() - return canvas - -def Ribbon45(DispUser, canvas): - canvas.saveState() - canvas.rotate(45) - offset_u=0 - if DispUser.Staff: - # Staff - canvas.setFillColorRGB(1,.2,.2) - canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) - canvas.setFillColorRGB(1,1,1) - canvas.setFont('Liberation', 20) - canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF") - elif DispUser.is_Intervenant: - # Intervenant - canvas.setFillColorRGB(.3,.3,1) - canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) - canvas.setFillColorRGB(1,1,1) - canvas.setFont('Liberation', 15) - canvas.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant") - else: - # Visiteur - canvas.setFillColorRGB(.8,.8,.8) - canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) - canvas.setFillColorRGB(0,0,0) - canvas.setFont('Liberation', 12) - canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur") - canvas.restoreState() - return canvas - -def Ribbon90(DispUser, canvas): - canvas.saveState() - canvas.rotate(90) - offset_u=0 - if DispUser.Staff: - # Staff - canvas.setFillColorRGB(1,.2,.2) - canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) - canvas.setFillColorRGB(1,1,1) - canvas.setFont('Liberation', 20) - canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF") - elif DispUser.is_Intervenant: - # Intervenant - canvas.setFillColorRGB(.3,.3,1) - canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) - canvas.setFillColorRGB(1,1,1) - canvas.setFont('Liberation', 15) - canvas.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant") - else: - # Visiteur - canvas.setFillColorRGB(.8,.8,.8) - canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) - canvas.setFillColorRGB(0,0,0) - canvas.setFont('Liberation', 12) - canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur") - canvas.restoreState() - return canvas - def JM2L_Logo(canvas, Offset=(0,0)): OffX, OffY = Offset logoobject = canvas.beginText() diff --git a/jm2l/models.py b/jm2l/models.py index 77b4a02..e573454 100644 --- a/jm2l/models.py +++ b/jm2l/models.py @@ -137,6 +137,10 @@ class User(Base): soc_link = Column(UnicodeText) Staff = Column(Integer, default=0) vote_logo = Column(Integer, default=0) + + wifi_user = Column(Unicode(80), nullable=True) + wifi_pass = Column(Unicode(80), nullable=True) + # relations tiers = relationship('Tiers', secondary='user_tiers_link' ) events = relationship('Event', secondary='user_event_link' ) diff --git a/jm2l/static/img/wifi.png b/jm2l/static/img/wifi.png new file mode 100644 index 0000000000000000000000000000000000000000..2f0c280c12ba36ec936933235dfdb1f80b0959e0 GIT binary patch literal 3361 zcmV++4c_vJP)vYcwGc2Mgcp`2=MIvg{5r`Q@Kv6L+Nj!ovxL|;j7^5C@ zg3$v4iV7MdF2QI7L_}oK7(_spU=)=>L{vn;nOOXMdhl>e{La|JsBJt z=gOyQ@}k=_`Z2FNEwI&a+d~cx{Yo_4wO_ln${pwD9StWyvQSm=(z<*`0{|fE1H!@A zp77B9^@s@F(VWILO~HOe&jmm#%2wY)NM?w8Z>x7O@b+k@uPleD5jrl=a`2gx8@s}_ z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K0Y$qljG1qY1+=(%o~R-sv4@T;6S(RV$L|!7B}I;IdW^7vbI(xXZMeR)k-AlaS20qVHN( z=-KAzn1@6XW$Tg%D=o%3kf>>eS83YuZzNJf7qsqHv3$t((C=v+5iDChOGJdU>3>_J zk*lv4*pX^b;S^&q&j?>$$SNcNc;S_X}{XKJKVNX1PiDX3rZwe4*-zS`z<97 z`jf~d0iN{AhA|ga~C~5Q8yj`oz*yU#lO(+k&@_-`mn+U+er4S-b8#q~2 z8|De$fO4zO>~Jr&R4vrX0&8yedm1Mr8poB0EmhM_yhBxoKh+t8(zfi{eQ=kF3gNP~ zf1vWd213%qI>GgKrc-B6Nu>ub13@7&AKYnSiKle9OK3r;Y|U+o{Pl1mCC)>EGO{2! zVSyEq_~oNav&xi8fOd!K%&|i!;2sLDo#6HC9xh4h1tLEYiP&tKwX>U|S5N86DyogS zp#|a4%Db5rY__bLNXG2_0?Tup5;Vc%`Sfy1zv)G#Se-=Dbx5>c1k)!LM?Bo1t?Wo= zPW^Ktb@oExa1(|5=KboS>lh>ry=rn*8j`dtG6-fE(WpZ-dv;@i0|2O-X7!Wt_!W~( z=Izpd-UEAeh5$ggQ)>He6q)v%+p{g59y&dhIsN5gl$nyD&bxC1#bDi-(T|=VOI$Qd z>TnCKxLC=AOrA5-fXZ~ow3J_&>1w#s9IF|2p1`$7GV{J~ zm^G{8sk7cPjJj14x9waf(@JOHPIJ7y_}Wp)y>Miy59dQ rUGKfzE=~yVlHe7wuDFuY0{8y|wX1vLChHFC00000NkvXXu0mjfDsp#4 literal 0 HcmV?d00001 diff --git a/jm2l/templates/Profil/Profil.mako b/jm2l/templates/Profil/Profil.mako index ec3060c..3f9e76c 100644 --- a/jm2l/templates/Profil/Profil.mako +++ b/jm2l/templates/Profil/Profil.mako @@ -13,7 +13,7 @@
Mon lien de connection - Mon profil public
-

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

+

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

<% DicFormA = { 'nom': {'PlaceHolder':u"Mon Nom", 'ContainerClass':"span6", 'next':False}, @@ -61,7 +61,22 @@ DicForm2 = { ${helpers.DisplayRespForm(profil_form, DicFormA)}
+ ${helpers.show_my_pictures(uprofil)} + +
+ Vos identifiants wifi: +
+
SSID
+
Unice-HotSpot
+
Votre utilisateur:
+
${uprofil.wifi_user}
+
Le mot de passe:
+
${uprofil.wifi_pass}
+
+ Plus de détails ... +
+
diff --git a/jm2l/to_print.py b/jm2l/to_print.py new file mode 100644 index 0000000..740080d --- /dev/null +++ b/jm2l/to_print.py @@ -0,0 +1,135 @@ +# -*- coding: utf8 -*- +from pyramid.response import Response +import cStringIO as StringIO +from pyramid.view import view_config +from .models import DBSession, Event, Salles +from reportlab.pdfgen import canvas +from reportlab.pdfbase import pdfmetrics +from reportlab.pdfbase.ttfonts import TTFont +from reportlab.lib.units import mm +from .upload import MediaPath + +CurrentYear = 2015 +# Create PDF container +EXPIRATION_TIME = 300 # seconds +WIDTH = 210 * mm +HEIGHT = 297 * mm +ICONSIZE = 10 * mm + + +def JM2L_large_Logo(canvas, Offset=(0,0)): + OffX, OffY = Offset + + canvas.setFont('Logo', 110) + canvas.setFillColorRGB(.83,0,.33) + canvas.drawCentredString(WIDTH/2-OffY, HEIGHT-100-OffX, "JM2L") + + canvas.setFont("Helvetica-Bold", 30) + yearobject = canvas.beginText() + yearobject.setFillColorRGB(1,1,1) + yearobject.setTextRenderMode(0) + yearobject.setTextOrigin(WIDTH/2-OffY-120, HEIGHT-36-OffX) + yearobject.setWordSpace(48) + yearobject.textLines("2 0 1 5") + yearobject.setWordSpace(1) + canvas.drawText(yearobject) + + +def one_time_step(canvas, str, hour, max_size, offset): + max_x, max_y = max_size + off_x, off_y = offset + step_y = max_y/9 + half_step = step_y/2 + canvas.drawCentredString(off_x-30, max_y-step_y*hour+off_y-3, str) + hour_place = step_y*hour+off_y + canvas.line(off_x-5, hour_place, off_x, hour_place) + if hour<9: + canvas.line(off_x-2, hour_place+half_step, off_x, hour_place+half_step) + +@view_config(route_name='place_print', http_cache = (EXPIRATION_TIME, {'public':True})) +def place_print(request): + # Ok let's generate a print for place schedule + + # Register LiberationMono font + ttfFile = "jm2l/static/fonts/LiberationMono-Regular.ttf" + pdfmetrics.registerFont(TTFont("Liberation", ttfFile)) + # Import font + ttfFile_Logo = "jm2l/static/fonts/PWTinselLetters.ttf" + pdfmetrics.registerFont(TTFont("Logo", ttfFile_Logo)) + + pdf = StringIO.StringIO() + + c = canvas.Canvas( pdf, pagesize=(WIDTH, HEIGHT) ) + c.translate(mm, mm) + + # Feed some metadata + c.setCreator("linux-azur.org") + c.setTitle("Planning Salle") + + c.saveState() + + year = int(request.matchdict.get('year', CurrentYear)) + # Initialization + # Compute days used by all events matching the specified input year + place_used = DBSession.query(Event.salle_uid)\ + .filter(Event.for_year == year)\ + .filter(Event.event_type != 'Stand')\ + .group_by(Event.salle_uid) + + for place in place_used: + place_uid = place[0] + place_obj = Salles.by_id(place_uid) + # Logo on Top + JM2L_large_Logo(c) + max_size = (WIDTH-110, HEIGHT-300) + offset = (70, 90) + c.setFillColorRGB(.5,.5,.5) + c.setFont('Liberation', 40) + c.drawCentredString(WIDTH/2, HEIGHT-190, place_obj.name, 1) + c.setFont('Liberation', 35) + c.drawCentredString(WIDTH/2, HEIGHT-145, place_obj.place_type, 0 ) + c.setFont('Helvetica', 20) + c.drawCentredString(WIDTH/2, 55, place_obj.phy.name, 0) + + # Timetable container + c.setLineWidth(.1) + c.setLineCap(2) + #c.setFillColorRGB(0,0,1) + c.rect(offset[0], offset[1], max_size[0], max_size[1], fill=0, stroke=1) + c.setLineWidth(.5) + # create time mark + c.setFillColorRGB(0,0,0) + c.setFont('Helvetica', 10) + for i in range(0,10): + one_time_step(c, "%.2dh00" % (i+10), i, max_size, offset) + + c.setFont('Helvetica', 12) + Events = DBSession.query(Event)\ + .filter(Event.for_year == year)\ + .filter(Event.salle_uid == place_uid)\ + .order_by(Event.start_time) + for ev in Events: + place_time(c, ev, max_size, offset) + #c.rect(70, 50, WIDTH-100, HEIGHT-250, fill=0, stroke=1) + c.showPage() + + c.save() + pdf.seek(0) + + return Response(app_iter=pdf, content_type = 'application/pdf' ) + +def place_time(c, ev, max_size, offset): + max_x, max_y = max_size + off_x, off_y = offset + minute = max_y/(9*60) + start_pos_y = ((int( ev.start_time.strftime('%H') )-10)*60 + int( ev.start_time.strftime('%M') )) * minute + stop_pos_y = ((int( ev.end_time.strftime('%H') )-10)*60 + int( ev.end_time.strftime('%M') )) * minute + + c.setFillColorRGB(1,1,1) + c.rect(offset[0], max_y + off_y - start_pos_y, max_size[0], start_pos_y-stop_pos_y, fill=1, stroke=1) + c.setFillColorRGB(0,0,0) + #c.drawString(off_x+5, max_y + off_y - 15 - start_pos_y, ev.start_time.strftime('%H:%M'), 0) + c.drawCentredString(WIDTH/2, max_y + off_y - 35 - start_pos_y, ev.name, 0) + intervs = ','.join( [x.slug for x in ev.intervenants] ) + c.drawString(WIDTH/2, max_y + off_y - 45 - start_pos_y, intervs, 0) + \ No newline at end of file diff --git a/jm2l/views.py b/jm2l/views.py index cb27b4f..4bfd7ee 100644 --- a/jm2l/views.py +++ b/jm2l/views.py @@ -73,6 +73,43 @@ def ICal_Progamme_Request(request): request.response.content_type = "text/calendar" return cal.to_ical() +## =-=- Here, We handle ICal requests -=-= +@view_config(route_name='progr_dyn_iCal', renderer="string") +def ICal_Progamme_Dyn_Request(request): + year = int(request.matchdict.get('year', CurrentYear)) + # Initialization + # Compute days used by all events matching the specified input year + Events = DBSession.query(Event)\ + .filter(Event.for_year == year)\ + .filter(Event.event_type != 'Stand')\ + .order_by(Event.start_time) + + cal = Calendar() + cal.add('prodid', '-//Programme %d//jm2l.linux-azur.org//' % year) + cal.add('version', '2.0') + today = datetime.datetime.now() + tz = timezone('Europe/Paris') + for i, ev in enumerate(Events): + if ev.event_type: + event = Evt() + event['uid'] = "%d/%d" % ( year, ev.uid ) + event.add('summary', ev.name +'_night' ) + event.add('dtstart', ev.start_time.replace(tzinfo=tz, day=today.day, month = today.month, hour=(ev.start_time.hour)%24) ) + event.add('dtend', ev.end_time.replace(tzinfo=tz, day=today.day, month = today.month, hour=(ev.end_time.hour)%24) ) + event.add('created', ev.last_change.replace(tzinfo=tz) ) + if i%2: + event.add('description', "http://video.webmfiles.org/big-buck-bunny_trailer.webm" ) + else: + event.add('description', "http://video.webmfiles.org/elephants-dream.webm" ) + event.add('location', "http://jm2l.linux-azur.org/image/tasks/89/le-projet-de-learning-centre-sophiatech-32-638.jpg" ) + event.add('url', "http://www.linux-azur.org/event/%s/%s" % (ev.for_year, ev.slug) ) + event.add('salle', "%s" % (ev.Salle.name) ) + event.add('priority', 5) + cal.add_component(event) + request.response.content_type = "text/calendar" + return cal.to_ical() + + ## =-=- Here, We handle Json requests -=-= @view_config(route_name='users_json', renderer="json") def JSON_User_Request(request): @@ -213,9 +250,9 @@ def JSON_TimeLine_Request(request): "text":"9ème Édition", "asset": { - "media":"https://www.youtube.com/watch?v=DnfjrxVoLao", - "credit":"JM2L", - "caption":"" + "media":"https://www.youtube.com/watch?v=91X65eEKxvU&t=6s", + "credit":"Polytech nice sophia", + "caption":"JM2L 2015" } } elif year==2011: