diff options
Diffstat (limited to 'app/tutorials')
-rw-r--r-- | app/tutorials/__init__.py | 0 | ||||
-rw-r--r-- | app/tutorials/admin.py | 33 | ||||
-rw-r--r-- | app/tutorials/build.py | 17 | ||||
-rw-r--r-- | app/tutorials/migrations/0001_initial.py | 49 | ||||
-rw-r--r-- | app/tutorials/migrations/0002_auto_20190505_1107.py | 22 | ||||
-rw-r--r-- | app/tutorials/migrations/0003_auto_20190505_1109.py | 20 | ||||
-rw-r--r-- | app/tutorials/migrations/__init__.py | 0 | ||||
-rw-r--r-- | app/tutorials/models.py | 109 | ||||
-rw-r--r-- | app/tutorials/urls.py | 23 | ||||
-rw-r--r-- | app/tutorials/views.py | 23 |
10 files changed, 296 insertions, 0 deletions
diff --git a/app/tutorials/__init__.py b/app/tutorials/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/tutorials/__init__.py diff --git a/app/tutorials/admin.py b/app/tutorials/admin.py new file mode 100644 index 0000000..e3ae640 --- /dev/null +++ b/app/tutorials/admin.py @@ -0,0 +1,33 @@ +from django.contrib import admin +from .models import Tutorial +from utils.widgets import LGEntryForm + + +@admin.register(Tutorial) +class TutorialAdmin(admin.ModelAdmin): + form = LGEntryForm + list_display = ('title', 'pub_date', 'enable_comments', 'status') + list_filter = ('pub_date', 'enable_comments', 'status') + prepopulated_fields = {"slug": ('title',)} + fieldsets = ( + ('Entry', { + 'fields': ( + 'title', + 'sub_title', + 'body_markdown', + ('pub_date', 'status'), + 'tags', + 'meta_description', + ('slug', 'enable_comments', 'has_code'), + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + } + ), + ) + + class Media: + js = ('image-loader.js', 'next-prev-links.js') diff --git a/app/tutorials/build.py b/app/tutorials/build.py new file mode 100644 index 0000000..4256595 --- /dev/null +++ b/app/tutorials/build.py @@ -0,0 +1,17 @@ +from builder.base import BuildNew +from django.urls import reverse + + +class BuildTutorals(BuildNew): + + def build(self): + self.build_list_view( + base_path=reverse("tutorials:list"), + paginate_by=99999 + ) + self.build_detail_view() + + +def builder(): + j = BuildTutorals("tutorials", "tutorial") + j.build() diff --git a/app/tutorials/migrations/0001_initial.py b/app/tutorials/migrations/0001_initial.py new file mode 100644 index 0000000..298406e --- /dev/null +++ b/app/tutorials/migrations/0001_initial.py @@ -0,0 +1,49 @@ +# Generated by Django 2.1.7 on 2019-05-05 15:21 + +from django.db import migrations, models +import taggit.managers + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('taxonomy', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Topic', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=60)), + ('slug', models.SlugField()), + ('pluralized_name', models.CharField(max_length=60)), + ], + ), + migrations.CreateModel( + name='Tutorial', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('slug', models.SlugField(unique_for_date='pub_date')), + ('body_html', models.TextField(blank=True)), + ('body_markdown', models.TextField()), + ('pub_date', models.DateTimeField(verbose_name='Date published')), + ('last_updated', models.DateTimeField(auto_now=True)), + ('enable_comments', models.BooleanField(default=False)), + ('has_code', models.BooleanField(default=False)), + ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0)), + ('meta_description', models.CharField(blank=True, max_length=256, null=True)), + ('template_name', models.IntegerField(choices=[(0, 'default')], default=0)), + ('tags', taggit.managers.TaggableManager(blank=True, help_text='Topics Covered', through='taxonomy.TaggedItems', to='taxonomy.LuxTag', verbose_name='Tags')), + ('topics', models.ManyToManyField(blank=True, to='tutorials.Topic')), + ], + options={ + 'get_latest_by': 'pub_date', + 'ordering': ('-pub_date',), + 'verbose_name_plural': 'posts', + }, + ), + ] diff --git a/app/tutorials/migrations/0002_auto_20190505_1107.py b/app/tutorials/migrations/0002_auto_20190505_1107.py new file mode 100644 index 0000000..76f19a5 --- /dev/null +++ b/app/tutorials/migrations/0002_auto_20190505_1107.py @@ -0,0 +1,22 @@ +# Generated by Django 2.1.7 on 2019-05-05 16:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tutorials', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='tutorial', + name='template_name', + ), + migrations.AddField( + model_name='tutorial', + name='sub_title', + field=models.CharField(blank=True, max_length=200), + ), + ] diff --git a/app/tutorials/migrations/0003_auto_20190505_1109.py b/app/tutorials/migrations/0003_auto_20190505_1109.py new file mode 100644 index 0000000..95e61b7 --- /dev/null +++ b/app/tutorials/migrations/0003_auto_20190505_1109.py @@ -0,0 +1,20 @@ +# Generated by Django 2.1.7 on 2019-05-05 16:09 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tutorials', '0002_auto_20190505_1107'), + ] + + operations = [ + migrations.RemoveField( + model_name='tutorial', + name='topics', + ), + migrations.DeleteModel( + name='Topic', + ), + ] diff --git a/app/tutorials/migrations/__init__.py b/app/tutorials/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/tutorials/migrations/__init__.py diff --git a/app/tutorials/models.py b/app/tutorials/models.py new file mode 100644 index 0000000..7c7570c --- /dev/null +++ b/app/tutorials/models.py @@ -0,0 +1,109 @@ +from django.db import models +from django.urls import reverse +from django.contrib.sitemaps import Sitemap +import datetime +from itertools import chain + +from taggit.managers import TaggableManager + +from utils.util import render_images, markdown_to_html +from taxonomy.models import TaggedItems + + +class Tutorial(models.Model): + title = models.CharField(max_length=200) + sub_title = models.CharField(max_length=200, blank=True) + slug = models.SlugField(unique_for_date='pub_date') + body_html = models.TextField(blank=True) + body_markdown = models.TextField() + pub_date = models.DateTimeField('Date published') + tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered') + last_updated = models.DateTimeField(auto_now=True) + enable_comments = models.BooleanField(default=False) + has_code = models.BooleanField(default=False) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + meta_description = models.CharField(max_length=256, null=True, blank=True) + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + verbose_name_plural = 'posts' + + def __str__(self): + return self.title + + def get_absolute_url(self): + return reverse('src:detail', kwargs={"slug": self.slug}) + + def comment_period_open(self): + return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date + + @property + def get_previous_published(self): + return self.get_previous_by_pub_date(status__exact=1) + + @property + def get_next_published(self): + return self.get_next_by_pub_date(status__exact=1) + + def save(self): + #md = render_images(self.body_markdown) + #self.body_html = markdown_to_html(md) + super(Tutorial, self).save() + + +class TutorialSitemap(Sitemap): + changefreq = "never" + priority = 1.0 + protocol = "https" + + def items(self): + return Tutorial.objects.filter(status=1) + + def lastmod(self, obj): + return obj.pub_date +def get_upload_path(self, filename): + return "images/src/%s" % filename + + +'''class SrcDemo(models.Model): + title = models.CharField(max_length=254) + slug = models.SlugField() + body = models.TextField(blank=True, null=True) + head = models.TextField(blank=True, null=True) + DEMO_TEMPLATES = ( + (0, 'Blank'), + (1, 'Basic_light'), + ) + template = models.IntegerField(choices=DEMO_TEMPLATES, default=0) + pub_date = models.DateTimeField('Date published', blank=True) + + class Meta: + verbose_name_plural = "Demos" + app_label = 'projects' + ordering = ('-pub_date',) + + def save(self): + if not self.id: + self.pub_date = datetime.datetime.now() + super(SrcDemo, self).save() +''' + + +class SrcSitemap(Sitemap): + changefreq = "never" + priority = 0.7 + protocol = "https" + + def items(self): + return list(chain( + Post.objects.filter(status=1), + Topic.objects.all() + )) + + def lastmod(self, obj): + return obj.pub_date diff --git a/app/tutorials/urls.py b/app/tutorials/urls.py new file mode 100644 index 0000000..8f4b189 --- /dev/null +++ b/app/tutorials/urls.py @@ -0,0 +1,23 @@ +from django.urls import path, re_path + +from . import views + +app_name = "src" + +urlpatterns = [ + path( + r'<slug>.txt', + views.EntryDetailViewTXT.as_view(), + name="detail-txt" + ), + path( + r'<slug>', + views.EntryDetailView.as_view(), + name="detail" + ), + path( + r'', + views.TutorialListView.as_view(), + name="list", + ), +] diff --git a/app/tutorials/views.py b/app/tutorials/views.py new file mode 100644 index 0000000..ab51ef2 --- /dev/null +++ b/app/tutorials/views.py @@ -0,0 +1,23 @@ +from django.views.generic import ListView +from django.views.generic.detail import DetailView + + +from .models import Tutorial + + +class TutorialListView(ListView): + model = Tutorial + + def get_queryset(self): + return Tutorial.objects.all() + + +class EntryDetailView(DetailView): + model = Tutorial + slug_field = "slug" + + +class EntryDetailViewTXT(EntryDetailView): + template_name = "blog/entry_detail.txt" + + |