예제 #1
0
    def save_attachment(self, target_id, _id, text, attachment):
        timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
        if _id == '':
            attachment_o = dict(type='attachment', _id=genUID(type='attachment'), target_id=target_id, attachment_state=0, tags=list(), history=list(), text='')
            attachment_change='new'
            attachment_o['timestamp'] = timestamp
        else:
            attachment_o = common_couch.getAttachment(holly_couch,  _id)
            history = attachment_o['history']
            if history == None:
                history = list()
            else:
                history.append([timestamp, attachment_o['text']])
            attachment_o['history'] = history
            attachment_change = 'changed'
        
        attachment_o['last_changed_by'] = getLoggedInUserId(request)
        attachment_o['text'] = text
        holly_couch[attachment_o['_id']] = attachment_o
        
        file = request.POST['attachment']

        if file != '':
            holly_couch.put_attachment(attachment_o, attachment.file, filename=attachment.filename)
        
        # TODO FIX BELOW
        #remember_attachment_change(holly_couch, target_id=target_id, attachment_id=attachment_o['_id'], changed_by=getLoggedInUserId(request), attachment_change=attachment_change)

        # TODO: where do we go from here?
        redirect_to = '/'
        if 'visiting_group' in attachment_o['target_id']:
            redirect_to = '/visiting_group/show_visiting_group?visiting_group_id='+attachment_o['target_id']
        raise redirect(redirect_to)
예제 #2
0
 def edit_attachment(self, note_id=None, visiting_group_id=None):
     attachment_id=note_id
     tmpl_context.form = create_edit_attachment_form
     if attachment_id == '':
         attachment_o = DataContainer(text='', target_id=target_id, _id='')
     else:
         attachment_o = common_couch.getAttachment(holly_couch,  attachment_id)
     return dict(attachment=attachment_o)