Anonymous avatar Anonymous committed f0b0d1a

add PenaBase

Comments (0)

Files changed (3)

 
 from django.db import models
 from django.contrib.auth.models import User
+from django.conf import settings
+from django.contrib.sites.models import Site
+from django.utils.translation import ugettext_lazy as _
+from datetime import datetime
 
 
-class Pena(models.Model):
+class PenaBase(models.Model):
+    now = datetime.now()
+    pub_date = models.DateTimeField(blank=True, null=True, default=now, verbose_name=_(u"Fecha de creación"))
+    slug = models.SlugField(max_length=140, blank=True)
+    is_active = models.BooleanField(default=True, verbose_name=_(u"Esta activo"))
+    is_live = models.BooleanField(default=True, verbose_name=_(u"Esta vivo")) # no se elimina, solo de hace -invisible-
+
+    lang = models.CharField(max_length=20, choices=settings.LANGUAGES, default=settings.LANGUAGE_CODE.lower(), blank=True)
+    site = models.ForeignKey(Site, blank=True, null=True)
+
+    meta_keywords = models.TextField(blank=True, help_text=_(u"opcional, para el SEO"))
+    meta_description = models.TextField(blank=True, help_text=_(u"opcional, para el SEO"))
+
+    @models.permalink
+    def get_absolute_url(self):
+        return (u'%s_%s' % (self._meta.app_label, self._meta.module_name), (self.slug,))
+        #return u'%s_%s/%s' % (self._meta.app_label, self._meta.module_name, self.slug,)
+
+    def save(self, *args, **kwargs):
+        if not self.slug:
+            if hasattr(self, 'name'):
+                self.slug = slugify(self.name)
+            elif hasattr(self, 'title'):
+                self.slug = slugify(self.title)
+            else:
+                self.slug = slugify(u"%s-%s-%s" % (self._meta.app_label, self._meta.module_name, self.pub_date))
+
+        if not self.lang:
+            self.lang = settings.LANGUAGE_CODE.lower()
+
+        if not self.site:
+            self.site = Site.objects.get_current()
+
+        return super(PenaBase, self).save(*args, **kwargs)
+
+    class Meta:
+        abstract = True
+        ordering = ('-pub_date',)
+        unique_together = ('slug', 'lang', 'site',)
+
+
+class Pena(PenaBase):
     user = models.ForeignKey(User)
-    slug = models.SlugField(max_length=30, unique=True)
     created = models.DateTimeField(auto_now_add=True)
     title = models.CharField(max_length=140, verbose_name=(u"Titulo"))
     image = models.FileField(blank=True, null=True, upload_to='img')
         pass
 
 
-class PenaComment(models.Model):
+class PenaComment(PenaBase):
     user = models.ForeignKey(User)
     pena = models.ForeignKey(Pena)
     created = models.DateTimeField(auto_now_add=True)
 
 
 urlpatterns = patterns('',
-    url(r'^main/$', 'pe-as.views.main', name='main'),
-    url(r'^pena/$', 'pe-as.views.pena', name='pena'),
+    url(r'^main/$', 'peas.views.main', name='main'),
+    url(r'^pena/$', 'peas.views.pena', name='pena'),
 )
 
 
 @login_required
 @csrf_protect
-def comment_pena(request, slug):
+def comment_pena(request, slug=None):
     """Comentar peña"""
     if request.method == 'POST':
         pena_comment_form = PenaCommentform(request.POST)
                     }
             new_comment_pena_save = PenaComment(**new_comment_pena)
             new_comment_pena_save.save()
-            return simple.redirect_to(request, u"%s#comentario" % new_comment_pena['pena'].get_absolute_url())
+            return simple.redirect_to(request)
     return pena(request, slug=slug)
 
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.