Skip to content

Commit

Permalink
Sfranklin/featured speakers (#133)
Browse files Browse the repository at this point in the history
* Adding featured speakers app

* Add featured_speakers and dependency to INSTALLED_APPS

* Add changes to frontend template

* Use name in admin dropdown list

* One row, many speakers

* Many hoops to customize the string display of Speaker model in admain
  • Loading branch information
PirosB3 authored Jun 26, 2017
1 parent 5889ca9 commit 9ac0d6f
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 4 deletions.
Empty file added featured_speakers/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions featured_speakers/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django import forms
from django.contrib import admin
from django.db import models

from ordered_model.admin import OrderedModelAdmin

from .models import FeaturedSpeaker
from symposion.speakers.models import Speaker

class SpeakerChoiceField(forms.ModelChoiceField):
"""Class to overwrite __str__ implementation on speakers and provide text in dropdown."""
def label_from_instance(self, obj):
return obj.name

class FeaturedSpeakerForm(forms.ModelForm):
speaker = SpeakerChoiceField(Speaker.objects.all())

class FeaturedSpeakerAdmin(OrderedModelAdmin):
list_display = ('title', 'speaker_name', 'move_up_down_links')
form = FeaturedSpeakerForm
def speaker_name(self, obj):
return obj.speaker.name
speaker_name.admin_order_field = 'speaker'



admin.site.register(FeaturedSpeaker, FeaturedSpeakerAdmin)
5 changes: 5 additions & 0 deletions featured_speakers/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class FeaturedSpeakersConfig(AppConfig):
name = 'featured_speakers'
30 changes: 30 additions & 0 deletions featured_speakers/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2017-06-21 02:54
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('symposion_speakers', '0003_auto_20170419_0518'),
]

operations = [
migrations.CreateModel(
name='FeaturedSpeaker',
fields=[
('order', models.PositiveIntegerField(db_index=True, editable=False)),
('title', models.CharField(max_length=50)),
('speaker', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='symposion_speakers.Speaker')),
],
options={
'ordering': ('order',),
'abstract': False,
},
),
]
Empty file.
12 changes: 12 additions & 0 deletions featured_speakers/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models

from ordered_model.models import OrderedModel
from symposion.speakers.models import Speaker


class FeaturedSpeaker(OrderedModel):
title = models.CharField(max_length=50)
speaker = models.OneToOneField(Speaker, on_delete=models.CASCADE, primary_key=True)

class Meta(OrderedModel.Meta):
pass
33 changes: 33 additions & 0 deletions featured_speakers/templates/featured_speakers/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="main-container">
<section class="speakers duplicatable-content">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1>Some of our speakers.</h1>
</div>
</div>
<div class="row speakers-row">
{% for featured in speakers %}
<div class="col-md-3 col-sm-6 speaker-column">
<div class="speaker">
{% if featured.speaker.photo %}
<div class="image-holder">
<img class="background-image" alt="Speaker" src="{{ MEDIA_URL }}{{ featured.speaker.photo.name }}">
<div class="hover-state text-center preserve3d">
<div class="social-links vertical-align">
{% if featured.speaker.twitter_username %}
<a href="http://twitter.com/{{ featured.speaker.twitter_username }}"><i class="icon social_twitter"></i></a>
{% endif %}
</div>
</div>
</div>
{% endif %}
<span class="speaker-name">{{ featured.speaker.name }}</span>
{{ featured.speaker.biography_html|safe }}
</div>
</div>
{% endfor %}
</div>
</div>
</section>
</div>
Empty file.
11 changes: 11 additions & 0 deletions featured_speakers/templatetags/featured_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django import template

from featured_speakers.models import FeaturedSpeaker

register = template.Library()


@register.inclusion_tag('featured_speakers/list.html', takes_context=True)
def featured_speakers(context):
context['speakers'] = FeaturedSpeaker.objects.all()
return context
3 changes: 3 additions & 0 deletions featured_speakers/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions featured_speakers/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
3 changes: 3 additions & 0 deletions pybay/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@
"eventlog",
"markitup",
"metron",
"ordered_model",
"taggit",
"timezones",


# symposion
"symposion.sponsorship",
"symposion.conference",
Expand All @@ -157,6 +159,7 @@
'pybay.faqs',
'pybay.flatpages_ext.apps.FlatpagesExtConfig',
'crispy_forms',
'featured_speakers',
]

# A sample logging configuration. The only tangible logging
Expand Down
13 changes: 9 additions & 4 deletions pybay/templates/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ <h1 class="text-white">Memories from PyBay 2016</h1>
</div><!--end of container-->
</section>
<!--Previous Meetup Ends -->
<!-- featured speakers -->
<div class="container">
<div class="row">
<div class="col-sm-12">
{% load featured_tags %}
{% featured_speakers %}
</div>
</div>
</div>
<!--Subscribe to stay tune Starts -->
<section class="subscribe-2">
<div class="container">
Expand Down Expand Up @@ -334,7 +343,3 @@ <h1 class="large-h1" style="color: black;">Subscribe to stay informed</h1>
</section>
<!--Subsribe to stay Tune Ends -->
{% endblock content %}




1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ django-crispy-forms==1.6.1
django-jsonfield==1.0.1
django-markitup==2.2.2
django-model-utils==2.4
django-ordered-model==1.4.1
django-reversion==1.10.1
django-sitetree==1.5.1
django-taggit==0.18.0
Expand Down

0 comments on commit 9ac0d6f

Please sign in to comment.