Commits

Vasil Vangelovski  committed 66f68c9

changed css url generation scheme

  • Participants
  • Parent commits 8f2850d

Comments (0)

Files changed (3)

File 960ls/models.py

     id = Column(Integer, primary_key=True)
     html = Column(UnicodeText())
     css = Column(UnicodeText())
-
-    def __init__(self, html = None, css = None):
+    css_url = Column(String(150))
+    
+    def __init__(self, html = None, css = None, css_url = None):
         self.html = html
         self.css = css
+        self.css_url = css_url
 
     def __repr__(self):
         return '<Template %s>' % (str(self.id))
 
 
 if __name__ == '__main__':
-    init_db()
+    init_db()

File 960ls/templates/saved_template.html

 		padding-left: 10px;
                 color: #000;
 	}
+        #css_embed_code_highlight{
+           font-size:10px;
+        }
+
 </style>
 <h2>CSS Link Code:</h2>
 <div id="css_embed_code_highlight" class="highlight">

File 960ls/webapp.py

 import os
 import sys
 import errno
+import uuid
 from datetime import datetime
 
 SITE_DOMAIN = '960ls.atomidata.com'
     
     
         
-    cssperma = 'http://%s/static/cssserve/%s/%s.css'%(SITE_DOMAIN, '/'.join(list(str(template.id))), str(template.id))
+    cssperma = template.css_url
+    
     pygmented_css_link =  highlight('<link rel="stylesheet" type="text/css" href="%s">'%cssperma,
                                     CssLexer(),
                                     HtmlFormatter(style = 'bw',
                                gutter_width = long( request.form.get('gutter_width', DEFAULT_GUT_WIDTH)),
                                column_number = long( request.form.get('column_number', DEFAULT_COL_NUM)),
                               )
+
+    n = datetime.now()
+    root = os.path.dirname(__file__)
+    csspath = os.path.join(os.path.join(root, 'static'), 'cssserve')
+    csspath = os.path.join(csspath, str(n.year))
+    csspath = os.path.join(csspath, str(n.month))
+    csspath = os.path.join(csspath, str(n.day))
     
+    if not os.path.isdir(csspath):
+        mkdir_p(csspath)
+
+    filename = "%s.css"%uuid.uuid4().hex
     
-    
-    template = Template(html = unicode(request.form.get('html_code')), css = unicode(csscontent))
-    root = os.path.dirname(__file__)
+    cssf = open(os.path.join(csspath, filename), 'w')
+
+    cssf.write(csscontent)
+    cssf.close()
+
+    cssperma = 'http://%s/static/cssserve/%s/%s'%(SITE_DOMAIN,
+                                                      '/'.join([str(n.year), str(n.month), str(n.day)]), filename)
+    template = Template(html = unicode(request.form.get('html_code')), css = unicode(csscontent), css_url = cssperma)
     
     db_session.add(template)
     db_session.commit()
-    csspath = os.path.join(os.path.join(root, 'static'), 'cssserve')
-    for c in list(str(template.id)):
-        csspath = os.path.join(csspath, c)
-    if not os.path.isdir(csspath):
-        mkdir_p(csspath)
-    cssf = open(os.path.join(csspath, "%s.css"%str(template.id)), 'w')
-    cssf.write(csscontent)
-    cssf.close()
+
     return template.id
 
 @app.route("/zipped/<int:template_id>")