def get_caches_list(sql): caches = [] if not sql: return [] for row in iter_sql(sql): cache = Geothing.objects.get(pk=row[0]) caches.append(cache) return caches
def cache_types(): choices = [] sql = """ SELECT DISTINCT type_code FROM cach """ for item in iter_sql(sql): choices.append((item[0], GEOCACHING_SU_CACH_TYPES.get(item[0], ''))) return choices
def populate_cach_type(field, *kargs, **kwargs): field.choices = [] field.choices.append(('ALL', _('all'))) field.choices.append(('REAL', _('all real'))) field.choices.append(('UNREAL', _('all unreal'))) sql = """ SELECT DISTINCT type_code FROM cach """ for item in iter_sql(sql): field.choices.append( (item[0], GEOCACHING_SU_CACH_TYPES.get(item[0], '')))
def countries_iso3(): choices = [] sql = """ SELECT DISTINCT c.iso3, c.name FROM geocacher gc LEFT JOIN geo_country as c ON gc.country_iso3=c.iso3 WHERE gc.found_caches > 0 HAVING c.iso3 IS NOT NULL ORDER BY c.name """ l = [] for item in iter_sql(sql): l.append((item[0], _(item[1]))) return choices + sorted(l, key=lambda x: x[1])
def populate_subjects(field, *kargs, **kwargs): field.choices = [] field.choices.append(('ALL', _('all'))) sql = """ SELECT gcs.code, gcs.name FROM geo_country_subject gcs LEFT JOIN geo_country gc ON gcs.country_iso=gc.iso WHERE gc.iso3 = '%s' ORDER BY gcs.name """ % kwargs.get('selected_country_iso', '') l = [] for item in iter_sql(sql): l.append((item[0], _(item[1]))) field.choices = field.choices + sorted(l, key=lambda x: x[1])
def populate_countries_iso3(field, *kargs, **kwargs): field.choices = [] field.choices.append(('ALL', _('all'))) sql = """ SELECT DISTINCT c.iso3, c.name FROM cach LEFT JOIN geo_country as c ON cach.country_code=c.iso HAVING c.iso3 IS NOT NULL ORDER BY c.name """ l = [] for item in iter_sql(sql): l.append((item[0], _(item[1]))) field.choices = field.choices + sorted(l, key=lambda x: x[1])
def populate_country_iso3(field, *kargs, **kwargs): field.choices = [] field.choices.append(('', _('all'))) sql = """ SELECT DISTINCT c.iso3, c.name FROM geocacher gc LEFT JOIN geo_country as c ON gc.country_iso3=c.iso3 WHERE gc.found_caches > 0 HAVING c.iso3 IS NOT NULL ORDER BY c.name """ l = [] for item in iter_sql(sql): l.append((item[0], _(item[1]))) field.choices = field.choices + sorted(l, key=lambda x: x[1])