def search(partial): """ Search for households containing the partial search. :param partial: The string to search for. :return: The households JSON. """ return jsonify(result=db.query_db(queries.HOUSEHOLD_SEARCH, [ '%' + partial + '%', ]))
def getHouseholdRelation(householdId, userId): """ Returns the relation between this household and this user. :param householdId: The household to check. :param userId: The user to check. :return: A relation from enums.e_household_relation. """ val = db.query_db(queries.HOUSEHOLD_MEMBERSHIP_GET_FOR_USER_AND_HOUSEHOLD, [userId, householdId], True) return val['e_household_relation'] if val is not None else None
def getUsersForHousehold(householdId): """ Returns a list of users for a given household. Keys in each dictionary within the returned list are: * id * membership_date * e_household_relation :param householdId: :return: A list of users for the household. """ return db.query_db(queries.HOUSEHOLD_GET_USERS, [householdId, ])
def getHouseholdsForUser(userId): """ Returns a list of households for a given user. Keys in each dictionary within the returned list are: * households.id * households.household_name * households.e_household_type * household_memberships.e_household_relation :param userId: The user for which to get the households. :return: A list of households for the user. """ return db.query_db(queries.USER_GET_HOUSEHOLDS_NO_REQUESTS, [userId, ])
def getEvents(log, after, count): """ Return the events after a certain index. :param log: The log type to get events for. :param after: Index to start events (descending) :param count: How many events to pull. :return: An array of events. """ if not enums.contains(enums.e_log_event_type, log): return None return db.query_db(queries.LOG_GET, [log, after, count])