Example #1
0
def depute(request, dep_id):
    dep = Depute.objects.get(identifiant=dep_id)
    dossiers = Dossier.objects.filter(
        date_promulgation__isnull=False).order_by("-date_promulgation",
                                                  "titre")
    return HttpResponse(
        template([
            _render_breadcrumb([dep]), L.p / (
                L.a(href=dep.url() + "/lois-en-cours") /
                L.button(".btn.btn-warning") / "voir lois en cours",
                ' ',
                L.a(href=dep.url() + "/autres-votes") /
                L.button(".btn.btn-warning") / "voir autres votes",
            ), L.h2 / ["Lois", L.small(".text-muted") / " promulguées"],
            L.div(".list-group") / [
                L.
                a(".list-group-item.list-group-item-action.flex-column.align-items-start",
                  href=dos.url(dep)) / [
                      L.div(".d-flex.w-100.justify-content-between") / [
                          L.h5(".mb-1") / dos.titre,
                          _display_depute_vote(dos, dep),
                      ]
                  ] for dos in dossiers
            ]
        ]))
Example #2
0
    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')
Example #3
0
def homepage(request):
    deputes = Depute.objects.filter(actif=True).order_by(
        Lower('nom'), 'prenom')
    return HttpResponse(
        template([
            raw("""
		<div class="alert alert-dismissible alert-info">
		  <p>Ce site permet de retrouver facilement les votes de vos députés</p>
		  <p>Vous pouvez trouver votre député par circonscription sur
		  	 <a href="https://www.nosdeputes.fr/circonscription" class="alert-link">NosDéputés.fr</a></p>
		</div>
		"""),
            L.p / L.a(href="/deputes/inactifs") /
            L.button(".btn.btn-warning") / "voir députés inactifs",
            L.h2 / ["Députés ", L.small(".text-muted") / " actifs"],
            L.div(".list-group") / [
                L.
                a(".list-group-item.list-group-item-action.flex-column.align-items-start",
                  href=dep.url()) / [
                      L.div(".d-flex.w-100.justify-content-between") / [
                          L.h5(".mb-1") / f"{dep.nom}, {dep.prenom}",
                          L.small / f"{dep.groupe}"
                      ]
                  ] for dep in deputes
            ],
        ]))
Example #4
0
    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')
Example #5
0
 def test_escaping(self):
     self.assertEqual(str(L.div(id='hello & ; " \'')),
                      '<div id="hello &amp; ; &quot; &#x27;"></div>')
     self.assertEqual(
         str(L.h1 / '<script>alert("h4x0r")</script>'),
         '<h1>&lt;script&gt;alert(&quot;h4x0r&quot;)&lt;/script&gt;</h1>')
     self.assertEqual(
         str(L.button(onclick=raw('alert(\'follow the rabbit\')'))),
         '<button onclick="alert(\'follow the rabbit\')"></button>')
Example #6
0
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),
        ]))
Example #7
0
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),
        ]))
Example #8
0
def depute_dossier(request, dep_id, dos_id):
    dep = Depute.objects.get(identifiant=dep_id)
    dos = Dossier.objects.get(identifiant=dos_id)
    etapes = Etape.objects.filter(dossier=dos).order_by("-date")
    return HttpResponse(
        template([
            _render_breadcrumb([dep, dos]), L.p / L.a(href=dos.url_an()) /
            L.button(".btn.btn-info") / "dossier législatif", L.h2 / [
                "Étapes",
            ],
            L.div(".list-group") / [
                L.
                a(".list-group-item.list-group-item-action.flex-column.align-items-start",
                  href=etape.url(dep)) / [
                      L.div(".d-flex.w-100.justify-content-between") / [
                          L.h5(".mb-1") / etape.titre,
                          _display_etape_vote(etape, dep),
                      ]
                  ] for etape in etapes
            ]
        ]))
Example #9
0
def index(request):
    email = None
    message = None

    if 'token' in request.GET:
        try:
            token = LoginToken.objects.get(email=request.GET['email'], token=request.GET['token'])
            email = token.email
        except LoginToken.DoesNotExist:
            pass

    if email: # logged in
        account = Account.objects.get(email=email)

        if request.method == 'POST':
            # todo: atomize / transaction
            # todo: validate email
            dest_email = request.POST['email']
            dest_amount = -1
            message = 'invalid amount'
            try:
                dest_amount = int(request.POST['amount'])
            except ValueError:
                pass
            optional_message = ''
            if request.POST['message']:
                optional_message = '\nHis message: \n' + slugify(request.POST['message'][:140], allow_unicode=True)
            if account.amount >= dest_amount and dest_amount > 0: # TODO: else "not enough founds"
                try:
                    dest_account = Account.objects.get(email=dest_email)
                    dest_account.amount += dest_amount
                    dest_account.save()
                except Account.DoesNotExist:
                    dest_account = Account.objects.create(email=dest_email, amount=dest_amount)

                token = get_random_string()
                LoginToken.objects.create(email=dest_email, token=token, expire_on=datetime.date.today() + datetime.timedelta(days=1))

                send_mail('[petals] %s sent you %d petals' % (email, dest_amount), """%s sent you %d petals.%s
You current balance is now: %d petals

http://petal.x.dam.io/?token=%s&email=%s
""" % (email, dest_amount, optional_message, dest_account.amount, token, dest_email), '*****@*****.**', [dest_email], fail_silently=False)
                account.amount -= dest_amount
                account.save()
                message = '%d sent' % dest_amount
    else:
        if request.method == 'POST':
            email = request.POST['email']
            try:
                account = Account.objects.get(email=email)
                token = get_random_string()
                LoginToken.objects.create(email=email, token=token, expire_on=datetime.date.today() + datetime.timedelta(days=1))
                send_mail('[petals] link to connect to your account', """Here is a temporary link to connect to your account:
http://petal.x.dam.io/?token=%s&email=%s
""" % (token, email), '*****@*****.**', [email], fail_silently=False)
                message = 'connection link sent to %s' % email
            except Account.DoesNotExist:
                pass
        email = None # lol

    total = sum([account.amount for account in Account.objects.all()])

    content = L.div('.container') / (
        L.div('.row') / (
            L.div('.col-sm-12') / (
                L.h3 / (L.a(href='/') / 'Petal'),
                L.strong / ('%d petals in circulation' % total),
                L.hr,
            ),
        ),
        (
            L.div('.row') / (
                L.div('.col-sm-3') / (
                    L.h3 / email,
                    L.p / ('You have %d petals' % account.amount),
                    L.h4 / 'send petals',
                    L.form(method='post') / (
                        L.input(type='hidden', name='csrfmiddlewaretoken', value=get_token(request)),
                        L.div / (
                            L.label('control-label') / 'email', L.br, L.input(name='email'),
                        ),
                        L.div / (
                            L.label('control-label') / 'amount', L.br, L.input(name='amount', type='number'),
                        ),
                        L.div / (
                            L.label('control-label') / 'message (optional)', L.br, L.input(name='message', max_length="140"),
                        ),
                        L.br,
                        L.button(type='submit') / 'send petals',
                    ),
                    L.i / message,
                ),
            )
        ) if email else (
            L.div('.row') / (
                L.div('.col-sm-3') / (
                    L.h3 / 'see your account',
                    L.p / 'You will receive an email with a link to login to your account',
                    L.form(method='post') / (
                        L.input(type='hidden', name='csrfmiddlewaretoken', value=get_token(request)),
                        L.div / (
                            L.label('control-label') / 'email', L.br, L.input(name='email'),
                        ),
                        L.br,
                        L.button(type='submit') / 'send email with login link'
                    ),
                    L.i / message,
                ),
            )
        )
    )
    return HttpResponse(tpl_base(content))
Example #10
0
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,
        ]))