Example #1
0
  def get(self):
    config = memcache.get('config') or Configuration.all().get()
    notify_descriptions = (memcache.get('ndesc') or
                           NotificationTypes.all())

    if config:
      template_values = {
        'key_id': config.key_id,
        'vcode': config.vcode,
        'rcpt_char': config.rcpt_char,
        'rcpt_org': config.rcpt_org,
        'rcpt_org2': config.rcpt_org2 or '',
        'dest_email': config.dest_email,
        'notify_types': config.notify_types,
        'notify_descriptions': notify_descriptions,
      }
    else:
      template_values = {
        'key_id': '',
        'vcode': '',
        'rcpt_char': '',
        'rcpt_org': '',
        'rcpt_org2': '',
        'dest_email': '',
        'notify_types': [],
        'notify_descriptions': notify_descriptions,
      }

    template = jinja_environment.get_template('index.html')
    self.response.out.write(template.render(template_values))
Example #2
0
 def post(self):
     if login.isAdmin():
         isActive = self.request.get('active') == 'True'
         activeProperty = Configuration.all().filter('name', 'checkin').get()
         if (activeProperty):
             activeProperty.value = isActive
         else:
             activeProperty = Configuration(name='checkin', value=isActive)
         activeProperty.put()
Example #3
0
  def get(self):
    config = memcache.get('config') or Configuration.all().get()
    if not config:
      # We haven't set up our configuration yet, so don't try to do anything
      return

    elink_api = elink_appengine.AppEngineAPI(api_key=(config.key_id, config.vcode))
    elink_char = evelink.char.Char(config.rcpt_char, api=elink_api)
    elink_eve = evelink.eve.EVE(api=elink_api)

    recips = set([config.rcpt_org])
    if config.rcpt_org2:
      recips.add(config.rcpt_org2)

    headers = elink_char.messages()
    message_ids = set(h['id'] for h in headers if h['to']['org_id'] in recips)

    headers = dict((h['id'], h) for h in headers)

    message_ids_to_relay = set()
    sender_ids = set()

    for m_id in message_ids:
      seen = memcache.get('seen-%s' % m_id) or SeenMail.gql("WHERE mail_id = :1", m_id).get()
      if not seen:
        message_ids_to_relay.add(m_id)
        sender_ids.add(headers[m_id]['sender_id'])
      else:
        memcache.set('seen-%s' % m_id, True)

    if not message_ids_to_relay:
      self.response.out.write("No pending messages.")
      return

    bodies = elink_char.message_bodies(message_ids_to_relay)
    senders = elink_eve.character_names_from_ids(sender_ids)

    e = EmailMessage()
    e.to = config.dest_email
    e.sender = '*****@*****.**'
    for m_id in message_ids_to_relay:
      sender = senders[headers[m_id]['sender_id']]
      timestamp = headers[m_id]['timestamp']
      e.subject = '[EVEMail] %s' % headers[m_id]['title']
      e.html = self.format_message(bodies[m_id] or '', timestamp, sender)
      e.send()
      SeenMail(mail_id=m_id).put()
      memcache.set('seen-%s' % m_id, True)
      self.response.out.write("Processed message ID %s.<br/>\n" % m_id)

    return
Example #4
0
def base_context():
    context = Context({
        'current_user':current_user(),
        'admin':admin(),
        'login_url':users.create_login_url('/blogs'),
        'logout_url':users.create_logout_url('/blogs'),
        'recent_comments':Comment.all().order('-date').fetch(5),
        'categories':Category.all(),
        'blogs_count':Blog.all().count(),
        'archives':Archive.all().order('-year').order('-month'),
        'friendlyURLs':FriendlyURL.all()
    })
    configuration=Configuration.all().fetch(1)
    if configuration:
        context.configuration=configuration[0]
    return context
Example #5
0
  def get(self):
    config = memcache.get('config') or Configuration.all().get()
    notify_descriptions = (memcache.get('ndesc') or
                           NotificationTypes.all())

    if not config:
      # We haven't set up our configuration yet, so don't try to do anything
      return

    elink_api = elink_appengine.AppEngineAPI(api_key=(config.key_id, config.vcode))
    elink_char = evelink.char.Char(config.rcpt_char, api=elink_api)
    elink_eve = evelink.eve.EVE(api=elink_api)

    self.send_emails(config, elink_api, elink_char, elink_eve)
    self.send_notifications(config, elink_api, elink_char, elink_eve,
                            notify_descriptions)
Example #6
0
def base_context():
    context = Context(
        {
            "current_user": current_user(),
            "admin": admin(),
            "login_url": users.create_login_url("/blogs"),
            "logout_url": users.create_logout_url("/blogs"),
            "recent_comments": Comment.all().order("-date").fetch(5),
            "categories": Category.all(),
            "blogs_count": Blog.all().count(),
            "archives": Archive.all().order("-year").order("-month"),
            "friendlyURLs": FriendlyURL.all(),
        }
    )
    configuration = Configuration.all().fetch(1)
    if configuration:
        context.configuration = configuration[0]
    else:
        context.configuration = False
    return context
Example #7
0
    def put(self, id):
        isActive = Configuration.all().filter('name', 'checkin').get()
        isAdmin = login.isAdmin()
        isPlayer = login.isPlayer() and not isAdmin
        user = users.get_current_user()
        if not isAdmin and not isPlayer:
            self.response.out.write('not_logged_in')
        else:
            request = json.loads(self.request.body)
            status = request['status']
            n_presents = Player.all().filter('status =', 'present').count()

            if status != 'present' or n_presents < 10:
                player = None
                if isAdmin:
                    id = long(id)
                    player = Player.get_by_id(id)
                    logging.info('Admin set status to \'' + status + '\' for ' +
                                 str(player.email))
                elif isPlayer and (isActive is None or isActive.value):
                    player = Player.all()
                    player = player.filter('email =', user.email()).get()
                    logging.info(str(player.email) + ' set status to \'' +
                                 status + '\'')

                if player:
                    player.status = status
                    player.put()
                    #self.response.out.write('ok')
                else:
                    logging.info(user.nickname() + ' (' + user.email() +
                                 ') tried to set status to \'' +
                                 status + '\' but it was inactive')
                    self.response.set_status(401, 'La lista &egrave; bloccata o \
                            non sei pi&ugrave; loggato')

            else:
                logging.info(user.nickname() + ' (' + user.email() +
                             ') tried to set status to \'' + status +
                             '\' but it was full')
                self.response.set_status(500, 'La lista &egrave; piena')
Example #8
0
    def post(self):
        #email = users.get_current_user().email()
        isActive = Configuration.all().filter('name', 'checkin').get()
        isAdmin = login.isAdmin()
        isPlayer = login.isPlayer() and not isAdmin
        user = users.get_current_user()
        if not isAdmin and not isPlayer:
            self.response.out.write('not_logged_in')
        else:
            n_presents = Player.all().filter('status =', 'present').count()
            status = self.request.get('status')
            if status != 'present' or n_presents < 10:
                player = None
                id = self.request.get('id')
                if isAdmin and id:
                    id = long(id)
                    player = Player.get_by_id(id)
                    logging.info('Admin set status to \'' + 
                            status + '\' for ' + str(player.email))
                elif isActive == None or isActive.value:
                    player = Player.all()
                    player = player.filter('email =', user.email()).get()
                    logging.info(str(player.email) + ' set status to \'' + 
                            status + '\'')

                if player:
                    player.status = status
                    player.put()
                    self.response.out.write('ok')
                else:
                    logging.info(user.nickname() + ' (' + user.email() + 
                            ') tried to set status to \'' + status + 
                            '\' but it was inactive')
                    self.response.out.write('inactive')

            else:
                logging.info(user.nickname() + ' (' + user.email() + 
                        ') tried to set status to \'' + status + 
                        '\' but it was full')
                self.response.out.write('full')
Example #9
0
  def get(self):
    config = memcache.get('config') or Configuration.all().get()

    if config:
      template_values = {
        'key_id': config.key_id,
        'vcode': config.vcode,
        'rcpt_char': config.rcpt_char,
        'rcpt_org': config.rcpt_org,
        'rcpt_org2': config.rcpt_org2 or '',
        'dest_email': config.dest_email,
      }
    else:
      template_values = {
        'key_id': '',
        'vcode': '',
        'rcpt_char': '',
        'rcpt_org': '',
        'rcpt_org2': '',
        'dest_email': '',
      }

    template = jinja_environment.get_template('index.html')
    self.response.out.write(template.render(template_values))
Example #10
0
 def get(self):
     if login.isAdmin():
         isActive = Configuration.all().filter('name', 'checkin').get()
         self.response.out.write(isActive == None or isActive.value)
Example #11
0
  def post(self):
    key_id = self.request.get('key_id')
    vcode = self.request.get('vcode')
    rcpt_char = self.request.get('rcpt_char')
    rcpt_org = self.request.get('rcpt_org')
    rcpt_org2 = self.request.get('rcpt_org2')
    dest_email = self.request.get('dest_email')

    if not (key_id and vcode and rcpt_org and dest_email):
      self.response.out.write("Missing one or more fields.")
      return

    try:
      key_id = int(key_id)
    except (ValueError, TypeError):
      self.response.out.write("Key ID must be an integer.")
      return

    try:
      rcpt_char = int(rcpt_char)
    except (ValueError, TypeError):
      rcpt_char = self.get_entity_id(rcpt_char)

    try:
      rcpt_org = int(rcpt_org)
    except (ValueError, TypeError):
      rcpt_org = self.get_entity_id(rcpt_org)

    if not rcpt_org:
      self.response.out.write("Invalid organization name/id.")
      return

    if rcpt_org2:
      try:
        rcpt_org2 = int(rcpt_org2)
      except (ValueError, TypeError):
        rcpt_org2 = self.get_entity_id(rcpt_org2)

      if not rcpt_org2:
        self.response.out.write("Invalid organization #2 name/id.")
        return

    config = Configuration.all().get()
    if not config:
      config = Configuration(
        key_id=key_id,
        vcode=vcode,
        rcpt_char=rcpt_char,
        rcpt_org=rcpt_org,
        rcpt_org2=rcpt_org2,
        dest_email=dest_email,
      )
    else:
      config.key_id = key_id
      config.vcode = vcode
      config.rcpt_char = rcpt_char
      config.rcpt_org = rcpt_org
      if rcpt_org2:
        config.rcpt_org2 = rcpt_org2
      config.dest_email = dest_email

    config.put()
    memcache.set('config', config)

    self.response.out.write("Configuration saved.")
    return
Example #12
0
                subject="MtrHub: Remember to take a meter reading.",
                body=body)
            meter.set_next_reminder()
            meter.put()
        self.return_ok({})

routes = [
    (r'/', Home), (r'/view_meter', ViewMeter), (r'/view_read', ViewRead),
    (r'/edit_read', EditRead), (r'/send_read', SendRead), (r'/upload', Upload),
    (r'/chart', Chart), (r'/meter_settings', MeterSettings),
    (r'/view_reader', ViewReader), (r'/reader_settings', ReaderSettings),
    (r'/welcome', Welcome), (r'/export_reads', ExportReads),
    (r'/add_meter', AddMeter), (r'/cron', Cron),
    (r'/cron/reminders', Reminders), (r'/add_reader', AddReader)]

template_names = dict(
    [(cls.__name__, rt[1:] + '.html') for rt, cls in routes if rt != '/'])
template_names['Home'] = 'home.html'
conf = Configuration.all().get()
if conf is None:
    session_key = ''.join(
        random.choice(
            string.ascii_uppercase + string.digits) for x in range(10)
        ).encode('ascii', 'ignore')
    conf = Configuration(session_key=session_key)
    conf.put()
config = {
    'webapp2_extras.sessions': {
        'secret_key': conf.session_key.encode('ascii', 'ignore')}}
app = webapp2.WSGIApplication(routes, debug=True, config=config)