summaryrefslogtreecommitdiff
path: root/app/people
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2018-03-07 10:31:15 -0600
committerluxagraf <sng@luxagraf.net>2018-03-07 10:31:15 -0600
commitce9c1a25a2872979b969c64f804529d200a8c0ad (patch)
tree809ba96e13ff51c45d8d9f46e6700b1fe4f82b09 /app/people
parent875e1a8c87ea0825653684068810987c78c94857 (diff)
added a people app as per derek sivers' suggestion
Diffstat (limited to 'app/people')
-rw-r--r--app/people/__init__.py0
-rw-r--r--app/people/admin.py8
-rw-r--r--app/people/build.py35
-rw-r--r--app/people/migrations/0001_initial.py42
-rw-r--r--app/people/migrations/__init__.py0
-rw-r--r--app/people/models.py54
-rw-r--r--app/people/urls.py36
-rw-r--r--app/people/views.py38
8 files changed, 213 insertions, 0 deletions
diff --git a/app/people/__init__.py b/app/people/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/people/__init__.py
diff --git a/app/people/admin.py b/app/people/admin.py
new file mode 100644
index 0000000..ea0b463
--- /dev/null
+++ b/app/people/admin.py
@@ -0,0 +1,8 @@
+from django.contrib import admin
+from .models import Person
+
+
+@admin.register(Person)
+class PersonAdmin(admin.ModelAdmin):
+ list_display = ('last_name', 'first_name', 'location_met', )
+
diff --git a/app/people/build.py b/app/people/build.py
new file mode 100644
index 0000000..35fdb19
--- /dev/null
+++ b/app/people/build.py
@@ -0,0 +1,35 @@
+import os
+from django.urls import reverse
+from builder.base import BuildNew
+
+
+class BuildBooks(BuildNew):
+
+ def build(self):
+ self.build_detail_view()
+ self.build_list_view(
+ base_path=reverse("books:live_redirect"),
+ paginate_by=24
+ )
+ print("building books")
+
+ def get_model_queryset(self):
+ return self.model.objects.all()
+
+ def build_detail_view(self):
+ '''
+ write out all the expenses for each trip
+ '''
+ for obj in self.get_model_queryset():
+ url = obj.get_absolute_url()
+ path, slug = os.path.split(url)
+ path = '%s/' % path
+ # write html
+ response = self.client.get(url)
+ print(path, slug)
+ self.write_file(path, response.content, filename=slug)
+
+
+def builder():
+ j = BuildBooks("books", "book")
+ j.build()
diff --git a/app/people/migrations/0001_initial.py b/app/people/migrations/0001_initial.py
new file mode 100644
index 0000000..9174f3f
--- /dev/null
+++ b/app/people/migrations/0001_initial.py
@@ -0,0 +1,42 @@
+# Generated by Django 2.0.1 on 2018-03-07 10:27
+
+from django.db import migrations, models
+import django.db.models.deletion
+import taggit.managers
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ('locations', '0003_auto_20180307_1027'),
+ ('taggit', '0002_auto_20150616_2121'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Person',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('first_name', models.CharField(max_length=200)),
+ ('last_name', models.CharField(max_length=200)),
+ ('email', models.EmailField(blank=True, max_length=120, null=True)),
+ ('street', models.CharField(blank=True, max_length=355, null=True)),
+ ('city', models.CharField(blank=True, max_length=200, null=True)),
+ ('state', models.CharField(blank=True, max_length=200, null=True)),
+ ('postal_code', models.CharField(blank=True, max_length=20, null=True)),
+ ('country', models.CharField(max_length=200, null=True)),
+ ('phone', models.CharField(blank=True, max_length=22, null=True)),
+ ('slug', models.CharField(max_length=50)),
+ ('body_markdown', models.TextField(blank=True, null=True)),
+ ('body_html', models.TextField(blank=True, null=True)),
+ ('next_contact_date', models.DateField(blank=True, null=True)),
+ ('location_met', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')),
+ ('tags', taggit.managers.TaggableManager(blank=True, help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags')),
+ ],
+ options={
+ 'ordering': ('-last_name',),
+ },
+ ),
+ ]
diff --git a/app/people/migrations/__init__.py b/app/people/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/people/migrations/__init__.py
diff --git a/app/people/models.py b/app/people/models.py
new file mode 100644
index 0000000..b4bc2cc
--- /dev/null
+++ b/app/people/models.py
@@ -0,0 +1,54 @@
+from django.db import models
+from django.template.defaultfilters import slugify
+
+from taggit.managers import TaggableManager
+from locations.models import Location
+from utils.widgets import markdown_to_html
+
+
+class Person(models.Model):
+ first_name = models.CharField(max_length=200)
+ last_name = models.CharField(max_length=200)
+ email = models.EmailField(max_length=120, null=True, blank=True)
+ street = models.CharField(max_length=355, null=True, blank=True)
+ city = models.CharField(max_length=200, null=True, blank=True)
+ state = models.CharField(max_length=200, null=True, blank=True)
+ postal_code = models.CharField(max_length=20, null=True, blank=True)
+ country = models.CharField(max_length=200, null=True)
+ phone = models.CharField(max_length=22, blank=True, null=True)
+ slug = models.CharField(max_length=50, blank=True)
+ body_markdown = models.TextField(null=True, blank=True)
+ body_html = models.TextField(null=True, blank=True)
+ tags = TaggableManager(blank=True)
+ location_met = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True)
+ next_contact_date = models.DateField(null=True, blank=True)
+
+ class Meta:
+ ordering = ('-last_name',)
+
+ def __str__(self):
+ return "%s %s" %(self.first_name, self.last_name)
+
+ def get_absolute_url(self):
+ return reverse("people:detail", kwargs={"slug": self.slug})
+
+ @property
+ def get_previous_admin_url(self):
+ n = self.get_previous_by_pub_date()
+ return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] )
+
+ @property
+ def get_next_admin_url(self):
+ model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
+ try:
+ return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk] )
+ except model.DoesNotExist:
+ return ''
+
+ def save(self, *args, **kwargs):
+ if not self.slug:
+ self.slug = slugify(("%s-%s")[:50] %(self.last_name, self.first_name))
+ if self.body_markdown:
+ self.body_html = markdown_to_html(self.body_markdown)
+ super(Person, self).save()
+
diff --git a/app/people/urls.py b/app/people/urls.py
new file mode 100644
index 0000000..0ae38eb
--- /dev/null
+++ b/app/people/urls.py
@@ -0,0 +1,36 @@
+from django.urls import path, re_path
+from django.views.generic.base import RedirectView
+
+from . import views
+
+app_name = "people"
+
+urlpatterns = [
+ re_path(
+ r'^tag/(?P<slug>[-\w]+)/$',
+ views.PersonTagListView.as_view(),
+ {'page':1},
+ name='list-tag'
+ ),
+ re_path(
+ r'tag/(?P<slug>[-\w]+)/(?P<page>\d+)/$',
+ views.PersonTagListView.as_view(),
+ name='list-tag'
+ ),
+ re_path(
+ r'^(?P<page>\d+)/$',
+ views.PersonListView.as_view(),
+ name="list"
+ ),
+ path(
+ r'',
+ views.PersonListView.as_view(),
+ {'page':1},
+ name="list"
+ ),
+ path(
+ r'<str:slug>/',
+ views.PersonDetailView.as_view(),
+ name='detail',
+ ),
+]
diff --git a/app/people/views.py b/app/people/views.py
new file mode 100644
index 0000000..36c0657
--- /dev/null
+++ b/app/people/views.py
@@ -0,0 +1,38 @@
+from django.views.generic.detail import DetailView
+from utils.views import PaginatedListView
+
+from taggit.models import Tag
+from .models import Person
+
+
+class PersonListView(PaginatedListView):
+ model = Person
+ template_name = 'archives/people.html'
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(PersonListView, self).get_context_data(**kwargs)
+ context['tags'] = Person.tags.all()
+ return context
+
+
+class PersonDetailView(DetailView):
+ model = Person
+ template_name = "details/person.html"
+ slug_field = "slug"
+
+
+class PersonTagListView(PaginatedListView):
+ model = Person
+ template_name = 'archives/people.html'
+
+ def get_queryset(self):
+ print(self.kwargs['slug'])
+ return Person.objects.filter(tags__slug=self.kwargs['slug'])
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(PersonTagListView, self).get_context_data(**kwargs)
+ context['tag'] = Tag.objects.get(slug__exact=self.kwargs['slug'])
+ context['tags'] = Person.tags.all()
+ return context