Commits

Philippe Marichal committed bc1ee10

Initial version of faq app

Comments (0)

Files changed (8)

+syntax: glob
+*.pyc
+.DS_Store
Empty file added.
+from django.contrib import admin
+
+from models import FaqEntry
+
+class FaqAdmin(admin.ModelAdmin):
+    fieldsets = (
+        (None, {
+            'fields': ('position', 'question', 'answer', 
+                       'status', ),
+        }),  
+    )
+    list_display = ('get_truncated_question', 'position', 'get_anchor', 'status', )
+    search_fields = ('question', 'answer', )
+    list_filter = ('status', )
+    radio_fields = {"status": admin.VERTICAL} 
+    
+admin.site.register(FaqEntry, FaqAdmin)

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 'FaqEntry'
+        db.create_table('faq_faqentry', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('position', self.gf('django.db.models.fields.PositiveIntegerField')()),
+            ('question', self.gf('django.db.models.fields.CharField')(max_length=255)),
+            ('answer', self.gf('django.db.models.fields.TextField')()),
+            ('status', self.gf('django.db.models.fields.CharField')(max_length=1)),
+        ))
+        db.send_create_signal('faq', ['FaqEntry'])
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'FaqEntry'
+        db.delete_table('faq_faqentry')
+
+
+    models = {
+        'faq.faqentry': {
+            'Meta': {'ordering': "['position']", 'object_name': 'FaqEntry'},
+            'answer': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'position': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'question': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'status': ('django.db.models.fields.CharField', [], {'max_length': '1'})
+        }
+    }
+
+    complete_apps = ['faq']

migrations/__init__.py

Empty file added.
+# -*- coding: utf-8 -*-
+from django.db import models
+from django.core.urlresolvers import reverse
+
+
+class FaqEntry(models.Model):
+    
+    STATUS_DRAFT = 'D'
+    STATUS_PUBLISHED = 'P'
+    FAQ_STATUS = (
+            (STATUS_DRAFT, u'Draft'),
+            (STATUS_PUBLISHED, u'Publiée'),
+    )
+    
+    position= models.PositiveIntegerField(help_text="La position dans la liste de FAQ (entier > 0).")
+    question = models.CharField(max_length=255)
+    answer = models.TextField("réponse")
+    status = models.CharField("statut", max_length=1, choices=FAQ_STATUS, default=STATUS_DRAFT)
+
+    class Meta:
+        ordering = ['position']
+        verbose_name = u"question de faq"
+        verbose_name_plural = u"questions de faq"
+
+    def __unicode__(self):
+        return self.question[:100]
+
+    def get_absolute_url(self):
+        #http://<domain>/faq/#faq1
+        url = reverse('faq', current_app='faq')
+        return "%s#faq%d" % (url, self.id)
+    
+    
+    def get_truncated_question(self):
+        return self.question[:100]
+    get_truncated_question.short_description = "Question"
+    
+    def get_anchor(self):
+        return self.get_absolute_url()
+    get_anchor.short_description = 'balise'
+from django.conf.urls.defaults import *
+from django.views.generic import ListView
+
+from models import *
+
+# faq_dict = {
+#     'queryset': FaqEntry.objects.filter(status='P'),
+#     'template_name': 'faq/faq.html',
+#     'template_object_name': 'faqs',    
+# }
+
+urlpatterns = patterns('',
+    url(r'^$',
+        ListView.as_view(queryset=FaqEntry.objects.filter(status='P'),
+                         context_object_name="faqs",
+                         template_name="faq/faq.html"), 
+        name="faq"),
+    )
+# Create your views here.