예제 #1
0
def login(login, password):
    """Try to verify the user.

    Returns (User, authenticated?)

    User will be None if password is missing or user does not exist,
    otherwise the object will be retrieved from the database.

    authenticated? will be True iff check_password succeeds
    and False otherwise.
    """
    user = None
    if login:
        user = User.by_username(login)
    if user and password:
        return (user, user.check_password(password))

    return (None, False)
예제 #2
0
def import_transactions():
    parser = gocept.logging.ArgumentParser(
        description="Import banking transactions.")
    parser.add_argument('-c',
                        '--config',
                        default='portal.ini',
                        help='Specify the config file. (default: portal.ini)')
    options = parser.parse_args()
    app = Application.from_filename(options.config)
    registry = pyramid.registry.Registry(
        bases=(zope.component.getGlobalSiteManager(), ))
    config = pyramid.config.Configurator(settings=app.settings,
                                         registry=registry)
    config.setup_registry(settings=app.settings)
    request = pyramid.testing.DummyRequest(_registry=registry)
    request.client_addr = '127.0.0.1'
    context = pyramid.threadlocal.manager.get().copy()
    context['request'] = request
    context['registry'] = registry
    pyramid.threadlocal.manager.push(context)
    user = User.by_username('system')
    import_transactions_from_fints(user)
예제 #3
0
    def send_report(self):
        org_id = self.request.user.organization_id
        current_year = get_selected_year()
        price = (EnergyPrice.query().filter(
            EnergyValue.organization_id == org_id).filter(
                EnergyPrice.year == current_year).one())

        data = json.loads(json.dumps(price))
        data['phases'] = self.phases
        data['price'] = format_eur(data['price'])
        data['bill'] = format_eur(data['bill'])
        data['normal_fee'] = format_eur(data['normal_fee'])
        data['power_fee'] = format_eur(data['power_fee'])

        subject = "Bericht Energieabrechnung {year}".format(**data)

        body = """
        <p>Sehr geehrter Vorstand,</p>

        <p>anbei die Kennzahlen zur diesjährigen Energieabrechnung:</p>

        <table>
        <tr><td>Verbrauch Hauptzähler: </td><td>{usage_hauptzaehler} kWh</td></tr>
        <tr><td>Verbrauch der Mitglieder (inkl. SAT-Anlage und
        Vereinsgebäude): </td><td>{usage_members} kWh</td></tr>
        <tr><td colspan=2></td></tr>

        <tr><td>Verluststrom: </td><td>{usage_hauptzaehler} kWh - {usage_members} kWh = {leakage_current} kWh</td></tr>
        <tr><td colspan=2></td></tr>

        <tr><td>Preis pro kWh: </td><td>{bill} / {usage_hauptzaehler} kWh = {price}/kWh</td></tr>
        <tr><td colspan=2></td></tr>

        <tr><td>Grundgebühr 1 Phase ({phases} insgesamt): </td><td>{leakage_current} kWh * {price}/kWh / {phases} = {normal_fee}</td></tr>
        <tr><td>Grundgebühr einfacher Zähler (1 Phase): </td><td>{normal_fee}</td></tr>
        <tr><td>Grundgebühr Kraftstromzähler (3 Phase): </td><td>{power_fee}</td></tr>
        </table><br /><br />""".format(**data)  # noqa
        send_mail("*****@*****.**", subject, body,
                  User.by_username('system'))
예제 #4
0
 def __call__(self):
     data = self.request.json
     sender = data['FromFull']['Email'].lower()
     if sender == '*****@*****.**':
         return Response('ok')
     if data['Subject'].startswith('***** SPAM'):
         return Response('ok')
     message = Message.create(inbound=True,
                              organization_id=self.organization_id,
                              user=User.by_username('system'))
     member = Member.query().filter(Member.email == sender).first()
     if member:
         message.members.append(member)
         message.organization_id = member.organization_id
     else:
         external = (ExternalRecipient.query().filter(
             ExternalRecipient.email == sender).first())
         if not external:
             external = ExternalRecipient.create(email=sender)
             external.lastname = data['FromFull']['Name']
             external.organization_id = self.organization_id
         message.externals.append(external)
         message.organization_id = external.organization_id
     message.subject = data['Subject']
     message.body = (data['HtmlBody']
                     if data['HtmlBody'] else data['TextBody'])
     message.sent = self.sent_date(data)
     message.accounting_year = message.sent.year
     for attachment in data['Attachments']:
         Attachment.create(message=message,
                           organization_id=message.organization_id,
                           filename=attachment["Name"],
                           mimetype=attachment["ContentType"],
                           size=attachment["ContentLength"],
                           data=base64.b64decode(attachment["Content"]))
     return Response('ok')
예제 #5
0
def export_events_ics():
    import sw.allotmentclub.browser.calendar
    parser = gocept.logging.ArgumentParser(
        description="Export events in ics format.")
    parser.add_argument('-c',
                        '--config',
                        default='portal.ini',
                        help='Specify the config file. (default: portal.ini)')
    parser.add_argument('-t', '--type', help='The type (Mitglied|Vorstand)')
    options = parser.parse_args()
    assert options.type in ('Mitglied', 'Vorstand')

    queries = {
        'Mitglied': sw.allotmentclub.browser.calendar.MitgliederQuery,
        'Vorstand': sw.allotmentclub.browser.calendar.VorstandQuery
    }

    Application.from_filename(options.config)

    name = ('Mitgliederliste'
            if options.type == 'Mitglied' else 'Vorstandsliste')
    output = f"""\
BEGIN:VCALENDAR
VERSION:2.0
PRODID:VerwaltungLeunaBundalow
X-WR-CALNAME:Leuna-Siedlung {name}
NAME:Leuna-Siedlung Mitgliederliste
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:Europe/Berlin
TZURL:http://tzurl.org/zoneinfo-outlook/Europe/Berlin
X-LIC-LOCATION:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
"""

    db = zope.component.getUtility(risclog.sqlalchemy.interfaces.IDatabase)
    query = queries[options.type](db, User.by_username('system')).select()
    for event in query:
        m = hashlib.md5()
        m.update('-'.join(str(i) for i in event).encode())
        uid = m.hexdigest()
        if event[-2]:
            timestamp = event[4].strftime('%Y%m%dT000000Z')
            start = end = event[4].strftime('%Y%m%d')
            if event[5]:
                end = event[5].strftime('%Y%m%d')
        else:
            timestamp = event[4].strftime('%Y%m%dT%H%M%SZ')
            start = end = event[4].strftime('%Y%m%dT%H%M%S')
            if event[5]:
                end = event[5].strftime('%Y%m%dT%H%M%S')
        output += f"""\
BEGIN:VEVENT
DTSTAMP:{timestamp}
UID:{uid}@roter-see.de
DTSTART;TZID=Europe/Berlin:{start}
DTEND;TZID=Europe/Berlin:{end}
SUMMARY:{event[2]}
LOCATION:{event[3]}
END:VEVENT
"""
    output += "END:VCALENDAR"
    print(output)