old_contents: # Copyright (c) 2016 Luke San Antonio Bialecki
  # All rights reserved.
  
  from . import models
  from .models import db
  
  
  def user_is_participant(user_id, org_id):
      q = db.session.query(models.org_participants).filter_by(
          participant=user_id, org=org_id
      )
      (ret,) = db.session.query(q.exists()).first()
      return ret
  
  
  def user_is_mod(user_id, org_id):
      q = db.session.query(models.org_mods).filter_by(mod=user_id, org=org_id)
      (ret,) = db.session.query(q.exists()).first()
      return ret
  
new_contents: # Copyright (c) 2016 Luke San Antonio Bialecki
  # All rights reserved.
  
  from . import exceptions as ex
  from . import models
  from .models import db, User, Org
  
  
  def user_is_participant(user_id, org_id):
      q = db.session.query(models.org_participants).filter_by(
          participant=user_id, org=org_id
      )
      (ret,) = db.session.query(q.exists()).first()
      return ret
  
  
  def user_is_mod(user_id, org_id):
      q = db.session.query(models.org_mods).filter_by(mod=user_id, org=org_id)
      (ret,) = db.session.query(q.exists()).first()
      return ret
  
  
  def get_field(request, field):
      val = request.get_json().get(field, None)
      if val is None:
          raise ex.MissingFieldError(field)
      return val
  
  
  def get_org_by_id(org_id):
      org = Org.query.filter_by(id=org_id).first()
      if org is None:
          raise ex.OrgNotFound(org_id)
      return org
  
  
  def get_user_by_id(user_id):
      user = User.query.filter_by(id=user_id).first()
      if user is None:
          raise ex.UserNotFound(user_id)
      return user
  
subject: Add helper functions to view_util for better error handling