summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/TODO8
-rw-r--r--app/src/admin.py27
-rw-r--r--app/src/build.py91
-rw-r--r--app/src/models.py56
-rw-r--r--app/src/urls.py65
-rw-r--r--app/src/views.py89
6 files changed, 247 insertions, 89 deletions
diff --git a/app/src/TODO b/app/src/TODO
index 6fa16fa..9cb5989 100644
--- a/app/src/TODO
+++ b/app/src/TODO
@@ -1,3 +1,7 @@
-add book detail page.
-redirect home book and rss
+clean up design of book detail
+add paypal app and generate button
+handle callbacks from paypal to deliver the book and link to files
+
+
+redirect lhp: home, book and rss
diff --git a/app/src/admin.py b/app/src/admin.py
index 558528d..31c0255 100644
--- a/app/src/admin.py
+++ b/app/src/admin.py
@@ -2,11 +2,34 @@ from django.contrib import admin
from .models import Topic, Entry, Book
from jrnl.admin import BlogEntryForm
+
class TopicAdmin(admin.ModelAdmin):
- prepopulated_fields = {"slug": ('name',), "pluralized_name":('name',)}
+ prepopulated_fields = {"slug": ('name',), "pluralized_name": ('name',)}
+
class BookAdmin(admin.ModelAdmin):
- prepopulated_fields = {"slug": ('title',),}
+ prepopulated_fields = {"slug": ('title', )}
+ list_display = ('title', 'pub_date', 'status')
+ fieldsets = (
+ ('Entry', {
+ 'fields': (
+ 'title',
+ 'body_markdown',
+ 'image',
+ ('pub_date', 'status'),
+ ('price', 'price_sale'),
+ 'meta_description',
+ ('slug', 'template_name'),
+ ),
+ 'classes': (
+ 'show',
+ 'extrapretty',
+ 'wide'
+ )
+ }
+ ),
+ )
+
class EntryAdmin(admin.ModelAdmin):
form = BlogEntryForm
diff --git a/app/src/build.py b/app/src/build.py
index a60f80c..6fe1f17 100644
--- a/app/src/build.py
+++ b/app/src/build.py
@@ -1,51 +1,58 @@
-from builder.base import *
-from .models import Topic, Entry
+import os
+from builder.base import BuildNew
+from django.core.urlresolvers import reverse
+from . import models
-class BuildSrc(Build):
+class BuildSrc(BuildNew):
+
def build(self):
- self.build_archive()
- self.build_topic_archive()
- self.build_detail_pages()
- self.build_feed()
-
- def build_detail_pages(self):
- '''
- Grab all the notes, render them to a template string and write that out to the filesystem
- '''
- for entry in Entry.objects.filter(status__exact=1):
- c = Context({'object': entry, 'MEDIA_URL': settings.BAKED_MEDIA_URL, 'IMAGES_URL': settings.BAKED_IMAGES_URL, 'SITE_URL':settings.SITE_URL})
- t = render_to_string('details/src_entry.html', c).encode('utf-8')
- path = 'src/'
- self.write_file(path, t, 'html', entry.slug)
- s = render_to_string('details/note.txt', c).encode('utf-8')
- self.write_file(path, s, 'txt', entry.slug)
-
- def build_archive(self):
- path = 'src/'
+ self.build_list_view(
+ base_path=reverse("src:list"),
+ )
+ self.build_list_view(
+ base_path=reverse("src:list_books"),
+ )
+ self.build_detail_view()
+ # These are the unique classes for this model:
+ self.build_books_view()
+ self.build_topic_view()
+ self.build_feed("src:feed")
+
+ def build_topic_view(self):
+ for topic in models.Topic.objects.all():
+ url = reverse("src:list_topics", kwargs={'slug': topic.slug, })
+ path, slug = os.path.split(url)
+ response = self.client.get(url, HTTP_HOST='127.0.0.1')
+ self.write_file('%s/' % path, response.content, filename=slug)
+
+ def build_books_view(self):
+ for obj in models.Book.objects.all():
+ url = reverse("src:detail_book", kwargs={'slug': obj.slug, })
+ path, slug = os.path.split(url)
+ response = self.client.get(url, HTTP_HOST='127.0.0.1')
+ self.write_file('%s/' % path, response.content, filename=slug)
+
+
+
+def builder():
+ j = BuildSrc("src", "entry")
+ j.build()
+
+
+"""
+
+
+
+
+ def build_books(self):
+ path = 'src/books/'
c = Context({
- 'object_list': Entry.objects.filter(status__exact=1),
+ 'object_list': Book.objects.filter(status__exact=1),
'MEDIA_URL': settings.BAKED_MEDIA_URL,
'IMAGES_URL': settings.BAKED_IMAGES_URL
})
- t = render_to_string('archives/src_home.html', c).encode('utf-8')
+ t = render_to_string('archives/src_books.html', c).encode('utf-8')
self.write_file(path, t)
- def build_topic_archive(self):
- for topic in Topic.objects.all():
- path = 'src/topic/'
- c = Context({
- 'object_list': Entry.objects.filter(topics__slug=topic.slug),
- 'topic': topic,
- 'MEDIA_URL': settings.BAKED_MEDIA_URL,
- 'IMAGES_URL': settings.BAKED_IMAGES_URL
- })
- t = render_to_string('archives/src_home.html', c).encode('utf-8')
- self.write_file(path, t, 'html', topic.slug)
-
- def build_feed(self):
- qs = Entry.objects.filter(status__exact=1)
- c = Context({'object_list': qs, 'SITE_URL': settings.SITE_URL})
- t = render_to_string('feed.xml', c).encode('utf-8')
- fpath = '%s' % ('/src/rss/',)
- self.write_file(fpath, t, 'xml')
+"""
diff --git a/app/src/models.py b/app/src/models.py
index ea70d86..e5b2f54 100644
--- a/app/src/models.py
+++ b/app/src/models.py
@@ -1,15 +1,17 @@
from django.db import models
from django.contrib.sitemaps import Sitemap
from django.contrib.syndication.views import Feed
-from blog.models import image_url_replace, extract_images
+from jrnl.models import image_url_replace, extract_images
import markdown
import datetime
+from itertools import chain
+
class Topic(models.Model):
name = models.CharField(max_length=60)
slug = models.SlugField()
pluralized_name = models.CharField(max_length=60)
-
+
def __str__(self):
return self.name
@@ -20,6 +22,7 @@ class Topic(models.Model):
def pub_date(self):
return datetime.datetime.now()
+
class Entry(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(unique_for_date='pub_date')
@@ -55,7 +58,6 @@ class Entry(models.Model):
def comment_period_open(self):
return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date
-
def get_images(self):
return extract_images(self.body_html)
@@ -71,7 +73,12 @@ class Entry(models.Model):
def save(self):
md = image_url_replace(self.body_markdown)
- self.body_html = markdown.markdown(md, extensions=['markdown.extensions.codehilite(css_class=highlight,linenums=False)', 'markdown.extensions.fenced_code', 'markdown.extensions.attr_list','extra'], safe_mode=False)
+ self.body_html = markdown.markdown(md, extensions=[
+ 'markdown.extensions.codehilite(css_class=highlight,linenums=False)',
+ 'markdown.extensions.fenced_code',
+ 'markdown.extensions.attr_list',
+ 'extra'
+ ], safe_mode=False)
super(Entry, self).save()
@@ -91,8 +98,21 @@ class Book(models.Model):
(0, 'Draft'),
(1, 'Published'),
)
+ price = models.FloatField()
+ price_sale = models.FloatField()
status = models.IntegerField(choices=PUB_STATUS, default=0)
meta_description = models.CharField(max_length=256, null=True, blank=True)
+ DEFAULT = 'details/src_book.html'
+ BOOK2 = 'details/src_book_2.html'
+ TEMPLATES = (
+ (DEFAULT, 'Default'),
+ (BOOK2, 'Book Two'),
+ )
+ template_name = models.CharField(
+ max_length=200,
+ choices=TEMPLATES,
+ default=DEFAULT
+ )
class Meta:
ordering = ('-pub_date',)
@@ -104,19 +124,16 @@ class Book(models.Model):
def get_absolute_url(self):
return "/src/books/%s" % (self.slug)
+ def save(self):
+ md = image_url_replace(self.body_markdown)
+ self.body_html = markdown.markdown(md, extensions=[
+ 'markdown.extensions.codehilite(css_class=highlight,linenums=False)',
+ 'markdown.extensions.fenced_code',
+ 'markdown.extensions.attr_list',
+ 'extra'
+ ], safe_mode=False)
+ super(Book, self).save()
-class LatestFull(Feed):
- title = "luxagraf:src Code and Technology"
- link = "/src/"
- description = "Latest postings to luxagraf.net/src"
- description_template = 'feeds/blog_description.html'
-
- def items(self):
- return Entry.objects.filter(status__exact=1).order_by('-pub_date')[:10]
-
-
-
-from itertools import chain
class SrcSitemap(Sitemap):
changefreq = "never"
@@ -124,8 +141,11 @@ class SrcSitemap(Sitemap):
protocol = "https"
def items(self):
- return list(chain(Entry.objects.all(), Book.objects.all(), Topic.objects.all()))
-
+ return list(chain(
+ Entry.objects.all(),
+ Book.objects.all(),
+ Topic.objects.all()
+ ))
def lastmod(self, obj):
return obj.pub_date
diff --git a/app/src/urls.py b/app/src/urls.py
index a2368e3..217912c 100644
--- a/app/src/urls.py
+++ b/app/src/urls.py
@@ -1,17 +1,52 @@
-from django.conf.urls import *
-from django.views.generic import ListView
+from django.conf.urls import url, include
-from .models import Entry, Book
+from . import views
-urlpatterns = patterns('',
- (r'topic/(?P<slug>[-\w]+)/$', 'src.views.topic'),
- (r'books/$', ListView.as_view(
- queryset=Book.objects.filter(status__exact=1).order_by('-pub_date'),
- template_name="archives/src_books.html",
- )),
- (r'(?P<slug>[-\w]+)/$', 'src.views.detail'),
- (r'^$', ListView.as_view(
- queryset=Entry.objects.filter(status__exact=1).order_by('-pub_date'),
- template_name="archives/src_home.html",
- )),
-)
+
+urlpatterns = [
+ url(
+ regex=r'^feed.xml',
+ view=views.SrcRSSFeedView(),
+ name="feed"
+ ),
+ url(
+ r'^something/paypal/',
+ include('paypal.standard.ipn.urls'),
+ name="paypal-ipn"
+ ),
+ url(
+ regex=r'topic/(?P<slug>[-\w]+)$',
+ view=views.TopicListView.as_view(),
+ name="list_topics"
+ ),
+ url(
+ regex=r'books/(?P<slug>[-\w]+)$',
+ view=views.BookDetailView.as_view(),
+ name='detail_book'
+ ),
+ url(
+ regex=r'books/$',
+ view=views.BookListView.as_view(),
+ name='list_books'
+ ),
+ url(
+ regex=r'(?P<slug>[-\w]+).txt$',
+ view=views.EntryDetailViewTXT.as_view(),
+ name="detail-txt"
+ ),
+ url(
+ regex=r'(?P<slug>[-\w]+).amp$',
+ view=views.EntryDetailViewAMP.as_view(),
+ name="detail-amp"
+ ),
+ url(
+ regex=r'(?P<slug>[-\w]+)$',
+ view=views.EntryDetailView.as_view(),
+ name="detail"
+ ),
+ url(
+ regex=r'^$',
+ view=views.SrcListView.as_view(),
+ name="list",
+ ),
+]
diff --git a/app/src/views.py b/app/src/views.py
index ceba079..95ddafa 100644
--- a/app/src/views.py
+++ b/app/src/views.py
@@ -1,15 +1,84 @@
-from django.shortcuts import render_to_response, get_object_or_404
-from django.template import RequestContext
-from .models import Entry, Topic
+from django.views.generic import ListView
+from django.views.generic.detail import DetailView
+from django.contrib.syndication.views import Feed
+from django.core.urlresolvers import reverse
+from django.conf import settings
+from paypal.standard.forms import PayPalPaymentsForm
-def topic(request, slug):
- obj = get_object_or_404(Topic, slug__exact=slug)
- qs = Entry.objects.filter(topics__slug=slug).order_by('-pub_date')
- return render_to_response('archives/src_home.html', {'object_list': qs, 'topic':obj}, context_instance=RequestContext(request))
+from .models import Entry, Topic, Book
-def detail(request, slug):
- obj = get_object_or_404(Entry, slug__exact=slug)
- return render_to_response('details/src_entry.html', {'object': obj}, context_instance=RequestContext(request))
+class BookListView(ListView):
+ template_name = "archives/src_books.html"
+ def queryset(self):
+ return Book.objects.filter(status__exact=1)
+
+
+class BookDetailView(DetailView):
+ model = Book
+
+ def get_template_names(self):
+ book = self.get_object()
+ return [book.template_name]
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(BookDetailView, self).get_context_data(**kwargs)
+ book = self.get_object()
+ paypal_dict = {
+ "business": settings.PAYPAL_RECEIVER_EMAIL,
+ "amount": book.price,
+ "item_name": book.title,
+ "invoice": "unique-invoice-id",
+ "notify_url": "https://www.example.com" + reverse('src:paypal-ipn'),
+ "return_url": "https://www.example.com/your-return-location/",
+ "cancel_return": "https://www.example.com/your-cancel-location/",
+ }
+ context['paypal_form'] = PayPalPaymentsForm(initial=paypal_dict)
+ return context
+
+
+class SrcListView(ListView):
+ template_name = "archives/src_home.html"
+
+ def queryset(self):
+ return Entry.objects.filter(status__exact=1)
+
+
+class EntryDetailView(DetailView):
+ model = Entry
+ template_name = "details/src_entry.html"
+ slug_field = "slug"
+
+
+class EntryDetailViewTXT(EntryDetailView):
+ template_name = "details/entry.txt"
+
+
+class EntryDetailViewAMP(EntryDetailView):
+ template_name = "details/src_entry.amp"
+
+
+class TopicListView(ListView):
+ template_name = 'archives/src_home.html'
+
+ def queryset(self):
+ return Entry.objects.filter(topics__slug=self.kwargs['slug'])
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(TopicListView, self).get_context_data(**kwargs)
+ context['topic'] = Topic.objects.get(slug__exact=self.kwargs['slug'])
+ return context
+
+
+class SrcRSSFeedView(Feed):
+ title = "luxagraf:src Code and Technology"
+ link = "/src/"
+ description = "Latest postings to luxagraf.net/src"
+ description_template = 'feeds/blog_description.html'
+
+ def items(self):
+ return Entry.objects.filter(status__exact=1).order_by('-pub_date')[:10]