Commits

Shu Zong Chen  committed 0d048fb

initial tweaking to gis_io models in prepartion of connecting it to site

  • Participants
  • Parent commits 5b9b9f1

Comments (0)

Files changed (2)

File cjh/gis_io/admin.py

+from django.contrib import admin
+from cjh.gis_io.models import Upstream
+
+class UpstreamAdmin(admin.ModelAdmin):
+	readonly_fields = ('last_modified',)
+	#exclude = ('engine',)
+	#def save_model(self, request, obj, form, change):
+	#	obj.engine = 'markdown'
+	#	obj.save()
+
+admin.site.register(Upstream, UpstreamAdmin)

File cjh/gis_io/models.py

 
 DL_YAML = os.path.join(settings.BASE_PATH, '../upstreams.yaml')
 DL_BASE = os.path.join(settings.BASE_PATH, '../upstreams')
+DL_DOWNLOAD_PATH = lambda x: os.path.normpath(os.path.join(DL_BASE, x.parent_id, x.id))
 
 class GIS_IO(object):
 	"""
 	GIS IO Manager
+
+	Use GIS_IO.upstreams to get all upstreams available
 	"""
 	_upstreams = None
 
 	@staticmethod
-	def get_upstreams():
-		with open(DL_YAML) as fh:
-			data = yaml.load(fh)
-		ret = []
-		for d in data['data']:
-			for s in d['sources']:
-				ret.append(GIS_Upstream(d['id'], d['name'], s))
-		return ret
+	def upstreams():
+		"""
+		Return list of all upstreams
 
-	@staticmethod
-	def upstreams():
+		Memoized
+		"""
 		if GIS_IO._upstreams is None:
-			GIS_IO._upstreams = GIS_IO.get_upstreams()
+			with open(DL_YAML) as fh:
+				data = yaml.load(fh)
+			ret = []
+			for d in data['data']:
+				for s in d['sources']:
+					ret.append(GIS_Upstream(d['id'], d['name'], s))
+			GIS_IO._upstreams = ret
 		return GIS_IO._upstreams
 
 class Upstream(models.Model):
 	"""
 	Object Representation of an upstream file.
 
-	Don't instantiate this directly, you get one through
-	GIS_IO.get_blah()
+	Don't instantiate this directly, you get one out of
+	GIS_IO.upstreams dictionary
 	"""
 	def __init__(self, parent_id, parent_name, data):
 		self.parent_id = parent_id
 	
 	@property
 	def download_path(self):
-		return os.path.normpath(os.path.join(DL_BASE, self.parent_id, self.id))
+		return DL_DOWNLOAD_PATH(self)
 
 class GIS_Item(object):
 	def __init__(self, meta, shape):