legacy-dotfiles/projects/models.py

60 lines
1.9 KiB
Python
Raw Normal View History

2011-10-17 01:34:04 +02:00
from django.db import models
from main.models import Tag, Activity
from django.db.models.signals import post_save, post_delete
class Language(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
class Screenshot(models.Model):
url = models.URLField(max_length=255)
description = models.CharField(max_length=300)
def __unicode__(self):
return self.description
class Project(models.Model):
STATUS_CHOICES = (
('active', "Active"),
('onhold', "On Hold"),
('dropped', "Dropped"),
)
slug = models.SlugField(max_length=255, primary_key=True)
name = models.CharField(max_length=300)
status = models.CharField(max_length=8, choices=STATUS_CHOICES)
tagline = models.CharField(max_length=140, null=True, blank=True)
languages = models.ManyToManyField(Language, null=True, blank=True)
source_url = models.URLField(max_length=255, null=True, blank=True)
bugtracker_url = models.URLField(max_length=255, null=True, blank=True)
wiki_url = models.URLField(max_length=255, null=True, blank=True)
description = models.TextField()
screenshots = models.ForeignKey(Screenshot, null=True, blank=True)
# tags = models.ManyToManyField(Tag, null=True, blank=True)
def __unicode__(self):
return self.name
def project_saved_callback(sender, **kwargs):
if kwargs['created']:
acttype = 'add'
else:
acttype = 'edit'
a = Activity(actcategory='project',
actdescription=kwargs["instance"].name,
acttype = acttype,
objpk = kwargs["instance"].pk)
a.save()
def project_deleted_callback(sender, **kwargs):
a = Activity(actcategory='project',
actdescription=kwargs["instance"].name,
acttype = 'delete')
a.save()
post_save.connect(project_saved_callback, sender=Project)
post_delete.connect(project_deleted_callback, sender=Project)