1. Francisco Souza
  2. website

Commits

Francisco Souza  committed e47e48a

Versão pré-pré-alfa da app blog.

  • Participants
  • Parent commits 76bee3d
  • Branches default

Comments (0)

Files changed (8)

File blog/__init__.py

  • Ignore whitespace
Empty file added.

File blog/admin.py

View file
  • Ignore whitespace
+from django.contrib import admin
+from models import Tag
+
+admin.site.register(Tag)

File blog/models.py

View file
  • Ignore whitespace
+#coding:utf-8
+from google.appengine.ext import db
+
+class Tag(db.Model):
+    nome = db.StringProperty(required=True)
+    
+    def put(self):
+        tags = Tag.all()
+        for tag in tags:
+            if self.nome == tag.nome:
+                raise RuntimeError('Nomes iguais!')
+            
+        db.Model.put(self)
+    
+    def __unicode__(self):
+        return self.nome
+    
+class Post(db.Model):
+    titulo = db.StringProperty(required=True)
+    texto = db.TextProperty(required=True)

File blog/signals.py

View file
  • Ignore whitespace
+from django.db.models import signals
+from models import Tag
+
+def tag_pre_save(signal, instance, sender, **kwargs):
+    tags = Tag.all()
+    for tag in tags:
+        if tag.nome == instance.nome:
+            raise RuntimeError('')
+        
+signals.pre_save.connect(tag_pre_save, sender=Tag)

File blog/tests.py

View file
  • Ignore whitespace
+import unittest
+from models import Tag
+
+class TagTestCase(unittest.TestCase):
+    
+    def setUp(self):
+        self.tag = Tag()
+        self.tag.nome = 'Teste'
+        self.tag.put()
+        
+    def testNovaInstancia(self):
+        nova_tag = Tag()
+        nova_tag.nome = 'Teste'
+        self.failUnlessRaises(RuntimeError, nova_tag.put)

File blog/urls.py

View file
  • Ignore whitespace
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('blog.views',
+        #
+)

File blog/views.py

View file
  • Ignore whitespace
+# Create your views here.

File urls.py

View file
  • Ignore whitespace
     (r'^contato/', 'views.contato'),
     (r'^projetos/', include('projetos.urls')),
     (r'^imagens/', include('imagens.urls')),
-    #(r'criar_admin/', 'views.criar_admin'),
+    ('^blog/', include('blog.urls')),
+    (r'criar_admin/', 'views.criar_admin'),
     #(r'criar_projeto/', 'views.criar_projeto'),
 )