source: main/branches/3D/openPLM/document3D/models.py @ 592

Revision 592, 2.6 KB checked in by agalech, 9 years ago (diff)

add document3d app

Line 
1from django.db import models
2from django.contrib import admin
3from openPLM.plmapp.models import *
4from openPLM.plmapp.controllers import DocumentController
5
6from django.db.models import get_model
7# Create your models here.
8
9class Document3D(Document):
10
11   
12   
13    @property
14    def menu_items(self):
15        items = list(super(Document3D, self).menu_items)       
16        items.extend(["3D"])
17        return items
18           
19       
20       
21
22
23admin.site.register(Document3D)
24
25
26
27
28media3Djs = DocumentStorage(location=settings.MEDIA_ROOT+"3D/")   
29
30class stp_to_jss(models.Model):
31
32    js = models.FileField(upload_to='.',storage=media3Djs)
33    stp = models.ForeignKey(DocumentFile)   
34
35   
36   
37#restricciones fichero:si no se genera el jss , o si el jss generado es demasiado grande
38class Document3DController(DocumentController):
39
40    def handle_added_file(self, doc_file):
41        from openPLM.document3D.aficher import convertir_STP_to_JSS
42   
43        fileName, fileExtension = os.path.splitext(doc_file.filename)
44        if fileExtension.upper()== '.STP':
45            res=stp_to_jss.objects.filter()
46           
47           
48           
49            #delete old jss file (only neccesary in case of check-in -> handle)
50            multi_jss=stp_to_jss.objects.filter(stp=doc_file)
51            count=multi_jss.count()
52            for i in range(count): 
53                os.remove(settings.MEDIA_ROOT+"3D/"+multi_jss[count-i-1].js.name)
54                print "Deleting .jss associes :" , (settings.MEDIA_ROOT+"3D/"+multi_jss[count-i-1].js.name)
55                multi_jss[count-i-1].delete()
56
57            # end delteting
58           
59            if not convertir_STP_to_JSS(doc_file):
60                return False           
61
62            return True
63           
64    def delete_file(self, doc_file):
65
66       
67        fileName, fileExtension = os.path.splitext(doc_file.filename)
68        if fileExtension.upper()== '.STP':
69       
70            multi_jss=stp_to_jss.objects.filter(stp=doc_file)
71
72            count=multi_jss.count()
73            for i in range(count):
74                print "el nombre es : " ,  multi_jss[count-i-1].js.name
75                os.remove(settings.MEDIA_ROOT+"3D/"+multi_jss[count-i-1].js.name)
76                print "Deleting .jss associes :" , (settings.MEDIA_ROOT+"3D/"+multi_jss[count-i-1].js.name)
77                multi_jss[count-i-1].delete()
78
79
80            super(Document3DController, self).delete_file(doc_file)
81           
82
83
84           
85        else:
86       
87            super(Document3DController, self).delete_file(doc_file)
88
89
90class Arbre:
91
92  def __init__(self, datos,):
93    self.datos
94    self.nom = nom
95    self.hijos  = []
96
97           
98
Note: See TracBrowser for help on using the repository browser.