Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- from datetime import datetime
- from django.db import models
- from django import forms
- from django.forms import ModelForm
- from django.db.models.signals import post_save
- import os
- SOUNDTYPE_STATUS = (
- (0, 'Waveform'),
- (1, 'Spectrum'),
- )
- #COLOR_STATUS = (
- # (1, 'Black'),
- # (2, 'Blue'),
- # (3, 'Red'),
- # (4, 'Orange'),
- # (5, 'Green'),
- # (6, 'Brown'),
- # (7, 'Purple'),
- # (8, 'White'),
- # (9, 'Cyan'),
- # (10, 'Beige'),
- #)
- COLOR_STATUS = (
- (1, 1),
- (2, 2),
- (3, 3),
- (4, 4),
- (5, 5),
- (6, 6),
- (7, 7),
- (8, 8),
- (9, 9),
- (10,10),
- )
- class NewSoundmodel(models.Model):
- waveform = models.ImageField(upload_to="audio/%Y%m%d/%H%m%S", null=True, blank=True)
- spectrum = models.ImageField(upload_to="audio/%Y%m%d/%H%m%S",null=True, blank=True)
- # Create your models here.
- class Soundmodel(models.Model):
- audiofile = models.FileField(upload_to="audio/%Y%m%d/%H%m%S")
- comment = models.CharField("comment", max_length=512, blank=True, null=True)
- comment = models.CharField("comment", max_length=512, blank=True, null=True)
- time_of_save = models.DateTimeField("Date & Time of Save", default=datetime.now()) #, auto_now=True)
- view_type = models.IntegerField(choices=SOUNDTYPE_STATUS, blank=True, null=True)
- sound_color = models.IntegerField(choices=COLOR_STATUS, blank=True,null=True)
- def __unicode__(self):
- return str(self.audiofile)
- class SoundForm(ModelForm):
- class Meta:
- model = Soundmodel
- exclude = ['waveform','spectrum','time_of_save']
- class NewSoundForm(ModelForm):
- class Meta:
- model = NewSoundmodel
- def SoundSaveAfter_Handler(sender, instance, **kwargs):
- print "got to new save!"
- sm = NewSoundmodel()
- print 'sc=' + str(instance.sound_color)
- ws = os.path.join(os.path.dirname(__file__), 'wavescripts')
- #st_audio = os.path.join(os.path.dirname(__file__), 'static\\audio\\')
- os.system('python '+ ws +'\\wav2png.py -c ' + str(instance.sound_color) + ' -h 171 ' + str(instance.audiofile.url))
- #p = Popen("python" + " wav2png.py -c " + str(instance.sound_color) + " -h 171 " + str(instance.audiofile.url), shell=True)
- # sts = os.waitpid(p.pid, 0)[1]
- sm.id= instance.id
- sm.waveform = str(instance.audiofile.url) + "_w.png"
- sm.spectrum = str(instance.audiofile.url) + "_s.jpg"
- sm.save()
- post_save.connect(SoundSaveAfter_Handler, sender = Soundmodel)
Add Comment
Please, Sign In to add comment