コード例 #1
0
    def organizations(self):
        """
      Active, verified organizations related to this incident.

      Handles current and legacy incident/s properties.
      """
        from organization import Organization  # avoid circular import

        # lookup using new incidents field
        orgs = list(Organization.all().filter('incidents', self.key()).filter(
            'org_verified', True).filter('is_active', True))

        # build list of id and look for global admin
        org_ids = set()
        seen_global_admin = False
        for org in orgs:
            if org.is_global_admin:
                seen_global_admin = True
            org_id = org.key().id()
            if org_id not in org_ids:
                org_ids.add(org_id)

        # check legacy incident field
        legacy_field_orgs = Organization.all().filter('incident', self.key()) \
            .filter('org_verified', True) \
            .filter('is_active', True)
        for org in legacy_field_orgs:
            if org.key().id() not in org_ids:
                orgs.append(org)

        # prepend global admin if not encountered
        if not seen_global_admin:
            orgs = (list(Organization.all().filter('name', 'Admin')) + orgs)
        return orgs
コード例 #2
0
    def dispatch(self, *args, **kwargs):
        " All requests must have valid, in-date activation codes. "

        self.page_blocks = page_db.get_page_block_dict()

        self.activation_code = self.request.get('code')
        if not self.activation_code:
            self.abort(404)

        # lookup org by activation code
        orgs_by_code = Organization.all() \
            .filter('activation_code', self.activation_code)
        if orgs_by_code.count() != 1:
            self.abort(404)
        self.org_by_code = orgs_by_code[0]

        # send response if already activated
        if self.org_by_code.is_active:
            self.render(
                already_activated_template,
                org=self.org_by_code
            )
            return

        # send response if too late
        if self.org_by_code.activate_by < datetime.datetime.utcnow():
            self.render(
                activation_too_late_template,
                org=self.org_by_code
            )
            return

        # continue handling request
        super(ActivationHandler, self).dispatch(*args, **kwargs)
コード例 #3
0
    def dispatch(self, *args, **kwargs):
        " All requests must have valid, in-date activation codes. "

        self.page_blocks = page_db.get_page_block_dict()

        self.activation_code = self.request.get('code')
        if not self.activation_code:
            self.abort(404)

        # lookup org by activation code
        orgs_by_code = Organization.all() \
            .filter('activation_code', self.activation_code)
        if orgs_by_code.count() != 1:
            self.abort(404)
        self.org_by_code = orgs_by_code[0]

        # send response if already activated
        if self.org_by_code.is_active:
            self.render(already_activated_template, org=self.org_by_code)
            return

        # send response if too late
        if self.org_by_code.activate_by < datetime.datetime.utcnow():
            self.render(activation_too_late_template, org=self.org_by_code)
            return

        # continue handling request
        super(ActivationHandler, self).dispatch(*args, **kwargs)
コード例 #4
0
ファイル: event_db.py プロジェクト: DuaneNClark/crisiscleanup
  def organizations(self):
      """
      Active, verified organizations related to this incident.

      Handles current and legacy incident/s properties.
      """
      from organization import Organization  # avoid circular import

      # lookup using new incidents field
      orgs = list(
          Organization.all().filter('incidents', self.key())
              .filter('org_verified', True)
              .filter('is_active', True)
      )

      # build list of id and look for global admin
      org_ids = set()
      seen_global_admin = False
      for org in orgs:
          if org.is_global_admin:
              seen_global_admin = True
          org_id = org.key().id()
          if org_id not in org_ids:
              org_ids.add(org_id)

      # check legacy incident field
      legacy_field_orgs = Organization.all().filter('incident', self.key()) \
          .filter('org_verified', True) \
          .filter('is_active', True)
      for org in legacy_field_orgs:
          if org.key().id() not in org_ids:
              orgs.append(org)

      # prepend global admin if not encountered
      if not seen_global_admin:
          orgs = (
              list(Organization.all().filter('name', 'Admin')) +
              orgs
          )
      return orgs
def create_work_order_search_form(events, work_types, limiting_event=None):
    events_by_recency = sorted(events, key=lambda event: event.key().id(), reverse=True)

    # determine orgs and work types to include
    if limiting_event:
        if limiting_event.key() not in [e.key() for e in events]:
            raise Exception("Event %s unavailable" % limiting_event)
        orgs = Organization.all().filter('incidents', limiting_event.key())
        work_types = [
            site.work_type for site
            in Query(Site, projection=['work_type'], distinct=True) \
                .filter('event', limiting_event.key())
            if site.work_type in work_types
        ]
    else:
        orgs = Organization.all().filter('incidents in', [event for event in events])

    class WorkOrderSearchForm(Form):

        def __init__(self, *args, **kwargs):
            super(WorkOrderSearchForm, self).__init__(*args, **kwargs)
            self.offset.data = 0  # offset set by the form should always be 0

        offset = HiddenField(default="0")
        order = HiddenField()
        event = SelectField(
            choices=[
                (e.key(), e.name) for e in events_by_recency
            ],
            default=events_by_recency[0].key()
        )
        query = TextField("Search")
        reporting_org = SelectField(
            choices=[('', '')] + [
                (org.key(), org.name) for org in orgs
            ],
            default=''
        )
        claiming_org = SelectField(
            choices=[('', '')] + [
                (org.key(), org.name) for org in orgs
            ],
            default=''
        )
        work_type = SelectField(
            choices=[('', '')] + [
                (work_type, work_type) for work_type in work_types
            ],
            default=''
        )
        status = SelectField(
            choices=[('', '')] + [
                (s, s) for s in Site.status.choices
            ],
            default=''
        )
        per_page = SelectField(
            choices=[
                (n, n) for n in [10, 50, 100, 250]
            ],
            coerce=int,
            default=10
        )

    return WorkOrderSearchForm