Guest User

Untitled

a guest
Jul 18th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. from django.db import models
  2. from datetime import datetime
  3. from django.db import models
  4. from django import forms
  5. from django.forms import ModelForm
  6. from django.db.models.signals import post_save
  7. import os
  8.  
  9.  
  10. SOUNDTYPE_STATUS = (
  11. (0, 'Waveform'),
  12. (1, 'Spectrum'),
  13. )
  14.  
  15. #COLOR_STATUS = (
  16. # (1, 'Black'),
  17. # (2, 'Blue'),
  18. # (3, 'Red'),
  19. # (4, 'Orange'),
  20. # (5, 'Green'),
  21. # (6, 'Brown'),
  22. # (7, 'Purple'),
  23. # (8, 'White'),
  24. # (9, 'Cyan'),
  25. # (10, 'Beige'),
  26. #)
  27. COLOR_STATUS = (
  28. (1, 1),
  29. (2, 2),
  30. (3, 3),
  31. (4, 4),
  32. (5, 5),
  33. (6, 6),
  34. (7, 7),
  35. (8, 8),
  36. (9, 9),
  37. (10,10),
  38. )
  39.  
  40. class NewSoundmodel(models.Model):
  41.  
  42. waveform = models.ImageField(upload_to="audio/%Y%m%d/%H%m%S", null=True, blank=True)
  43. spectrum = models.ImageField(upload_to="audio/%Y%m%d/%H%m%S",null=True, blank=True)
  44.  
  45. # Create your models here.
  46. class Soundmodel(models.Model):
  47. audiofile = models.FileField(upload_to="audio/%Y%m%d/%H%m%S")
  48. comment = models.CharField("comment", max_length=512, blank=True, null=True)
  49.  
  50. comment = models.CharField("comment", max_length=512, blank=True, null=True)
  51. time_of_save = models.DateTimeField("Date & Time of Save", default=datetime.now()) #, auto_now=True)
  52. view_type = models.IntegerField(choices=SOUNDTYPE_STATUS, blank=True, null=True)
  53. sound_color = models.IntegerField(choices=COLOR_STATUS, blank=True,null=True)
  54. def __unicode__(self):
  55. return str(self.audiofile)
  56.  
  57. class SoundForm(ModelForm):
  58. class Meta:
  59. model = Soundmodel
  60. exclude = ['waveform','spectrum','time_of_save']
  61.  
  62. class NewSoundForm(ModelForm):
  63. class Meta:
  64. model = NewSoundmodel
  65.  
  66.  
  67. def SoundSaveAfter_Handler(sender, instance, **kwargs):
  68. print "got to new save!"
  69.  
  70. sm = NewSoundmodel()
  71. print 'sc=' + str(instance.sound_color)
  72. ws = os.path.join(os.path.dirname(__file__), 'wavescripts')
  73. #st_audio = os.path.join(os.path.dirname(__file__), 'static\\audio\\')
  74. os.system('python '+ ws +'\\wav2png.py -c ' + str(instance.sound_color) + ' -h 171 ' + str(instance.audiofile.url))
  75. #p = Popen("python" + " wav2png.py -c " + str(instance.sound_color) + " -h 171 " + str(instance.audiofile.url), shell=True)
  76. # sts = os.waitpid(p.pid, 0)[1]
  77.  
  78. sm.id= instance.id
  79. sm.waveform = str(instance.audiofile.url) + "_w.png"
  80. sm.spectrum = str(instance.audiofile.url) + "_s.jpg"
  81. sm.save()
  82.  
  83. post_save.connect(SoundSaveAfter_Handler, sender = Soundmodel)
Add Comment
Please, Sign In to add comment