add_submit.py :  » Content-Management-Systems » Silva » trunk » views » add » CSVSource » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Content Management Systems » Silva 
Silva » trunk » views » add » CSVSource » add_submit.py
from Products.Silva import mangle

# I18N stuff
from Products.Silva.i18n import translate


model = context.REQUEST.model
REQUEST = context.REQUEST

# if we cancelled, then go back to edit tab
if REQUEST.has_key('add_cancel'):
    return model.edit['tab_edit']()

# validate form
from Products.Formulator.Errors import ValidationError,FormValidationError
try:
    result = context.form.validate_all(REQUEST)
except FormValidationError, e:
    # in case of errors go back to add page and re-render form
    return context.add_form(message_type="error",
        message=context.render_form_errors(e))

# get id and set up the mangler
id = mangle.Id(model, result['object_id'])

# try to cope with absence of title in form (happens for ghost)
if result.has_key('object_title'):
    title = result['object_title']
else:
    title = ""

# if we don't have the right id, reject adding
id_check = id.validate()
if id_check == id.OK:
    id = str(id)
else:
    return context.add_form(message_type="error",
        message=context.get_id_status_text(id))

# get file, character encoding from the form
file = result.get('object_file')
character_set = result['object_character_set']
de = character_set.strip()

try:
    unicode('abcd', de, 'replace')
except LookupError:
    # unknown encoding, return error message
    m = _(
        'Unknown encoding ${enc}. CSVSource not added! ',
        mapping={'enc':de})
    return context.add_form(message_type="error", message=m)

try:
    model.manage_addProduct['SilvaExternalSources'].manage_addCSVSource(id, title, file)
except IOError, e:
    m = _(
        'Problem ${exception}',
        mapping={'exception':e})
    msg = unicode(m)
    return context.add_form(message_type="error", message=msg)
object = getattr(model, id)

# update last author info in new object
object.sec_update_last_author_info()

object.set_data_encoding(de)
# now go to tab_edit in case of add and edit, back to container if not.
if REQUEST.has_key('add_edit_submit'):
    REQUEST.RESPONSE.redirect(object.absolute_url() + '/edit/tab_edit')
else:
    m = _(
        'Added ${metatype} ${id}.',
        mapping={'metatype':object.meta_type, 'id':context.quotify(id)})
    return model.edit['tab_edit'](message_type="feedback", message=m)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.