diff options
Diffstat (limited to 'apps/build/base.py')
-rw-r--r-- | apps/build/base.py | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/apps/build/base.py b/apps/build/base.py index 462f910..d8e4cdc 100644 --- a/apps/build/base.py +++ b/apps/build/base.py @@ -68,7 +68,7 @@ class BuildWriting(Build): model = get_model('blog', 'entry') qs = {'object_list': model.objects.filter(status__exact=1).order_by('-pub_date')[1:4]} c = Context(qs) - t = render_to_string('bin/recent_entries.html',c) + t = render_to_string('bin/recent_entries.html',c).encode('utf-8') fpath = '%s%s' %(settings.PROJ_ROOT,'templates/includes/recent_entries.html') self.write_file(fpath,t) @@ -78,7 +78,7 @@ class BuildWriting(Build): self.build_recent_entries() qs = get_model('blog', 'entry').objects.filter(status__exact=1).latest() c = Context({'featured':qs,'MEDIA_URL':settings.MEDIA_URL}) - t = render_to_string('archives/homepage.html',c) + t = render_to_string('archives/homepage.html',c).encode('utf-8') fpath = '%s%s' %(settings.STATIC_ROOT,'index.html') self.write_file(fpath,t) @@ -109,10 +109,9 @@ class BuildPhotos(BuildWriting): class BuildAbout(Build): def build(self): model = get_model('chunks', 'Chunk') + qs = model.objects.filter(key__in=['about_top','about_middle','about_bottom']) c = Context({ - 'top': model.objects.get(key='about_top'), - 'middle': model.objects.get(key='about_middle'), - 'bottom': model.objects.get(key='about_bottom'), + 'object_list': qs, 'IMAGES_URL' : settings.IMAGES_URL, 'MEDIA_URL':settings.MEDIA_URL }) @@ -155,4 +154,62 @@ class BuildContact(Build): c = Client() response = c.get('/contact/') fpath = '%scontact/index.html' %(settings.STATIC_ROOT) - self.write_file(fpath,str(response.content))
\ No newline at end of file + self.write_file(fpath,str(response.content)) + +class BuildProjects(Build): + def get_projects(self): + all_proj = [] + projects = get_model('projects', 'Project').objects.filter(status__exact=1).order_by('-pub_date') + for proj in projects: + row = {'slug':proj.slug, 'name':proj.model_name} + all_proj.append(row) + return all_proj + + def build_project_archive(self): + qs = get_model('projects', 'Project').objects.filter(status__exact=1).order_by('-pub_date') + c = Context({'object_list': qs,'MEDIA_URL':settings.MEDIA_URL,}) + t = render_to_string('archives/projects.html', c).encode('utf-8') + path = '%sprojects/' %(settings.STATIC_ROOT) + if not os.path.isdir(path): + os.makedirs(path) + fpath = '%sindex.html' %(path) + self.write_file(fpath,t) + + def build_project_details(self): + projects = self.get_projects() + for proj in projects: + model = get_model('projects', proj['name']) + if proj['name'] == 'NationalParks': + qs = model.objects.filter(visited__exact=True).order_by("-date_visited_begin") + else: + qs = model.objects.filter(status__exact=1) + c = Context({'object_list': qs,'MEDIA_URL':settings.MEDIA_URL,}) + t = render_to_string('details/%s.html' %(proj['slug']), c).encode('utf-8') + path = '%sprojects/%s/' %(settings.STATIC_ROOT, proj['slug']) + if not os.path.isdir(path): + os.makedirs(path) + fpath = '%sindex.html' %(path) + self.write_file(fpath,t) + def build_project_data(self): + from projects.shortcuts import render_to_geojson + model = get_model('projects', 'NationalParks') + for park in model.objects.filter(visited__exact=True): + qs = model.objects.filter(pk=park.id) + json = render_to_geojson( + qs, + included_fields=['id',], + geom_attribute='mpoly', + mimetype = 'application/json', + pretty_print=True + ) + json = str(json) + json ="\n".join(json.splitlines()[3:]) + #print json + path = '%sprojects/data/' %(settings.STATIC_ROOT) + if not os.path.isdir(path): + os.makedirs(path) + fpath = '%s%s.json' %(path, park.id) + self.write_file(fpath,json) + + +
\ No newline at end of file |