コード例 #1
0
ファイル: content.py プロジェクト: MahmoudGamalElDeen/tagger
 def _set_name(self, val):
     if self.parent.language_id == self.language_id:
         if self.parent.string_id == 'default':
             self.parent.article.id = make_id(val)
         else:
             self.parent.string_id = make_id(val)
     self._name = val
コード例 #2
0
    def post(self,
             mediatype,
             languageid,
             name,
             uri=None,
             uploadfile=None,
             fallbackfile=None,
             description=None,
             tagids=None):
        """create a new Media"""
        user = tmpl_context.user
        lang = tmpl_context.lang or DBSession.query(Language).first().id

        # TODO: redirect to "new" with errors instead of raising an exception
        if mediatype == 'image':
            if uploadfile is None:
                raise HTTPClientError(_('No image uploaded'))
            origname, ext = os.path.splitext(uploadfile.filename)
            filename = '%s%s' % (make_id(name), ext)
            tmpf = open(os.path.join(G.upload_dir, filename), 'w+b')
            shutil.copyfileobj(uploadfile.file, tmpf)
            tmpf.close()
            uri = filename
        elif mediatype == 'video':
            if uploadfile is None or fallbackfile is None:
                raise HTTPClientError(_('No video or no fallback uploaded'))
            # copy video file in the upload area
            origname, ext = os.path.splitext(uploadfile.filename)
            filename = '%s%s' % (make_id(name), ext)
            tmpf = open(os.path.join(G.upload_dir, filename), 'w+b')
            shutil.copyfileobj(uploadfile.file, tmpf)
            tmpf.close()

            # copy fallback video file in the upload area
            origname, fallbackext = os.path.splitext(fallbackfile.filename)
            fallbackname = '%s%s' % (make_id(name), fallbackext)
            fallbacktmpf = open(os.path.join(G.upload_dir, fallbackname),
                                'w+b')
            shutil.copyfileobj(fallbackfile.file, fallbacktmpf)
            fallbacktmpf.close()

            uri = filename
        elif mediatype == 'youtube':
            if not uri:
                raise HTTPClientError(_('No video id'))
        elif mediatype == 'vimeo':
            if not uri:
                raise HTTPClientError(_('No video id'))

        media = Media(mediatype, name, uri, user, languageid, description)
        DBSession.add(media)

        tags = tags_from_string(tagids, lang=lang)
        media.tags[:] = tags

        flash('%s %s' % (_('Created Media:'), media.id), 'ok')
        return dict(redirect_to=url('/admin/media/'))
コード例 #3
0
ファイル: content.py プロジェクト: MahmoudGamalElDeen/tagger
 def __init__(self, name, uri, user, lang, description=None):
     self.id = make_id(name)
     self.uri = uri
     self.user = user
     self.data.append(LinkData(name, lang, description))
     self.associable = Associable(u'link')
     now = datetime.now()
     self._created = now        
     self.associable._created = now
コード例 #4
0
ファイル: content.py プロジェクト: MahmoudGamalElDeen/tagger
 def __init__(self, title, category, lang, user, text=None):
     self.id = make_id(title)
     self.category = category
     self.user = user
     self.pages.append(Page(title, lang, user, text=text, is_default=True))
     self.associable = Associable(u'article')
     now = datetime.now()
     self._created = now
     self.associable._created = now
     self.published = False
コード例 #5
0
ファイル: content.py プロジェクト: MahmoudGamalElDeen/tagger
 def _set_name(self, val):
     if self.parent.language_id == self.language_id:
         self.parent.id = make_id(val)
     self._name = val
コード例 #6
0
ファイル: content.py プロジェクト: MahmoudGamalElDeen/tagger
 def __init__(self, name, lang, user, text=None, is_default=False):
     self.string_id = is_default and u'default' or make_id(name)
     self.data.append(PageData(name, lang, text))
     self.user = user
     now = datetime.now()
     self._created = now        
コード例 #7
0
ファイル: content.py プロジェクト: MahmoudGamalElDeen/tagger
 def __init__(self, name, lang, description=None):
     self.id = make_id(name)
     self.data.append(CategoryData(name, lang, description))
コード例 #8
0
ファイル: content.py プロジェクト: MahmoudGamalElDeen/tagger
 def __init__(self, name, lang):
     self.id = make_id(name)
     self.data.append(TagData(name, lang))