def test_shortcut(self): self.assertEqual(str(L.span('.hello')), '<span class="hello"></span>') self.assertEqual(str(L.span('.hello.world')), '<span class="hello world"></span>') self.assertEqual(str(L.span('#world.hello')), '<span class="hello" id="world"></span>') self.assertEqual(str(L.span('#what')), '<span id="what"></span>')
def test_raise(self): # no children for void tags with self.assertRaises(LysException): L.br / L.p # only str or raw() attributes values with self.assertRaises(LysException): L.button(data_id=123) # invalid shortcuts with self.assertRaises(LysException): L.span('.foo.hello world') with self.assertRaises(LysException): L.span(',hello')
def top_pour_lois(request): results = [] for dossier in Dossier.objects.filter(date_promulgation__isnull=False): c = 0 c = Vote.objects.filter(scrutin_dossier=None, scrutin__etape__dossier=dossier, position='pour').count() c2 = Vote.objects.filter(scrutin_dossier=None, scrutin__etape__dossier=dossier).count() if c2: results.append([dossier, c / c2, c]) else: results.append([dossier, 0, 0]) results.sort(key=lambda r: (-r[1], -r[2])) lines = [] for i, r in enumerate(results): dossier, c, c2 = r lines.append( L.span( ".list-group-item.list-group-item-action.flex-column.align-items-start" ) / f"{i+1}: {dossier} avec {round(c*100, 2)}% de votes pour ({c2} votes)" ) return HttpResponse( template([ L.h2 / "Top des lois promulguées par le pourcentage de votes pour", L.div(".list-group") / lines, ]))
def top_contre_pourcentage(request): results = [] for dep in Depute.objects.all(): c = Vote.objects.filter(scrutin_dossier=None, scrutin__article__isnull=True, depute=dep, position='contre').count() c2 = Vote.objects.filter(scrutin_dossier=None, scrutin__article__isnull=True, depute=dep).count() if c2: results.append([dep, c / c2, c]) else: results.append([dep, 0, 0]) results.sort(key=lambda r: (-r[1], -r[2])) lines = [] for i, r in enumerate(results): dep, c, c2 = r lines.append( L.span( ".list-group-item.list-group-item-action.flex-column.align-items-start" ) / f"{i+1}: {dep} ({dep.groupe}) avec {round(c*100, 2)}% de votes contre ({c2} votes)" ) return HttpResponse( template([ L.h2 / "Top des députés qui ont votés contre les lois promulguées", L.div(".list-group") / lines, ]))
def test_raise(self): # no re-assignement of children with self.assertRaises(LysException): L.h1 / L.a / 'WeLcOmE-HoMe.Com' # no children for void tags with self.assertRaises(LysException): L.br / L.p # only str or raw() attributes values with self.assertRaises(LysException): L.button(data_id=123) # invalid shortcuts with self.assertRaises(LysException): L.span('.foo.hello world') with self.assertRaises(LysException): L.span(',hello')
def depute_scrutin(request, dep_id, scrutin_id): dep = Depute.objects.get(identifiant=dep_id) scrutin = Scrutin.objects.get(id=scrutin_id) return HttpResponse( template([ _render_breadcrumb( [dep, scrutin.dossier, scrutin.etape, scrutin.objet]), L.span('.badge.badge-info') / ( 'Le ', scrutin.date, (' ', scrutin.heure) if scrutin.heure else None, ), ((L.p / L.a(href=scrutin.url_an) / L.button(".btn.btn-info") / "scrutin") if scrutin else None), ]))
def depute_article(request, dep_id, etape_id, article): dep = Depute.objects.get(identifiant=dep_id) etape = Etape.objects.get(identifiant=etape_id) dos = etape.dossier try: scrutin = etape.scrutin_set.filter(article=article).first() except: scrutin = None return HttpResponse( template([ _render_breadcrumb([dep, dos, etape, article]), (L.span('.badge.badge-info') / ( 'Le ', scrutin.date, (' ', scrutin.heure) if scrutin.heure else None, ), ) if scrutin else None, ((L.p / L.a(href=scrutin.url_an) / L.button(".btn.btn-info") / "scrutin") if scrutin else None), ]))
def top_pour(request): results = [] for dep in Depute.objects.all(): c = Vote.objects.filter(scrutin_dossier=None, scrutin__article__isnull=True, depute=dep, position='pour').count() results.append([dep, c]) results.sort(key=lambda r: -r[1]) lines = [] for i, r in enumerate(results): dep, c = r lines.append( L.span( ".list-group-item.list-group-item-action.flex-column.align-items-start" ) / f"{i+1}: {dep} ({dep.groupe}) avec {c} votes pour") return HttpResponse( template([ L.h2 / "Top des députés qui ont votés pour les lois promulguées", L.div(".list-group") / lines, ]))
def depute_etape(request, dep_id, etape_id): dep = Depute.objects.get(identifiant=dep_id) etape = Etape.objects.get(identifiant=etape_id) dos = etape.dossier try: scrutin = etape.scrutin_set.filter(dossier__isnull=True, article__isnull=True).first() except: scrutin = None articles = etape.scrutin_set.values_list( 'article', flat=True).order_by('article').distinct() articles = [a for a in articles if a] articles.sort(key=_sort_articles) scrutins_amendements = etape.scrutin_set.filter(dossier=dos, etape=etape) return HttpResponse( template([ _render_breadcrumb([dep, dos, etape]), (L.span('.badge.badge-info') / ( 'Le ', scrutin.date, (' ', scrutin.heure) if scrutin.heure else None, ), ) if scrutin else None, L.p / (( ' ', L.a(href=scrutin.url_an) / L.button(".btn.btn-info") / f'Scrutin', ( ' ', L.a(href=scrutin.url_video) / L.button(".btn.btn-info") / "video du vote", ) if scrutin.url_video else None, ( ' ', L.a(href=scrutin.url_CR) / L.button(".btn.btn-info") / "compte-rendu", ) if scrutin.url_CR else None, ) if scrutin else None), (L.h2 / ["Articles", L.small(".text-muted") / " votés"], L.div(".list-group") / [ L. a(".list-group-item.list-group-item-action.flex-column.align-items-start", href="/" + dep.identifiant + "/etape/" + etape.identifiant + "/article/" + article) / [ L.div(".d-flex.w-100.justify-content-between") / [ L.h5(".mb-1") / f"Article {article}", _display_article_vote(etape, dep, article), ] ] for article in articles ]) if articles else None, (L.br, L.br, L.h2 / [ "Amendements et motions", L.small(".text-muted") / " votés" ], L.div(".list-group") / [ L. a(".list-group-item.list-group-item-action.flex-column.align-items-start", href="/" + dep.identifiant + "/scrutin/" + str(amdt_scrutin.id)) / [ L.div(".d-flex.w-100.justify-content-between") / [ L.h5(".mb-1") / f"{amdt_scrutin.objet}", _display_scrutin_vote(dep, amdt_scrutin), ] ] for amdt_scrutin in scrutins_amendements ]) if scrutins_amendements.count() else None, ]))