get http username/password from settings
This commit is contained in:
parent
76b3dbcfc7
commit
6009a1029e
|
@ -2,16 +2,32 @@ import datetime
|
|||
import urllib2
|
||||
import vobject
|
||||
|
||||
from zope import component
|
||||
|
||||
from Products.CMFCore.WorkflowCore import WorkflowException
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from Products.Five.browser import BrowserView
|
||||
from plone.registry.interfaces import IRegistry
|
||||
|
||||
from tabellio.config.interfaces import ITabellioSettings
|
||||
|
||||
class IcalImport(BrowserView):
|
||||
def __call__(self):
|
||||
self.settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
||||
self.plone_utils = getToolByName(self.context, 'plone_utils')
|
||||
self.portal_workflow = getToolByName(self.context, 'portal_workflow')
|
||||
url = self.request.form.get('url')
|
||||
content = urllib2.urlopen(url).read()
|
||||
|
||||
if self.settings.ical_username:
|
||||
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
||||
password_mgr.add_password(None, url,
|
||||
self.settings.ical_username, self.settings.ical_password)
|
||||
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
|
||||
opener = urllib2.build_opener(handler)
|
||||
urlopen = opener.open
|
||||
else:
|
||||
urlopen = urllib2.urlopen
|
||||
content = urlopen(url).read()
|
||||
parsed_cal = vobject.readOne(content)
|
||||
for vevent in parsed_cal.vevent_list:
|
||||
title = vevent.summary.value
|
||||
|
|
Reference in New Issue