Beispiel #1
0
def document(request, app, doc_type, doc_id = None):
    app_item = _find_app(app)
    doc_item = _find_doc_type(app_item, doc_type)
    if doc_id:
        document = request._db(app_item.get('db'))[doc_id]
    else:
        document = Document(_db = request._db(app_item.get('db')))
    
    
    form_class = doc_item.get('form')
    form = None
    
    if form_class:
        form = form_class(initial = document)
        
        if request.method == 'POST':
            form = form_class(request.POST, request.FILES, initial = document)
            if form.is_valid():
                form.save(files = request.FILES)
                return redirect('couchdb:documents', app, doc_type)

    
    document.attachments = document.get('_attachments', {})
    
    return {
        'app': app_item,
        'doc_item': doc_item,
        'doc_type': doc_type,
        'doc_id': doc_id,
        'document': document,
        'form': form,
    }
Beispiel #2
0
    def save(self, *args, **kwargs):
        """Save user object and update ``last_login`` field"""
        
        if hasattr(self, 'backend'):
            backend = self.backend
            del(self.backend)
        else:
            backend = None
            
        if hasattr(self, 'last_login') and type(self.last_login) == datetime:
            from django.conf import settings
            self.last_login = self.last_login.strftime(settings.DATETIME_FMT)

        Document.save(self, *args, **kwargs)

        if backend:
            self.backend = backend