class ITune(Interface): dexteritytextindexer.searchable('title') model.primary('title') title = schema.TextLine( title=_(u'Tune name'), description=_(u'The main name as you know this tune'), ) description = schema.Text( title=_(u'Short description'), description=_(u'Short tune description for, i.e., tooltips'), required=False, )
def handleSave(self, action): data, errors = self.extractData() if errors: self.status = _('Please correct errors') return self._handleApply(data) contextURL = self.context.absolute_url() self.request.response.redirect(contextURL)
def handleRecord(self, action): data, errors = self.extractData() if errors: self.status = _('Please correct errors') return tune = self._handleApply(data) tuneId = tune.getId() addRecordd = self.context.absolute_url() addRecordd += '/' + tuneId + '/++add++record' self.request.response.redirect(addRecordd)
class AddForm(add.DefaultAddForm): portal_type = 'abc' ignoreContext = True label = _(u'Add a new ABC !') def update(self): super(add.DefaultAddForm, self).update() title = self.request.form.get('title') if title: self.widgets['title'].value = u'**ABC**' + title.decode('utf-8') # import pdb;pdb.set_trace() def updateWidgets(self): super(add.DefaultAddForm, self).updateWidgets() @button.buttonAndHandler(_(u'Save this abc'), name='save_this_abc') def handleApply(self, action): data, errors = self.extractData() if errors: self.status = _('Please correct errors') return try: # par defaut, les commentaires sont de-actives # ils peuvent etre re-actives par element data['IAllowDiscussion.allow_discussion'] = False except Exception: pass try: obj = self.createAndAdd(data) logger.info(obj.absolute_url()) contextURL = self.context.absolute_url() contextURL += '/' + obj.getId() self.request.response.redirect(contextURL) except Exception: raise @button.buttonAndHandler(_(u'Cancel this abc')) def handleCancel(self, action): data, errors = self.extractData() # context is the thesis repo contextURL = self.context.absolute_url() self.request.response.redirect(contextURL)
def handleAddABC(self, action): data, errors = self.extractData() if errors: self.status = _('Please correct errors') return tune = self._handleApply(data) tuneId = tune.getId() # import pdb;pdb.set_trace() abcTitle = tune.title.encode('utf-8') addAbc = self.context.absolute_url() addAbc += '/' + tuneId + '/++add++abc?title=' addAbc += base64.b64encode(abcTitle) self.request.response.redirect(addAbc)
def javascript(self): auth = self.abcAutorized() authjs = u'true' if not auth: authjs = u'false' js = u"""<script type="text/javascript">\n""" js += u'tuneModified = ' + _(u"'The tune was modified... continue ?'") js += u';\n' js += u'var uuid = "' + api.content.get_uuid(self.context) + '";\n' js += u'var auth = ' + authjs + ';\n' js += u'</script>' # import pdb;pdb.set_trace() return js
def javascript(self): auth = self.abcAutorized() authjs = u'true' if not auth: authjs = u'false' js = u'<script type="text/javascript">\n' js += u'tuneModified = ' + _(u'"The tune was modified... continue ?"') js += u';\n' js += u'var uuid = "' + api.content.get_uuid(self.context) + '";\n' js += u'var auth = ' + authjs + ';\n' js += u'</script>' # import pdb;pdb.set_trace() return js
def handleApply(self, action): data, errors = self.extractData() if errors: self.status = _('Please correct errors') return try: # par defaut, les commentaires sont de-actives # ils peuvent etre re-actives par element data['IAllowDiscussion.allow_discussion'] = False except Exception: pass try: obj = self.createAndAdd(data) logger.info(obj.absolute_url()) contextURL = self.context.absolute_url() contextURL += '/' + obj.getId() self.request.response.redirect(contextURL) except Exception: raise
class AddForm(add.DefaultAddForm): portal_type = 'tune' ignoreContext = True label = _(u'Add a new tune !') def update(self): super(add.DefaultAddForm, self).update() def updateWidgets(self): super(add.DefaultAddForm, self).updateWidgets() def _handleApply(self, data): try: # par defaut, les commentaires sont de-actives # ils peuvent etre re-actives par element data['IAllowDiscussion.allow_discussion'] = False except Exception: pass try: tune = self.createAndAdd(data) # logger.info('ajout 1 tune') return tune except Exception: raise @button.buttonAndHandler(_(u'Save this tune'), name='save_this_tune') def handleSave(self, action): data, errors = self.extractData() if errors: self.status = _('Please correct errors') return self._handleApply(data) contextURL = self.context.absolute_url() self.request.response.redirect(contextURL) @button.buttonAndHandler(_(u'Cancel this tune')) def handleCancel(self, action): data, errors = self.extractData() contextURL = self.context.absolute_url() self.request.response.redirect(contextURL) @button.buttonAndHandler(_(u'save and add abc')) def handleAddABC(self, action): data, errors = self.extractData() if errors: self.status = _('Please correct errors') return tune = self._handleApply(data) tuneId = tune.getId() # import pdb;pdb.set_trace() abcTitle = tune.title.encode('utf-8') addAbc = self.context.absolute_url() addAbc += '/' + tuneId + '/++add++abc?title=' addAbc += base64.b64encode(abcTitle) self.request.response.redirect(addAbc) @button.buttonAndHandler(_(u'save and add record')) def handleRecord(self, action): data, errors = self.extractData() if errors: self.status = _('Please correct errors') return tune = self._handleApply(data) tuneId = tune.getId() addRecordd = self.context.absolute_url() addRecordd += '/' + tuneId + '/++add++record' self.request.response.redirect(addRecordd)
class importAbcFile(form.Form): fields = field.Fields(IImportABC) ignoreContext = True label = _(u'import ABC file...') description = _(u'the file must contain only abc tunes well formated') def cleanup(self, tune): returned = [] for line in tune: if line[:12] != '%ABCKeyWord:': returned.append(line) return returned def getTuneId(self, tune): """returns an Id from the title tune""" context = self.context normalizer = getUtility(INormalizer) for tuneLine in tune: if tuneLine[:2] == 'T:': title = tuneLine.split(':')[1] tuneId = normalizer.normalize(title, locale='fr') # logger.info("getTuneId:" + tuneLine + ':' + tuneId) idOrigine = tuneId i = 1 while tuneId in context.keys(): tuneId = idOrigine + '-' + str(i).zfill(3) i += 1 return tuneId return 'collective.abctune.NoId' def getTuneTitle(self, tune): """returns a title from the title tune""" for tuneLine in tune: if tuneLine[:2] == 'T:': title = tuneLine.split(':')[1] return title return 'collective.abctune.NoTitle' def getSubject(self, tune): subjects = [] for line in tune: if line[:12] == '%ABCKeyWord:': subject = line.split(':')[1] subjects.append(subject) return subjects def createTune(self, newtune=None, tuneId=None, tuneTitle=None, tuneSubject=None): tune = api.content.create(container=self.context, type='tune', title=tuneTitle, subject=tuneSubject) try: tune.allow_discussion = False except Exception: pass tune.reindexObject() logger.info('Tune created: ' + tune.title) abc = api.content.create(container=tune, type='abc', title=tuneTitle, abc=newtune) try: abc.allow_discussion = False except Exception: pass abc.reindexObject() logger.info('ABC created: ' + abc.title) return (tune, abc) def processABC(self, data): data = removeNonAscii(data) rawtunes = data.split('X:') for rawtune in rawtunes: # logger.info(line) # logger.info('-----------') tune = rawtune.split('\n')[1:] tune.insert(0, 'X:1') newtune = ('\n').join(self.cleanup(tune)) tuneId = self.getTuneId(tune) tuneTitle = self.getTuneTitle(tune) tuneSubject = self.getSubject(tune) if tuneId != 'collective.abctune.NoId': self.createTune(newtune=newtune, tuneId=tuneId, tuneTitle=tuneTitle, tuneSubject=tuneSubject) @button.buttonAndHandler(_(u'import tunes from this file')) def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return dataABC = data['data'].data self.processABC(dataABC) self.status = 'Thank you very much!' self.request.response.redirect(self.context.absolute_url()) @button.buttonAndHandler(_(u'Cancel import')) def handleCancel(self, action): """User cancelled. Redirect back to the front page. """ self.request.response.redirect(self.context.absolute_url())
class IImportABC(interface.Interface): data = NamedFile(title=_(u'file containing ABC tunes to import'))
from zope.interface import Interface # see plone.autoform.directives.txt from plone.autoform import directives as form from plone.supermodel import model from collective import dexteritytextindexer from plone.namedfile.field import NamedBlobImage from plone.namedfile.field import NamedBlobFile from zope.publisher.interfaces.browser import IDefaultBrowserLayer class ICollectiveAbctuneLayer(IDefaultBrowserLayer): """Marker interface that defines a browser layer.""" tunearea_title = _(u"The area from which the tune is from") tunearea_desc = _(u"More detailed origin of the tune, from O: field") tunecountry_title = u"The origin country of the tune, " tunecountry_title += u"from first part of O: field" tunecountry_title = _(tunecountry_title) score_desc = _(u'The score of the tune as png image') class Iabctune(Interface): dexteritytextindexer.searchable('abc') model.primary('abc') abc = schema.Text(title=_(u"Tune abc"), description=_(u'The tune in abc format'),) dexteritytextindexer.searchable('tunekeys')
class IABC(Interface): """ One tune or tune version in ABC format """ dexteritytextindexer.searchable('title') model.primary('title') title = schema.TextLine( title=_(u'ABC Tune name'), description=_(u'The name as you know this tune'), ) dexteritytextindexer.searchable('abc') model.primary('abc') abc = schema.Text( title=_(u'Tune abc'), description=_(u'The tune in abc format'), defaultFactory=abcDefaultValue, ) dexteritytextindexer.searchable('tunekeys') form.omitted('tunekeys') tunekeys = schema.List( title=u'keys', description=u'set by abc content', required=False, value_type=schema.TextLine(required=False), ) dexteritytextindexer.searchable('tunetype') form.omitted('tunetype') tunetype = schema.TextLine( title=_(u'The type of the tune'), description=_(u'from the field R:'), required=False, ) # NOTE: as specified in the v2.1 standard, A: field is deprecated # so, only O: is used to specified country and areas... separated # by ';' dexteritytextindexer.searchable('tunearea') form.omitted('tunearea') tunearea = schema.TextLine( title=tunearea_title, description=tunearea_desc, required=False, ) dexteritytextindexer.searchable('tunecountry') form.omitted('tunecountry') tunecountry = schema.TextLine( title=tunecountry_title, description=_(u'The country'), required=False, ) form.omitted('score') score = NamedBlobImage( title=_(u'Score'), description=score_desc, required=False, ) form.omitted('svgscore') svgscore = NamedBlobFile( title=_(u'SVG Score'), description=_(u'The score of the tune as SVG'), required=False, ) form.omitted('pdfscore') pdfscore = NamedBlobFile( title=_(u'PDF Score'), description=_(u'The score of the tune as PDF'), required=False, ) form.omitted('midi') midi = NamedBlobFile( title=_(u'Midi'), description=_(u'Midi sound of the tune'), required=False, ) form.omitted('mp3') mp3 = NamedBlobFile( title=_(u'mp3'), description=_(u'The mp3 sound of the tune'), required=False, ) form.omitted('ogg') ogg = NamedBlobFile( title=_(u'ogg'), description=_(u'The ogg sound of the tune'), required=False, )
from plone.namedfile.field import NamedBlobFile # this import Must be AFTER NamedBlobFile # if not, tests are broken !!! from collective import dexteritytextindexer from plone.namedfile.field import NamedBlobImage from plone.supermodel import model from zope import schema from zope.interface import Interface from zope.publisher.interfaces.browser import IDefaultBrowserLayer class ICollectiveAbctuneLayer(IDefaultBrowserLayer): """Marker interface that defines a browser layer.""" tunearea_title = _(u'The area from which the tune is from') tunearea_desc = _(u'More detailed origin of the tune, from O: field') tunecountry_title = u'The origin country of the tune, ' tunecountry_title += u'from first part of O: field' tunecountry_title = _(tunecountry_title) score_desc = _(u'The score of the tune as png image') def abcDefaultValue(): # http://docs.python.org/2.6/whatsnew/2.3.html#date-time-type # To get hold of the folder, do: context = data.context tune = u""" X:1 T:Ashplant, The %%MIDI chordvol 30 %%MIDI bassvol 30