Ejemplo n.º 1
0
def _search_and_download(django_app: wt.TestApp):
    # base.html: <a href="/import">QR-Codes erzeugen</a>
    # and        <a href="/search">Nach Personen suchen</a>
    resp = django_app.get("/")
    search_url = _check_menu(resp.text)
    search1 = django_app.get(search_url)
    # the following is hardcoded against data values in _make_visits:
    # --- search:
    data = dict(givenname="A.",
                from_date=aud.nowstring(),
                to_date=aud.nowstring())
    _fill_with(search1.form, data)
    search2 = search1.form.submit('submit_visit')
    # print("container:", _find(search2.text, name="div", class_="container"))
    if settings.USE_EMAIL_FIELD:
        assert "*****@*****.**" in search2.text
        assert "*****@*****.**" not in search2.text
        assert "*****@*****.**" not in search2.text
    assert "A." in search2.text
    assert "B." not in search2.text
    assert "C." not in search2.text
    # --- find contacts:
    search3 = search2.form.submit('submit_visitgroup')
    # print("### searchhits:", _find(search3.text, name="ol", class_="searchhits"))
    if settings.USE_EMAIL_FIELD:
        assert "*****@*****.**" in search3.text
        assert "*****@*****.**" in search3.text
        assert "*****@*****.**" not in search3.text
    assert "A." in search3.text
    assert "B." in search3.text
    assert "C." not in search3.text
    # --- download Excelfile:
    search4 = search3.form.submit('submit_xlsx')
    excelbytes = search4.body
    _validate_excel(excelbytes)
Ejemplo n.º 2
0
def test_nowstring():
    d_only = aud.nowstring()
    t_only = aud.nowstring(date=False, time=True)
    both = aud.nowstring(date=True, time=True)
    assert re.match(r"^\d\d\d\d-\d\d-\d\d$", d_only),\
           f"wrong d_only nowstring '{d_only}'"
    assert re.match(r"^\d\d:\d\d$", t_only),\
           f"wrong t_only nowstring '{t_only}'"
    assert re.match(r"^\d\d\d\d-\d\d-\d\d \d\d:\d\d$", both),\
           f"wrong both nowstring '{both}'"
Ejemplo n.º 3
0
 def get_form(self, data=None, files=None, **kwargs):
     if data:  # POST
         data = {k: v for k, v in data.items()}  # extract ordinary dict
         return arf.VisitForm(data=data, files=files, **kwargs)
     # else GET:
     if COOKIENAME in self.request.COOKIES:
         initial = json.loads(self.request.COOKIES[COOKIENAME])
     else:
         initial = dict(cookie=arm.Visit.make_cookie())
         logging.info(f"VisitView: new {initial}")
     initial['present_from_dt'] = aud.nowstring(date=False, time=True)
     return arf.VisitForm(initial=initial)
Ejemplo n.º 4
0
 def excel_download_response(self, visits: tg.List[tg.Optional[arm.Visit]]) -> djh.HttpResponse:
     # https://stackoverflow.com/questions/4212861
     excel_contenttype_excel = \
         "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
     excelbytes = are.get_excel_download(visits)
     response = djh.HttpResponse(excelbytes,
                                 content_type=excel_contenttype_excel)
     timestamp = aud.nowstring(date=True, time=True)
     # make name nice for Linux (no blanks) and for Windows (no colons):
     timestamp = timestamp.replace(' ', '_').replace(':', ".")
     filename = f"anwesende-{timestamp}.xlsx"
     response['Content-Disposition'] = (
         'attachment; filename="%s"' % (filename,))
     return response
Ejemplo n.º 5
0
 def get_form(self, data=None, files=None, **kwargs):
     if data:  # POST
         data = {k: v for k, v in data.items()}  # extract ordinary dict
         return arf.VisitForm(data=data, files=files, **kwargs)
     # else GET:
     if COOKIENAME in self.request.COOKIES:
         try:
             thecookie = self.request.COOKIES[COOKIENAME]
             initial = json.loads(thecookie)
         except json.JSONDecodeError as err:
             tb = traceback.format_exc(limit=12, chain=True)
             logging.warning(f"VisitView: broken cookie >>>>{thecookie}<<<<\n{tb}")
             initial = dict(cookie=arm.Visit.make_cookie())
             logging.info(f"VisitView: ersatz {initial}")
     else:
         initial = dict(cookie=arm.Visit.make_cookie())
         logging.info(f"VisitView: new {initial}")
     initial['present_from_dt'] = aud.nowstring(date=False, time=True)
     return arf.VisitForm(initial=initial)
Ejemplo n.º 6
0
class SearchForm(djf.Form):
    emailwarning = ("ABGESCHALTET. Die Daten enthalten keine Emailadressen. "
                    "Sie können also per Emailadresse nichts finden!")
    roomdescriptor = djf.CharField(
        label="Raumbeschreibung (organization;department;building;room)",
        initial="%",
        required=True,
    )
    givenname = djf.CharField(
        label="Vorname / Given name",
        initial="%",
        required=True,
    )
    familyname = djf.CharField(
        label="Nachname / Family name",
        initial="%",
        required=True,
    )
    phone = djf.CharField(
        label="Telefonnummer",
        initial="+%",
        required=True,
        help_text="Mögliche Leerzeichen durch '%' tolerierbar machen!")
    email = djf.CharField(
        label="Emailadresse",
        initial="%@%" if settings.USE_EMAIL_FIELD else "%",
        required=True,
        help_text="" if settings.USE_EMAIL_FIELD else emailwarning)
    from_date = djf.DateField(
        label="von Datum (jjjj-mm-tt)",
        initial="",
        required=True,
    )
    to_date = djf.DateField(
        label="bis Datum (jjjj-mm-tt)",
        initial=aud.nowstring(time=False),
        required=True,
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = cfh.FormHelper()
        self.helper.form_id = 'SearchForm'
        self.helper.form_method = 'post'
        self.helper.add_input(cfl.Submit('submit_visit', '1. Besuche finden'))
        self.helper.add_input(
            cfl.Submit('submit_visitgroup', '2. Kontaktgruppen finden'))
        self.helper.add_input(
            cfl.Submit('submit_xlsx', '3. Kontaktgruppen-Excel herunterladen'))

    def clean(self):
        self.cleaned_data = super().clean()
        cd = self.cleaned_data  # short alias
        if ('from_date' in cd and 'to_date' in cd
                and cd['from_date'] > cd['to_date']):
            self.add_error('to_date',
                           "'von Datum' muss vor oder auf 'bis Datum' liegen")
        if 'to_date' in cd:
            cd['to_date'] += dt.timedelta(
                hours=24)  # is time 0:00, should be 24:00
        return cd
Ejemplo n.º 7
0
class SearchForm(djf.Form):
    organization = djf.CharField(
        label="Organization",
        initial="%",
        required=True,
    )
    department = djf.CharField(
        label="Department",
        initial="%",
        required=True,
    )
    building = djf.CharField(
        label="Building",
        initial="%",
        required=True,
    )
    room = djf.CharField(
        label="Room",
        initial="%",
        required=True,
    )
    givenname = djf.CharField(
        label="Vorname / Given name",
        initial="%",
        required=True,
    )
    familyname = djf.CharField(
        label="Nachname / Family name",
        initial="%",
        required=True,
    )
    # phone = djf.CharField(label="Telefonnummer",
    #         initial="+491%", required=True, )
    email = djf.CharField(
        label="Emailadresse",
        initial="%@%",
        required=True,
    )
    from_date = djf.DateField(
        label="von Datum (jjjj-mm-tt)",
        initial="",
        required=True,
    )
    to_date = djf.DateField(
        label="bis Datum (jjjj-mm-tt)",
        initial=aud.nowstring(time=False),
        required=True,
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = cfh.FormHelper()
        self.helper.form_id = 'SearchForm'
        self.helper.form_method = 'post'
        self.helper.add_input(cfl.Submit('visit', '1. Besuche finden'))
        self.helper.add_input(
            cfl.Submit('visitgroup', '2. Kontaktgruppen finden'))
        self.helper.add_input(
            cfl.Submit('xlsx', '3. Kontaktgruppen-Excel herunterladen'))

    def clean(self):
        self.cleaned_data = super().clean()
        cd = self.cleaned_data  # short alias
        if ('from_date' in cd and 'to_date' in cd
                and cd['from_date'] > cd['to_date']):
            self.add_error('to_date',
                           "'von Datum' muss vor oder auf 'bis Datum' liegen")
        if 'to_date' in cd:
            cd['to_date'] += dt.timedelta(
                hours=24)  # is time 0:00, should be 24:00
        return cd