Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar_network/model
diff options
context:
space:
mode:
Diffstat (limited to 'sugar_network/model')
-rw-r--r--sugar_network/model/__init__.py2
-rw-r--r--sugar_network/model/artifact.py6
-rw-r--r--sugar_network/model/context.py71
-rw-r--r--sugar_network/model/routes.py6
4 files changed, 63 insertions, 22 deletions
diff --git a/sugar_network/model/__init__.py b/sugar_network/model/__init__.py
index bb70a8a..c846bc7 100644
--- a/sugar_network/model/__init__.py
+++ b/sugar_network/model/__init__.py
@@ -16,7 +16,7 @@
from sugar_network.model.routes import VolumeRoutes, FrontRoutes
-CONTEXT_TYPES = ['activity', 'project', 'package', 'content']
+CONTEXT_TYPES = ['activity', 'group', 'package', 'book']
NOTIFICATION_TYPES = ['create', 'update', 'delete', 'vote']
FEEDBACK_TYPES = ['question', 'idea', 'problem']
ARTIFACT_TYPES = ['instance', 'preview']
diff --git a/sugar_network/model/artifact.py b/sugar_network/model/artifact.py
index e461c4d..0a0239d 100644
--- a/sugar_network/model/artifact.py
+++ b/sugar_network/model/artifact.py
@@ -13,8 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from os.path import join
-
from sugar_network import db, model, static
from sugar_network.toolkit.router import Blob, ACL
@@ -62,8 +60,8 @@ class Artifact(db.Resource):
if value:
return value
return Blob({
- 'url': '/static/images/missing.png',
- 'blob': join(static.PATH, 'images', 'missing.png'),
+ 'url': '/static/images/missing-preview.png',
+ 'blob': static.path('images', 'missing-preview.png'),
'mime_type': 'image/png',
})
diff --git a/sugar_network/model/context.py b/sugar_network/model/context.py
index 869ad6c..461960b 100644
--- a/sugar_network/model/context.py
+++ b/sugar_network/model/context.py
@@ -13,9 +13,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from os.path import join
+import hashlib
+from cStringIO import StringIO
-from sugar_network import db, model, static
+from sugar_network import db, model, static, toolkit
from sugar_network.toolkit.router import Blob, ACL
@@ -30,6 +31,13 @@ class Context(db.Resource):
def type(self, value):
if value and 'package' in value and 'common' not in self['layer']:
self['layer'] = tuple(self['layer']) + ('common',)
+ if 'artifact_icon' not in self:
+ for name in ('activity', 'book', 'group'):
+ if name not in self.type:
+ continue
+ with file(static.path('images', name + '.svg')) as f:
+ Context.populate_images(self, f.read())
+ break
return value
@db.indexed_property(slot=1, prefix='S', full_text=True, localized=True)
@@ -59,13 +67,13 @@ class Context(db.Resource):
if 'package' in self['type']:
return Blob({
'url': '/static/images/package.png',
- 'blob': join(static.PATH, 'images', 'package.png'),
+ 'blob': static.path('images', 'package.png'),
'mime_type': 'image/png',
})
else:
return Blob({
'url': '/static/images/missing.png',
- 'blob': join(static.PATH, 'images', 'missing.png'),
+ 'blob': static.path('images', 'missing.png'),
'mime_type': 'image/png',
})
@@ -73,21 +81,35 @@ class Context(db.Resource):
def artifact_icon(self, value):
if value:
return value
- return Blob({
- 'url': '/static/images/missing.svg',
- 'blob': join(static.PATH, 'images', 'missing.svg'),
- 'mime_type': 'image/svg+xml',
- })
+ if 'package' in self['type']:
+ return Blob({
+ 'url': '/static/images/package.svg',
+ 'blob': static.path('images', 'package.svg'),
+ 'mime_type': 'image/png',
+ })
+ else:
+ return Blob({
+ 'url': '/static/images/missing.svg',
+ 'blob': static.path('images', 'missing.svg'),
+ 'mime_type': 'image/svg+xml',
+ })
@db.blob_property(mime_type='image/png')
def preview(self, value):
if value:
return value
- return Blob({
- 'url': '/static/images/missing.png',
- 'blob': join(static.PATH, 'images', 'missing.png'),
- 'mime_type': 'image/png',
- })
+ if 'package' in self['type']:
+ return Blob({
+ 'url': '/static/images/package-preview.png',
+ 'blob': static.path('images', 'package-preview.png'),
+ 'mime_type': 'image/png',
+ })
+ else:
+ return Blob({
+ 'url': '/static/images/missing-preview.png',
+ 'blob': static.path('images', 'missing-preview.png'),
+ 'mime_type': 'image/png',
+ })
@db.indexed_property(slot=3, default=0, acl=ACL.READ | ACL.CALC)
def downloads(self, value):
@@ -130,3 +152,24 @@ class Context(db.Resource):
@db.stored_property(typecast=dict, default={}, acl=ACL.PUBLIC | ACL.LOCAL)
def packages(self, value):
return value
+
+ @staticmethod
+ def populate_images(props, svg):
+ if 'guid' in props:
+ from sugar_network.toolkit.sugar import color_svg
+ svg = color_svg(svg, props['guid'])
+
+ def convert(w, h):
+ png = toolkit.svg_to_png(svg, w, h)
+ return {'blob': png,
+ 'mime_type': 'image/png',
+ 'digest': hashlib.sha1(png.getvalue()).hexdigest(),
+ }
+
+ props['artifact_icon'] = {
+ 'blob': StringIO(svg),
+ 'mime_type': 'image/svg+xml',
+ 'digest': hashlib.sha1(svg).hexdigest(),
+ }
+ props['icon'] = convert(55, 55)
+ props['preview'] = convert(140, 140)
diff --git a/sugar_network/model/routes.py b/sugar_network/model/routes.py
index 447ff30..c5c4929 100644
--- a/sugar_network/model/routes.py
+++ b/sugar_network/model/routes.py
@@ -15,7 +15,7 @@
import logging
import mimetypes
-from os.path import join, split
+from os.path import split
from sugar_network import static, db
from sugar_network.toolkit.router import route, fallbackroute, Blob, ACL
@@ -99,7 +99,7 @@ class FrontRoutes(object):
@fallbackroute('GET', ['static'])
def get_static(self, request):
- path = join(static.PATH, *request.path[1:])
+ path = static.path(*request.path[1:])
if not mimetypes.inited:
mimetypes.init()
mime_type = mimetypes.types_map.get('.' + path.rsplit('.', 1)[-1])
@@ -116,7 +116,7 @@ class FrontRoutes(object):
@route('GET', ['favicon.ico'])
def favicon(self, request, response):
return Blob({
- 'blob': join(static.PATH, 'favicon.ico'),
+ 'blob': static.path('favicon.ico'),
'mime_type': 'image/x-icon',
})