Kenneth Love avatar Kenneth Love committed 1273b82

cleaned up and separated talks into its own app.

Comments (0)

Files changed (17)

lightning/common/forms.py

 
 from uni_form.helpers import FormHelper, Submit
 
-from common.models import Talk
-
 class ProfileForm(forms.ModelForm):
     class Meta:
         model = User
         helper.form_action = ''
         helper.form_method = 'POST'
         return helper
-
-class TalkForm(forms.ModelForm):
-    class Meta:
-        model = Talk
-        exclude = ('user',)
-
-    def __init__(self, *args, **kwargs):
-        super(TalkForm, self).__init__(*args, **kwargs)
-        self.fields['url'].label = 'URL'
-
-    @property
-    def helper(self):
-        helper = FormHelper()
-        submit = Submit('save', 'Save', **{'css_class': 'primary'})
-        helper.add_input(submit)
-        helper.form_action = ''
-        helper.form_method = 'POST'
-        return helper

lightning/common/migrations/0001_initial.py

-# encoding: utf-8
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-class Migration(SchemaMigration):
-
-    def forwards(self, orm):
-        
-        # Adding model 'Talk'
-        db.create_table('common_talk', (
-            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('created_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
-            ('updated_at', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
-            ('url', self.gf('django.db.models.fields.URLField')(max_length=200)),
-            ('name', self.gf('django.db.models.fields.CharField')(max_length=1024)),
-            ('description', self.gf('django.db.models.fields.TextField')()),
-            ('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='talks', to=orm['auth.User'])),
-        ))
-        db.send_create_signal('common', ['Talk'])
-
-
-    def backwards(self, orm):
-        
-        # Deleting model 'Talk'
-        db.delete_table('common_talk')
-
-
-    models = {
-        'auth.group': {
-            'Meta': {'object_name': 'Group'},
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
-            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
-        },
-        'auth.permission': {
-            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
-            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
-            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
-        },
-        'auth.user': {
-            'Meta': {'object_name': 'User'},
-            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
-            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
-            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
-            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
-            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
-            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
-            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
-            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
-            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
-            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
-            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
-        },
-        'common.talk': {
-            'Meta': {'object_name': 'Talk'},
-            'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
-            'description': ('django.db.models.fields.TextField', [], {}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'name': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
-            'updated_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
-            'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
-            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'talks'", 'to': "orm['auth.User']"})
-        },
-        'contenttypes.contenttype': {
-            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
-            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
-            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
-            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
-        }
-    }
-
-    complete_apps = ['common']
Add a comment to this file

lightning/common/migrations/__init__.py

Empty file removed.

lightning/common/models.py

 from django.db import models
-from django.contrib.auth.models import User
 
 class Lumberjack(models.Model):
     created_at = models.DateTimeField(auto_now_add=True, editable=False)
     class Meta:
         abstract = True
 
-class Talk(Lumberjack):
-    url = models.URLField()
-    name = models.CharField(max_length=1024)
-    description = models.TextField()
-    user = models.ForeignKey(User, related_name='talks')
-
-    def __unicode__(self):
-        return self.name
-

lightning/common/views.py

 from django.contrib.auth import logout
 from django.http import HttpResponseRedirect
 from django.core.urlresolvers import reverse
-from django.views.generic import TemplateView, CreateView
-from django.views.generic import ListView
+from django.views.generic import TemplateView
 from django.contrib.auth.decorators import login_required
 from django.utils.decorators import method_decorator
 
-from common.forms import ProfileForm, TalkForm
-from common.models import Talk
+from common.forms import ProfileForm
 
 def logout_view(request):
     logout(request)
     return HttpResponseRedirect(reverse('home'))
 
+
 class CreateUpdateProfileView(TemplateView):
     template_name = 'common/profile_form.html'
 
             return HttpResponseRedirect(reverse('profile'))
 
         return self.render_to_response({'form': form})
-
-
-class TalksView(ListView):
-    template_name = 'common/talks.html'
-    model = Talk
-
-    @method_decorator(login_required)
-    def dispatch(self, *args, **kwargs):
-        return super(TalksView, self).dispatch(*args, **kwargs)
-
-    def get_queryset(self):
-        queryset = super(TalksView, self).get_queryset()
-        queryset = queryset.filter(user=self.request.user)
-        return queryset
-
-
-class CreateTalkView(CreateView):
-    template_name = 'common/create_talk.html'
-    form_class = TalkForm
-
-    @method_decorator(login_required)
-    def dispatch(self, *args, **kwargs):
-        return super(CreateTalkView, self).dispatch(*args, **kwargs)
-
-    def post(self, request):
-        form = TalkForm(request.POST)
-
-        if form.is_valid():
-            talk = form.save(commit=False)
-            talk.user = request.user
-            talk.save()
-
-            return HttpResponseRedirect(reverse('profile'))
-
-        return super(CreateTalkView, self).post(request)
-

lightning/settings/base.py

 
 MY_APPS = (
     'common',
+    'talks',
 )
 
 INSTALLED_APPS = THIRD_PARTY_APPS + MY_APPS
Add a comment to this file

lightning/talks/__init__.py

Empty file added.

lightning/talks/forms.py

+import floppyforms as forms
+
+from uni_form.helpers import FormHelper, Submit
+
+from talks.models import Talk
+
+
+class TalkForm(forms.ModelForm):
+    class Meta:
+        model = Talk
+        exclude = ('user',)
+
+    def __init__(self, *args, **kwargs):
+        super(TalkForm, self).__init__(*args, **kwargs)
+        self.fields['url'].label = 'URL'
+
+    @property
+    def helper(self):
+        helper = FormHelper()
+        submit = Submit('save', 'Save', **{'css_class': 'primary'})
+        helper.add_input(submit)
+        helper.form_action = ''
+        helper.form_method = 'POST'
+        return helper

lightning/talks/migrations/0001_initial.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding model 'Talk'
+        db.create_table('talks_talk', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('created_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
+            ('updated_at', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
+            ('url', self.gf('django.db.models.fields.URLField')(max_length=200)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=1024)),
+            ('description', self.gf('django.db.models.fields.TextField')()),
+            ('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='talks', to=orm['auth.User'])),
+            ('slug', self.gf('django.db.models.fields.SlugField')(max_length=100, db_index=True)),
+        ))
+        db.send_create_signal('talks', ['Talk'])
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'Talk'
+        db.delete_table('talks_talk')
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'talks.talk': {
+            'Meta': {'object_name': 'Talk'},
+            'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '100', 'db_index': 'True'}),
+            'updated_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'talks'", 'to': "orm['auth.User']"})
+        }
+    }
+
+    complete_apps = ['talks']
Add a comment to this file

lightning/talks/migrations/__init__.py

Empty file added.

lightning/talks/models.py

+from django.db import models
+from django.contrib.auth.models import User
+
+from common.models import Lumberjack
+
+class Talk(Lumberjack):
+    url = models.URLField()
+    name = models.CharField(max_length=1024)
+    description = models.TextField()
+    user = models.ForeignKey(User, related_name='talks')
+    slug = models.SlugField(editable=False, max_length=100)
+
+    def __unicode__(self):
+        return self.name
+

lightning/talks/tests.py

+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.assertEqual(1 + 1, 2)

lightning/talks/urls.py

+from django.conf.urls.defaults import patterns, url
+
+from talks.views import CreateTalkView, TalksView
+
+urlpatterns = patterns('',
+    url(r'^create/$', CreateTalkView.as_view(), name='create_talk'),
+    url(r'^$', TalksView.as_view(), name='talks'),
+)

lightning/talks/views.py

+from django.http import HttpResponseRedirect
+from django.core.urlresolvers import reverse
+from django.views.generic import CreateView, DeleteView
+from django.views.generic import ListView
+from django.contrib.auth.decorators import login_required
+from django.utils.decorators import method_decorator
+
+from talks.forms import TalkForm
+from talks.models import Talk
+
+
+class TalksView(ListView):
+    template_name = 'common/talks.html'
+    model = Talk
+
+    @method_decorator(login_required)
+    def dispatch(self, *args, **kwargs):
+        return super(TalksView, self).dispatch(*args, **kwargs)
+
+    def get_queryset(self):
+        queryset = super(TalksView, self).get_queryset()
+        queryset = queryset.filter(user=self.request.user)
+        return queryset
+
+
+class DeleteTalkView(DeleteView):
+    pass
+
+
+class CreateTalkView(CreateView):
+    template_name = 'common/create_talk.html'
+    form_class = TalkForm
+
+    @method_decorator(login_required)
+    def dispatch(self, *args, **kwargs):
+        return super(CreateTalkView, self).dispatch(*args, **kwargs)
+
+    def post(self, request):
+        form = TalkForm(request.POST)
+
+        if form.is_valid():
+            talk = form.save(commit=False)
+            talk.user = request.user
+            talk.save()
+
+            return HttpResponseRedirect(reverse('talks'))
+
+        return super(CreateTalkView, self).post(request)
+

lightning/templates/_layouts/base.html

 		<div class="topbar-inner">
 			<div class="container">
 				<h3><a href="{% url home %}">Lightning Talks</a></h3>
+				<ul class="nav">
+				{% if request.user.is_authenticated %}
+					<li><a href="{% url create_talk %}">Create a talk</a></li>
+					{% if request.user.talks.all %}
+					<li><a href="{% url talks %}">Your talks</a></li>
+					{% endif %}
+				{% endif %}
+				</ul>
 				<form action="">
 					<input type="text" placeholder="Search">
 				</form>
 				<ul class="nav secondary-nav">
-					<li class="dropdown">
-						<a href="#" class="dropdown-toggle">Your Account</a>
-						<ul class="dropdown-menu">
-							{% if request.user.is_authenticated %}
-							<li><a href="{% url profile %}">Your Profile</a></li>
-							<li><a href="{% url create_talk %}">Create a talk</a></li>
-							<li class="divider"></li>
-							<li><a href="{% url logout %}">Logout</a></li>
-							{% else %}
-							<li><a href="{% url socialauth_begin 'twitter' %}">Login with Twitter</a></li>
-							<li><a href="{% url socialauth_begin 'facebook' %}">Login with Facebook</a></li>
-							{% endif %}
-						</ul>
-					</li>
+				{% if request.user.is_authenticated %}
+					<li><a href="{% url profile %}">Your Profile</a></li>
+					<li><a href="{% url logout %}">Logout</a></li>
+				{% else %}
+					<li><a href="{% url socialauth_begin 'twitter' %}">Login with Twitter</a></li>
+					<li><a href="{% url socialauth_begin 'facebook' %}">Login with Facebook</a></li>
+				{% endif %}
 				</ul>
 			</div>
 		</div><!-- /topbar-inner -->

lightning/templates/common/talks.html

 {% block page_title %}Your talks | {% endblock %}
 
 {% block page_content %}
-{{ object_list }}
+<h2>Your talks</h2>
+{% for talk in object_list %}
+<article>
+	<a href="#"><h3>{{ talk.name }}</h3></a>
+	{{ talk.description|linebreaks }}
+</article>
+{% empty %}
+<article><h3>No talks yet.</h3></article>
+{% endfor %}
 {% endblock %}

lightning/urls.py

 from django.contrib import admin
 admin.autodiscover()
 
-from common.views import CreateUpdateProfileView, CreateTalkView, TalksView
+from common.views import CreateUpdateProfileView
 
 urlpatterns = patterns('',
-    # Examples:
-    # url(r'^$', 'lightning.views.home', name='home'),
-    # url(r'^lightning/', include('lightning.foo.urls')),
-
     url(r'^logout/$', 'common.views.logout_view', name='logout'),
     url(r'^profile/$', CreateUpdateProfileView.as_view(), name='profile'),
-    url(r'^talks/create/$', CreateTalkView.as_view(), name='create_talk'),
-    url(r'^talks/$', TalksView.as_view(), name='talks'),
+    url(r'^talks/', include('talks.urls')),
     url(r'^admin/', include(admin.site.urls)),
     url(r'', include('social_auth.urls')),
     url(r'^$', 'django.views.generic.simple.direct_to_template', {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.