diff options
Diffstat (limited to 'app/posts/views')
-rw-r--r-- | app/posts/views/__init__.py | 19 | ||||
-rw-r--r-- | app/posts/views/field_note_views.py | 39 | ||||
-rw-r--r-- | app/posts/views/guide_views.py | 96 | ||||
-rw-r--r-- | app/posts/views/jrnl_views.py | 173 | ||||
-rw-r--r-- | app/posts/views/src_views.py | 97 |
5 files changed, 424 insertions, 0 deletions
diff --git a/app/posts/views/__init__.py b/app/posts/views/__init__.py new file mode 100644 index 0000000..5fd984c --- /dev/null +++ b/app/posts/views/__init__.py @@ -0,0 +1,19 @@ +from django.contrib.syndication.views import Feed + +from ..models import Post + +class PostRSSFeedView(Feed): + title = "Luxagraf: Topographical Writings" + link = "https://luxagraf.net/" + description = "Latest postings to luxagraf.net" + description_template = 'feeds/blog_description.html' + + def items(self): + return Post.objects.filter(status__exact=1).order_by('-pub_date')[:10] + + def item_pubdate(self, item): + """ + Takes an item, as returned by items(), and returns the item's + pubdate. + """ + return item.pub_date diff --git a/app/posts/views/field_note_views.py b/app/posts/views/field_note_views.py new file mode 100644 index 0000000..41ceeaa --- /dev/null +++ b/app/posts/views/field_note_views.py @@ -0,0 +1,39 @@ +from django.views.generic.dates import YearArchiveView, MonthArchiveView +from django.views.generic.detail import DetailView + +from utils.views import PaginatedListView, LuxDetailView + +from ..models import Post, PostType + + +class FieldNoteListView(PaginatedListView): + model = Post + template_name = "posts/fieldnote_list.html" + """ + Return a list of Notes in reverse chronological order + """ + queryset = Post.objects.filter(post_type=PostType.FIELD_NOTE,status=1).order_by('-pub_date') + + +class FieldNoteDetailView(LuxDetailView): + model = Post + slug_field = "slug" + template_name = "posts/fieldnote_detail.html" + + +class FieldNoteDetailViewTXT(FieldNoteDetailView): + template_name = "posts/entry_detail.txt" + + +class FieldNoteYearArchiveView(YearArchiveView): + queryset = Post.objects.filter(post_type=PostType.FIELD_NOTE,status=1) + date_field = "pub_date" + template_name = "posts/fieldnote_archive_list_date.html" + make_object_list = True + + +class FieldNoteMonthArchiveView(MonthArchiveView): + queryset = Post.objects.filter(post_type=PostType.FIELD_NOTE,status=1) + date_field = "pub_date" + make_object_list = True + template_name = "posts/fieldnote_archive_list_date.html" diff --git a/app/posts/views/guide_views.py b/app/posts/views/guide_views.py new file mode 100644 index 0000000..e2f98f3 --- /dev/null +++ b/app/posts/views/guide_views.py @@ -0,0 +1,96 @@ +from django.views.generic import ListView +from django.views.generic.detail import DetailView +from django.contrib.syndication.views import Feed +from django.apps import apps +from django.conf import settings + +from utils.views import PaginatedListView, LuxDetailView + +from ..models import Post, PostType +from taxonomy.models import Category + + +class GuideListView(PaginatedListView): + """ + Return a list of Entries in reverse chronological order + """ + model = Post + template_name = "posts/guide_base.html" + + def get_queryset(self): + queryset = super(GuideListView, self).get_queryset() + return queryset.filter(status__exact=1).filter(post_type__in=[PostType.REVIEW,PostType.FIELD_TEST]).order_by('-pub_date').prefetch_related('location').prefetch_related('featured_image') + + +class ReviewsListView(GuideListView): + template_name = "posts/post.html" + + def get_queryset(self): + queryset = super(ReviewsListView, self).get_queryset() + return queryset.filter(post_type__in=[0,1]).filter(status__exact=1).order_by('-pub_date').prefetch_related('location').prefetch_related('featured_image') + + def get_context_data(self, **kwargs): + context = super(ReviewsListView, self).get_context_data(**kwargs) + context['archive_type'] = 'Field Tests' + return context + + +class EssayListView(PaginatedListView): + model = Post + template_name = "posts/essay_list.html" + + def get_queryset(self): + queryset = super(EssayListView, self).get_queryset() + return queryset.filter(site__domain='luxagraf.net').filter(post_type__in=[PostType.ESSAY]).filter(status__exact=1).order_by('-pub_date').prefetch_related('location').prefetch_related('featured_image') + + def get_context_data(self, **kwargs): + ''' + override for custom breadcrumb path + ''' + # Call the base implementation first to get a context + context = super(EssayListView, self).get_context_data(**kwargs) + context['breadcrumbs'] = ('Essays',) + return context + + +class PostDetailView(LuxDetailView): + model = Post + slug_field = "slug" + + def get_queryset(self): + queryset = super(PostDetailView, self).get_queryset() + return queryset.select_related('location').prefetch_related('field_notes') + + def get_context_data(self, **kwargs): + context = super(PostDetailView, self).get_context_data(**kwargs) + related = [] + for obj in self.object.related.all(): + model = apps.get_model(obj.post_model.app_label, obj.post_model.model) + related.append(model.objects.get(slug=obj.slug)) + context['related'] = related + return context + + def get_template_names(self): + obj = self.get_object() + return ["posts/%s_detail.html" % obj.get_post_type_display(), 'posts/post_detail.html'] + + +class PostDetailViewTXT(PostDetailView): + template_name = "posts/entry_detail.txt" + + +class PostsRSSFeedView(Feed): + title = "VanLifeReviews.com: " + link = "/" + description = "Latest reviews, stories and guides" + description_template = 'feeds/blog_description.html' + + def items(self): + return Post.objects.filter(status__exact=1).order_by('-pub_date')[:10] + + def item_pubdate(self, item): + """ + Takes an item, as returned by items(), and returns the item's + pubdate. + """ + return item.pub_date diff --git a/app/posts/views/jrnl_views.py b/app/posts/views/jrnl_views.py new file mode 100644 index 0000000..0dc2dc8 --- /dev/null +++ b/app/posts/views/jrnl_views.py @@ -0,0 +1,173 @@ +from django.views.generic import ListView +from django.views.generic.detail import DetailView +from django.views.generic.dates import DateDetailView +from django.urls import reverse +from django.views.generic.dates import YearArchiveView, MonthArchiveView +from django.contrib.syndication.views import Feed +from django.apps import apps +from django.shortcuts import get_object_or_404 +from django.conf import settings +from django.db.models import Q + +from utils.views import PaginatedListView + +#from ..models import Entry, HomepageCurrator, Home +from ..models import Post, PostType +from locations.models import LuxCheckIn, Country, Region, Location +from sightings.models import Sighting + + +class JrnlListView(PaginatedListView): + """ + Return a list of Entries in reverse chronological order + """ + model = Post + template_name = "posts/jrnl_list.html" + queryset = Post.objects.filter(post_type=PostType.JRNL).filter(status__exact=1).order_by('-pub_date').prefetch_related('location').prefetch_related('featured_image') + + def get_context_data(self, **kwargs): + context = super(JrnlListView, self).get_context_data(**kwargs) + context['breadcrumbs'] = ['jrnl',] + return context + +class JrnlCountryListView(PaginatedListView): + """ + Return a list of Entries by Country in reverse chronological order + """ + model = Post + template_name = "posts/jrnl_list.html" + + def get_context_data(self, **kwargs): + # Call the base implementation first to get a context + context = super(JrnlCountryListView, self).get_context_data(**kwargs) + try: + context['region'] = Country.objects.get(slug__exact=self.kwargs['slug']) + except: + context['region'] = Region.objects.get(slug__exact=self.kwargs['slug']) + context['breadcrumbs'] = ['jrnl',] + return context + + def get_queryset(self): + try: + region = Country.objects.get(slug__exact=self.kwargs['slug']) + qs = Post.objects.filter( + post_type=PostType.JRNL, + status__exact=1, + location__state__country=region + ).order_by('-pub_date') + except: + region = Region.objects.get(slug__exact=self.kwargs['slug']) + qs = Post.objects.filter( + post_type=PostType.JRNL, + status__exact=1, + location__state__country__lux_region=region.id + ).order_by('-pub_date') + return qs + + +class JrnlYearArchiveView(YearArchiveView): + queryset = Post.objects.filter(status__exact=1).filter(post_type=PostType.JRNL).select_related() + date_field = "pub_date" + make_object_list = True + allow_future = True + template_name = "posts/jrnl_date.html" + + +class JrnlMonthArchiveView(MonthArchiveView): + queryset = Post.objects.filter(status__exact=1).filter(post_type=PostType.JRNL).select_related() + date_field = "pub_date" + allow_future = True + template_name = "posts/jrnl_date.html" + + +class JrnlDetailView(DateDetailView): + model = Post + date_field = 'pub_date' + slug_field = "slug" + template_name = "posts/jrnl_detail.html" + + def get_queryset(self): + queryset = super(JrnlDetailView, self).get_queryset() + return queryset.filter(post_type=PostType.JRNL).select_related('location').prefetch_related('field_notes').prefetch_related('books') + + def get_object(self, queryset=None): + obj = get_object_or_404( + self.model, + slug=self.kwargs['slug'], + pub_date__month=self.kwargs['month'], + pub_date__year=self.kwargs['year'] + ) + self.location = obj.location + return obj + + def get_context_data(self, **kwargs): + context = super(JrnlDetailView, self).get_context_data(**kwargs) + context['wildlife'] = Sighting.objects.filter( + Q(location=self.location) | + Q(location__in=Location.objects.filter(parent=self.location)) + ).select_related().order_by('ap_id', 'ap__apclass__kind').distinct("ap") + related = [] + for obj in self.object.related.all(): + model = apps.get_model(obj.model_name.app_label, obj.model_name.model) + related.append(model.objects.get(slug=obj.slug, pub_date=obj.pub_date)) + context['related'] = related + context['breadcrumbs'] = ("jrnl",) + context['crumb_url'] = reverse('jrnl:list') + return context + + +class JrnlDetailViewTXT(JrnlDetailView): + template_name = "posts/jrnl_detail.txt" + + +class JrnlLatestView(JrnlDetailView): + template_name = "posts/jrnl_latest.html" + + def get_object(self, queryset=None): + obj = self.model.objects.filter(status=1).latest() + self.location = obj.location + return obj + + +class JrnlRSSFeedView(Feed): + title = "Luxagraf: Topographical Writings" + link = "/jrnl/" + description = "Latest postings to luxagraf.net" + description_template = 'feeds/blog_description.html' + + def items(self): + return Post.objects.filter(status__exact=1).filter(post_type=PostType.JRNL).order_by('-pub_date')[:10] + + def item_pubdate(self, item): + """ + Takes an item, as returned by items(), and returns the item's + pubdate. + """ + return item.pub_date + +''' +class HomepageList(ListView): + """ + Return a main entry and list of Entries in reverse chronological order + """ + model = Entry + + def get_home(self): + return Home.objects.filter(pk=1).prefetch_related('featured_image').select_related('featured').select_related('featured__location').get() + + def get_queryset(self): + queryset = super(HomepageList, self).get_queryset() + self.home = self.get_home() + return queryset.filter(status__exact=1).order_by('-pub_date').exclude().select_related('location').select_related('featured_image')[1:9] + + def get_template_names(self): + return ['%s' % self.home.template_name] + + def get_context_data(self, **kwargs): + # Call the base implementation first to get a context + context = super(HomepageList, self).get_context_data(**kwargs) + context['homepage'] = self.home + context['location'] = LuxCheckIn.objects.latest() + context['IMAGES_URL'] = settings.IMAGES_URL + return context +''' diff --git a/app/posts/views/src_views.py b/app/posts/views/src_views.py new file mode 100644 index 0000000..990088f --- /dev/null +++ b/app/posts/views/src_views.py @@ -0,0 +1,97 @@ +from django.views.generic import ListView +from django.views.generic.detail import DetailView +from django.contrib.syndication.views import Feed +from django.urls import reverse +from django.conf import settings + +#from paypal.standard.forms import PayPalPaymentsForm +from utils.views import PaginatedListView +from ..models import Post, PostType +from taxonomy.models import Category + + +class SrcListView(PaginatedListView): + model = Post + template_name="posts/src_list.html" + + def get_queryset(self): + queryset = super(SrcListView, self).get_queryset() + return queryset.filter(post_type=PostType.SRC).filter(status__exact=1).order_by('-pub_date') + + def get_context_data(self, **kwargs): + # Call the base implementation first to get a context + context = super(SrcListView, self).get_context_data(**kwargs) + #context['topics'] = Topic.objects.all() + context['breadcrumbs'] = ['src',] + return context + + +class SrcDetailView(DetailView): + model = Post + slug_field = "slug" + template_name="posts/src_detail.html" + + +class SrcDetailViewTXT(SrcDetailView): + template_name = "posts/jrnl_detail.txt" + + +class TopicListView(ListView): + template_name = 'posts/topic_list.html' + + def get_queryset(self): + return Post.objects.filter(topics__slug=self.kwargs['slug'],post_type=PostType.SRC) + + 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'] = Category.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 SrcPost.objects.filter(status__exact=1).order_by('-pub_date')[:10] + + +""" +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() + if book.price_sale < book.price: + price = book.price_sale + else: + price = book.price + #paypal_dict = { + # "business": settings.PAYPAL_RECEIVER_EMAIL, + # "amount": price, + # "item_name": book.title, + # "invoice": "unique-invoice-id", + # "notify_url": "https://luxagraf.net/src/paypal/" + reverse('src:paypal-ipn'), + # "return_url": "https://luxagraf.net/src/thank-you", + # "cancel_return": "https://luxagraf.net/src/books/", + #} + #context['paypal_form'] = PayPalPaymentsForm(initial=paypal_dict) + return context + +""" |