def get(self):
        event_shortname = self.request.get("shortname")
        page = self.request.get("page")
        page_int = int(page)

        if event_shortname == None:
            event_shortname = "sandy"
        event = None
        events = event_db.GetAllCached()
        for e in events:
            if e.short_name == event_shortname:
                event = e

        ids = []
        where_string = "Open"
        q = None
        if event.short_name != 'moore':
            gql_string = 'SELECT * FROM Site WHERE status >= :1 and event = :2'
            q = db.GqlQuery(gql_string, where_string, event.key())

        else:
            q = Query(model_class=site_db.Site)

            q.filter("event =", event.key())
            q.is_keys_only()
            q.filter("status >= ", "Open")

            this_offset = page_int * PAGE_OFFSET

            ids = [
                key.key().id()
                for key in q.fetch(PAGE_OFFSET, offset=this_offset)
            ]

        this_offset = page_int * PAGE_OFFSET

        ids = [
            key.key().id() for key in q.fetch(PAGE_OFFSET, offset=this_offset)
        ]

        def public_site_filter(site):
            # site as dict
            return {
                'event': site['event'],
                'id': site['id'],
                'case_number': site['case_number'],
                'work_type': site['work_type'],
                'claimed_by': site['claimed_by'],
                'status': site['status'],
                'floors_affected': site.get('floors_affected'),
                'blurred_latitude': site.get('blurred_latitude'),
                'blurred_longitude': site.get('blurred_longitude'),
            }

        output = json.dumps([
            public_site_filter(s[1]) for s in site_db.GetAllCached(event, ids)
        ],
                            default=dthandler)
        self.response.out.write(output)
def GetOrganizationForm(post_data):
  e = event_db.Event(name = "Test Incident",
  case_label = "B",
  counties = ["Kings"])
  query_string = "SELECT * FROM Organization WHERE is_active = True ORDER BY name"
  organizations = db.GqlQuery(query_string)
  events = event_db.GetAllCached()
  events = db.GqlQuery("SELECT * From Event ORDER BY created_date DESC")
  event_key = None
  if events.count() == 0:
    logging.warning("Initialize called")
    e = event_db.Event(name = "North Central Victorian Floods",
                       case_label = "A",
                       short_name = "ncv_floods")
    e.put()
    event_key = e.key()
    # TODO(Jeremy): This could be dangerous if we reset events.
    for s in site_db.Site.all().run(batch_size = 1000):
      event_db.AddSiteToEvent(s, e.key().id(), force = True)
    events = [e]

  if organizations.count() == 0:
    # init: populate the database with Admin user
    admin_org = organization.Organization(
        name="Admin",
        password="******",
        org_verified=True,
        is_active=True,
        is_admin=True,
        incidents=[event_key]
    )
    admin_org.put()
    admin_contact = primary_contact_db.Contact(
        first_name="Admin",
        last_name="Admin",
        title="Admin",
        phone="1234",
        email="*****@*****.**",
        organization=admin_org,
        is_primary=True
    )
    admin_contact.put()
    organizations = db.GqlQuery("SELECT * FROM Organization WHERE is_active = True ORDER BY name")

  class OrganizationForm(wtforms.form.Form):
    event = wtforms.fields.SelectField(
        'Work Event',
        choices = [(e.name, e.name) for e in events],
        validators = [wtforms.validators.required()])
    password = wtforms.fields.PasswordField(
        'Password',
        validators = [ wtforms.validators.required() ])
  form = OrganizationForm(post_data)
  return form
Пример #3
0
 def get(self):
     events = event_db.GetAllCached()
     logged_in = False
     org, event = key.CheckAuthorization(self.request)
     if org and key:
         logged_in = True
     template_params = page_db.get_page_block_dict()
     template_params.update({
         "events": events,
         "logged_in": logged_in,
     })
     self.response.out.write(template.render(template_params))
Пример #4
0
  def get(self):
    pass
    events = event_db.GetAllCached()
    logged_in = False
    org, event = key.CheckAuthorization(self.request)
    query_string = "SELECT * FROM Event WHERE short_name = '{0}'".format(self.request.get("event"))
    query = db.GqlQuery(query_string)
    event = query.get()
    # raise Exception(event)
    if org and key:
      logged_in = True

    template_params = page_db.get_page_block_dict()
    template_params.update({
      "events": events,
      "logged_in": logged_in,
      "initial_incident_id": self.request.GET.get("initial_incident_id", ""),
      "incident": self.request.get("incident"),
      "event": self.request.get("event"),
      "event_name": self.request.get("event_name")
      })
    self.response.out.write(template.render(template_params))
Пример #5
0
def GetAllCached(event, ids=None):
    if ids == None:
        q = Query(model_class=Site, keys_only=True)
        q.filter("event =", event)
        ids = [key.id() for key in q.run(batch_size=2000)]
    lookup_ids = [str(id) for id in ids]
    cache_results = memcache.get_multi(lookup_ids, key_prefix=cache_prefix)
    not_found = [id for id in ids if not str(id) in cache_results.keys()]
    data_store_results = []
    orgs = dict([(o.key(), o) for o in organization.GetAllCached()])
    events = dict([(e.key(), e) for e in event_db.GetAllCached()])
    if len(not_found):
        data_store_results = [
            (site, SiteToDict(site))
            for site in GetSitesAndSetReferences(not_found, events, orgs)
        ]
        memcache.set_multi(dict([(str(site[0].key().id()), site)
                                 for site in data_store_results]),
                           key_prefix=cache_prefix,
                           time=cache_time)

    sites = cache_results.values() + data_store_results
    return sites