summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2014-11-10 20:44:49 -0500
committerluxagraf <sng@luxagraf.net>2014-11-10 20:44:49 -0500
commitf650f1860eabfb7d114513dbd0980698ca2b7f84 (patch)
treea190e56d224baeeb3c8cc7adeb4233c47646c79f
parentd283e039666fa57ccf06c3d235162927db285fb8 (diff)
reverted Pages to database
-rw-r--r--app/blog/admin.py1
-rw-r--r--app/blog/models.py36
-rw-r--r--app/builder/base.py15
-rw-r--r--app/builder/views.py18
-rw-r--r--app/notes/admin.py1
-rw-r--r--app/pages/admin.py18
-rw-r--r--app/pages/models.py90
-rw-r--r--app/pages/views.py2
-rw-r--r--config/base_urls.py10
-rw-r--r--design/sass/_global.scss9
-rw-r--r--design/sass/_writing_details.scss108
-rw-r--r--design/templates/details/about.html18
12 files changed, 198 insertions, 128 deletions
diff --git a/app/blog/admin.py b/app/blog/admin.py
index 3038a4f..c30244e 100644
--- a/app/blog/admin.py
+++ b/app/blog/admin.py
@@ -17,6 +17,7 @@ class EntryAsideAdmin(admin.ModelAdmin):
class BlogEntryForm(forms.ModelForm):
class Meta:
model = Entry
+ fields = '__all__'
widgets = {
'body_markdown': forms.Textarea(attrs={'rows': 50, 'cols': 100}),
}
diff --git a/app/blog/models.py b/app/blog/models.py
index 4ff1935..4ad6022 100644
--- a/app/blog/models.py
+++ b/app/blog/models.py
@@ -162,7 +162,6 @@ class HomepageCurrator(models.Model):
template_name = models.CharField(max_length=200,help_text="full path")
-
class BlogSitemap(Sitemap):
changefreq = "never"
priority = 1.0
@@ -183,3 +182,38 @@ class LatestFull(Feed):
def items(self):
return Entry.objects.filter(status__exact=1).order_by('-pub_date')[:10]
+
+
+import os
+import io
+import urllib.request
+import urllib.parse
+import urllib.error
+import shutil
+from django_gravatar.helpers import get_gravatar_url, has_gravatar, get_gravatar_profile_url, calculate_gravatar_hash
+from django.dispatch import receiver
+from django_comments.signals import comment_was_posted
+from django_comments import Comment
+
+@receiver(comment_was_posted, sender=Comment)
+def cache_gravatar(sender, comment, **kwargs):
+ gravatar_exists = has_gravatar(comment.email)
+ grav_dir = settings.IMAGES_ROOT + '/gravcache/'
+ print(gravatar_exists)
+ if gravatar_exists:
+ url = get_gravatar_url(comment.email, size=60)
+ if not os.path.isdir(grav_dir):
+ os.makedirs(grav_dir)
+ local_grav = '%s/%s.jpg' % (grav_dir, calculate_gravatar_hash(comment.email))
+ urllib.request.urlretrieve(url, local_grav)
+ else:
+ dest = '%s/%s.jpg' % (grav_dir, calculate_gravatar_hash(comment.email))
+ src = settings.IMAGES_ROOT + '/gravcache/default.jpg'
+ try:
+ shutil.copy(src, dest)
+ # eg. src and dest are the same file
+ except shutil.Error as e:
+ print('Error: %s' % e)
+ # eg. source or destination doesn't exist
+ except IOError as e:
+ print('Error: %s' % e.strerror)
diff --git a/app/builder/base.py b/app/builder/base.py
index 7382655..0b92832 100644
--- a/app/builder/base.py
+++ b/app/builder/base.py
@@ -7,7 +7,7 @@ from django.template import Context
from django.db.models import get_model
from django.conf import settings
-from pages.models import PageGenerator
+#from pages.models import PageGenerator
class Build():
def write_file(self, path, text_object, ext='html', filename='index'):
@@ -57,7 +57,7 @@ class BuildAll(Build):
BuildMap().build()
BuildWritingFeed().build()
BuildSitemap().build()
- p = PageGenerator(settings.PROJ_ROOT + '_pages')
+ BuildPages().build()
p.write_files()
class BuildWriting(Build):
@@ -261,6 +261,17 @@ class BuildWritingFeed(Build):
fpath = '%s' % ('rss/',)
self.write_file(fpath, t, 'xml')
+class BuildPages(Build):
+ def build(self):
+ model = get_model('pages', 'page')
+ pages = model.objects.all()
+ for page in pages:
+ c = Context({'object':page,'SITE_URL':settings.SITE_URL, 'MEDIA_URL':settings.BAKED_MEDIA_URL})
+ t = render_to_string(["details/%s.html" % page.slug, 'details/page.html'],c).encode('utf-8')
+ s = render_to_string('details/page.txt',c).encode('utf-8')
+ fpath = '%s' %(page.slug)
+ self.write_file(fpath,t)
+ self.write_file(fpath,s,'txt')
class BuildMap(Build):
def build(self):
diff --git a/app/builder/views.py b/app/builder/views.py
index 04c1285..4d820e2 100644
--- a/app/builder/views.py
+++ b/app/builder/views.py
@@ -1,14 +1,14 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.conf import settings
-from builder.base import BuildWriting, BuildWritingFeed, BuildMap, BuildPhotos, BuildProjects, BuildSitemap
-from pages.models import PageGenerator
+from builder.base import BuildWriting, BuildWritingFeed, BuildMap, BuildPhotos, BuildProjects, BuildSitemap, BuildPages
+#from pages.models import PageGenerator
options = {
'writing': BuildWriting,
'photo_galleries': BuildPhotos,
'projects': BuildProjects,
- 'pages': PageGenerator,
+ 'pages': BuildPages,
'map': BuildMap,
'feed': BuildWritingFeed,
'sitemap': BuildSitemap,
@@ -24,10 +24,6 @@ def do_build(request):
BuildWritingFeed().build()
BuildSitemap().build()
context = {'message': 'Writing %s to Disk' % section}
- elif section == 'pages':
- p = PageGenerator(settings.PROJ_ROOT + '_pages')
- p.write_files()
- context = {'message': 'Building pages from flatfiles'}
elif section == 'scrapeflickr':
from photos import retriever
retriever.sync_sets()
@@ -36,3 +32,11 @@ def do_build(request):
options[section]().build()
context = {'message': 'Writing %s to Disk' % section}
return render_to_response('admin/message.html', context, context_instance=RequestContext(request))
+
+
+"""
+elif section == 'pages':
+ p = PageGenerator(settings.PROJ_ROOT + '_pages')
+ p.write_files()
+ context = {'message': 'Building pages from flatfiles'}
+"""
diff --git a/app/notes/admin.py b/app/notes/admin.py
index 3bbdc8d..ad3e84b 100644
--- a/app/notes/admin.py
+++ b/app/notes/admin.py
@@ -9,6 +9,7 @@ class NoteModelForm(forms.ModelForm):
class Meta:
model = Note
+ fields = '__all__'
class NoteAdmin(OSMGeoAdmin):
diff --git a/app/pages/admin.py b/app/pages/admin.py
index 66e4d8f..844007e 100644
--- a/app/pages/admin.py
+++ b/app/pages/admin.py
@@ -1,13 +1,22 @@
from django.contrib import admin
+from django import forms
from django.forms import Textarea
from django.db import models
-'''
+from pages.models import Page
+
+class PageEntryForm(forms.ModelForm):
+ class Meta:
+ model = Page
+ fields = '__all__'
+ widgets = {
+ 'body_markdown': forms.Textarea(attrs={'rows': 50, 'cols': 100}),
+ }
+
class PageAdmin(admin.ModelAdmin):
- formfield_overrides = {
- models.TextField: {'widget': Textarea(attrs={'rows': 25, 'cols': 40})},
- }
+ form = PageEntryForm
+
list_display = ('title', 'slug',)
search_fields = ['title', 'body_markdown']
prepopulated_fields = {"slug": ('title',)}
@@ -23,4 +32,3 @@ class PageAdmin(admin.ModelAdmin):
)
admin.site.register(Page, PageAdmin)
-'''
diff --git a/app/pages/models.py b/app/pages/models.py
index 3ef1a71..832b958 100644
--- a/app/pages/models.py
+++ b/app/pages/models.py
@@ -1,16 +1,8 @@
from django.db import models
from django.contrib.sitemaps import Sitemap
import markdown
-
-
-import os
-import yaml
-from django.conf import settings
-from django.template.loader import render_to_string
-from django.template import Context
from mdx_attr_list.mdx_attr_list import AttrListExtension
-
def markdown_processor(txt):
md = markdown.Markdown(
extensions=[AttrListExtension(),'footnotes',],
@@ -18,7 +10,7 @@ def markdown_processor(txt):
safe_mode=False
)
return md.convert(txt)
-'''
+
class Page(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField()
@@ -36,7 +28,7 @@ class Page(models.Model):
#run markdown
self.body_html = markdown_processor(self.body_markdown)
super(Page, self).save()
-'''
+
class PageSitemap(Sitemap):
changefreq = "never"
@@ -44,80 +36,4 @@ class PageSitemap(Sitemap):
protocol = "https"
def items(self):
- p = PageGenerator(settings.PROJ_ROOT + '_pages')
- return p.objects(include_in_sitemap=True)
- #return Page.objects.all()
-
-
-class PageGenerator(object):
-
- def __init__(self, path, *args, **kwargs):
- self._objects = []
- for (dirpath, dirnames, filenames) in os.walk(path):
- self.dirpath = dirpath
- self.file_list = filter(lambda item: not (item.startswith('.') or item.endswith('~') or item.endswith('.md')), filenames)
- self.get_files()
-
- def get_files(self):
- for f in self.file_list:
- p = Page(self.dirpath + '/' + f)
- self._objects.append(p)
-
- def objects(self, *args, **kwargs):
- filtered_list = []
- if kwargs:
- for item in self._objects:
- found = False
- for k, v in kwargs.items():
- if getattr(item, k) == v and not found:
- found = True
- filtered_list.append(item)
- elif getattr(item, k) != v and found:
- filtered_list.remove(item)
- return filtered_list
- return self._objects
-
- def write_files(self):
- for obj in self.objects():
- c = Context({'object': obj, 'SITE_URL': settings.SITE_URL})
- t = render_to_string(["details/%s.html" % obj.template], c)
- s = render_to_string('details/page.txt', c)
- _FileWriter('', t, ext="html", filename=obj.slug)
- _FileWriter('', s, ext="txt", filename=obj.slug)
-
-
-class _FileWriter(object):
- """
- Given a path and text object; write the page to disc
- """
- def __init__(self, path, text_object, ext='html', filename='index'):
- self.path = '%s%s' % (settings.FLATFILES_ROOT, path)
- if not os.path.isdir(self.path):
- os.makedirs(self.path)
- fpath = '%s%s.%s' % (self.path, filename, ext)
- self.write(fpath, text_object)
-
- def write(self, fpath, text_object):
- file = open(fpath, 'wb')
- file.write(text_object.encode('utf-8'))
- file.close()
-
-
-class _FileLoader(object):
-
- def __init__(self, filename, *args, **kwargs):
- self.filename = filename
- metadata = self.read()
- for k, v in metadata.items():
- setattr(self, k, v)
- if self.body_markdown:
- self.body_html = markdown_processor(self.body_markdown)
-
- def read(self):
- with open(self.filename, "r", encoding="utf-8") as f:
- contents = f.read()
- metayaml, self.body_markdown = contents.split('\n---')
- return yaml.load(metayaml)
-
-class Page(_FileLoader):
- pass
+ return Page.objects.all()
diff --git a/app/pages/views.py b/app/pages/views.py
index e933399..934cb40 100644
--- a/app/pages/views.py
+++ b/app/pages/views.py
@@ -3,6 +3,6 @@ from django.template import RequestContext
from pages.models import Page
def page(request, slug):
- obj = "" #get_object_or_404(Page, slug__exact=slug)
+ obj = get_object_or_404(Page, slug__exact=slug)
context = {'object': obj, }
return render_to_response(["details/%s.html" % obj.slug, 'details/page.html'], context, context_instance=RequestContext(request))
diff --git a/config/base_urls.py b/config/base_urls.py
index 2aa6bf0..56612ff 100644
--- a/config/base_urls.py
+++ b/config/base_urls.py
@@ -63,7 +63,7 @@ urlpatterns += patterns('',
#homepage
(r'^$', 'blog.views.home'),
#pages
- #(r'^(?P<slug>[-\w]+)/$', 'pages.views.page'),
+ (r'^(?P<slug>[-\w]+)/?$', 'pages.views.page'),
)
@@ -72,6 +72,8 @@ urlpatterns += patterns('',
{'document_root': settings.STATIC_ROOT, }
),
)
-#urlpatterns += patterns('',
-# #url(r'^blog/comments/', include('fluent_comments.urls')),
-#)
+urlpatterns += patterns('',
+ (r'^comments/', include('django_comments.urls')),
+ #url(r'^comments/', include('django_comments_xtd.urls'))
+ #url(r'^comments/', include('fluent_comments.urls')),
+)
diff --git a/design/sass/_global.scss b/design/sass/_global.scss
index 5051d3d..c65c21a 100644
--- a/design/sass/_global.scss
+++ b/design/sass/_global.scss
@@ -90,11 +90,11 @@ h1 {
.mailing-list--wrapper {
@include constrain_narrow;
@include breakpoint(gamma) {
- margin-top: 6em;
+ margin-top: 3em;
max-width: 580px;
h5 {
margin-bottom: .5em;
- margin-top: 5em;
+ margin-top: 2em;
}
}
h5 {
@@ -107,7 +107,10 @@ h1 {
margin-top: 5em;
}
}
-
+.divide-after:after {
+ margin-bottom: 3em;
+ @include faded_line_after;
+}
//**************** Page Breadcrumbs ************************
#breadcrumbs {
diff --git a/design/sass/_writing_details.scss b/design/sass/_writing_details.scss
index d0101ac..09fc6bb 100644
--- a/design/sass/_writing_details.scss
+++ b/design/sass/_writing_details.scss
@@ -115,6 +115,12 @@
.picfull {
margin-top: 20px;
}
+.picfullv {
+ margin-top: 20px;
+margin-left: auto;
+margin-right: auto;
+display: block;
+}
.picwide {
clear: both;
margin: 1em 0;
@@ -224,6 +230,108 @@
}
}
+//### COMMENTS AND FORMS ###
+.comments--header {
+ font-family: Helvetica Neue, Helvetica, sans-serif;
+ line-height: 6em;
+ @include fontsize(24);
+ &:before {
+ @include faded_line_after;
+ margin-top: 2em;
+ }
+}
+.comments--wrapper {
+ @include constrain_narrow();
+ text-align: left;
+ margin-top: -2em;
+}
+.comment {
+ margin-top: 2.5em;
+ margin-bottom: 2.5em;
+ &:first-child {
+ margin-top: none;
+ }
+ &:after {
+ @include faded_line_after;
+ }
+ &:last-child:after {
+ display: none;
+ }
+}
+.comment--head, .comment--body {
+ margin-left: 80px;
+}
+.comment--head {
+ margin-bottom: 1em;
+}
+.comment--body {
+ margin-bottom: 3em;
+}
+.who {
+ font-family: Helvetica Neue, Helvetica, sans-serif;
+ @include fontsize(18);
+}
+.when {
+ @include fontsize(13);
+ margin-left: 1em;
+ font-style: italic;
+}
+
+.gravatar {
+ border: 2px $brown solid;
+ background: transparent;
+ max-width: 100%;
+ padding: 0;
+ float: left;
+ margin-top: 5px;
+}
+
+
+.comment--form--wrapper {
+ @include constrain_narrow();
+ &:before {
+ @include faded_line_after;
+ }
+}
+.comment--form--header {
+ margin-top: 2em;
+}
+.comment--form {
+ margin: 0 auto;
+ @include breakpoint(delta) {
+ margin-left: 20%
+ }
+ label {
+ display: block;
+ font-weight: 500;
+ letter-spacing: 1px;
+ font-family: "Helvetica Neue Light","Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;
+ @include fontsize(13);
+ }
+ input, textarea {
+ padding: .25em;
+ border: #c5c5c5 1px solid;
+ border-radius: .125em;
+ color: darken($body_font_light, 20);
+ width: 100%;
+ @include breakpoint(gamma) {
+ width: 70%;
+ }
+ }
+ input[type="submit"] {
+ width: auto;
+ color: white;
+ letter-spacing: 1px;
+ background: $orange;
+ font: bold .65em Verdana,sans-serif;
+ text-transform: uppercase;
+ border: none;
+ border-radius: .25em;
+ padding: 8px 12px 7px;
+ }
+}
+
+
// ##############################################
// On double and double-dark make the top wide
// with two columns of text (nothing for ie9-
diff --git a/design/templates/details/about.html b/design/templates/details/about.html
deleted file mode 100644
index f627a3c..0000000
--- a/design/templates/details/about.html
+++ /dev/null
@@ -1,18 +0,0 @@
-{% extends 'base.html' %}
-{% load typogrify_tags %}
-{% block pagetitle %}Luxagraf | About{% endblock %}
-{% block metadescription %}About: Luxagraf is written and published by Scott Gilbertson. Writing is done in notebooks, later Vim, and published to the web with GeoDjango. Photos taken with a Panasonic GF1.{% endblock %}
-{%block htmlclass%}class="single"{%endblock%}
-{%block bodyid%}id="about"{%endblock%}
-
-{% block primary %}<ul class="bl" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
- <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> &rarr; </li>
- <li>About</li>
- </ul>
- <article role="main">
- <h1 class="hide">About Luxagraf</h1>
- <div class="post-body-single">
- {{object.body_html|safe|smartypants|widont}}
- </div>
- </article>
-{% endblock %}