Пример #1
0
def get_embedly_code(args):
    id = args["id"]
    url = args["url"]
    type = args["type"]
    try:
        if url:
            response = oembed_replace(url)
            if response:  
                widget = Widget.get_by_key_name(id)
                if type == "embedly":
                    widget.embedly_code = db.Text(response)
                if type == "googlemaps":
                    widget.googlemaps_code = db.Text(response)
                widget.put()
    except:
        logging.info("Embedly Error")
        logging.info(args)
Пример #2
0
 def get(self, **kwargs):
     user =  self.current_user
     admin = False
     method = kwargs.get('method')
     if method == 'scripturl':
         upload_url = blobstore.create_upload_url('/upload')
         
         self.response.out.write(upload_url)
     if method == 'headerimageurl':
         #pages = Page.get(user.pages)
         key_name = self.request.get("p")
         #for p in pages:
         #    if p.id == page_id:
         #        page = p
         #        admin = True
         #if admin:
         page = Page.get_by_key_name(key_name)
         if page:
             header_image_url = page.header_image_url
             
             self.response.out.write(header_image_url)
         else:
             
             self.response.out.write('')
     if method == 'getwidget':
         widget_id = self.request.get("wid")
         widget = Widget.get_by_key_name(widget_id)
         tenr = range(1,11)
         if widget:
             widget_type = widget.type
         if not widget:
             widget_type = self.request.get("wtype").lstrip('wi-')
             widget = dict(type=widget_type,
                         id=widget_id
                         )
         if widget_type:
             self.render('app/widgets/'+widget_type+".html", widget=widget,tenr=tenr)
         else:
             
             self.response.out.write("This widget cannot be found.")
Пример #3
0
 def post(self, **kwargs):
     user =  self.current_user
     admin = False
     method = kwargs.get('method')
     if method == 'deletewidget':
         key_name = self.request.get("wid")
         widget = Widget.get_by_key_name(key_name)
         if widget:
             widget.deleted = True
             widget.last_modified_by = user
         try:
             db.put(widget)
             self.response.out.write('True')
         except:
             self.response.out.write('False')
             
     if method == 'savepageorder':
         page_order = self.request.get('pageorder')
         page_order = page_order.split(',')
         batch = []
         for k,v in enumerate(page_order):
             widget = Widget.get_by_key_name(v)
             if widget:
                 widget.order = k
                 widget.last_modified_by = user
                 batch.append(widget)
         try:
             db.put(batch)
             self.response.out.write('True')
         except:
             self.response.out.write('False')
             
     if method == 'savewidget':
         page = Page.get_by_key_name(self.request.get('pageid'))
         key_name = self.request.get('wid')
         widget = Widget.get_by_key_name(key_name)
         if self.request.get('wtype') == 'embedly':
            fields = simplejson.loads(self.request.get('wcontents'))
            #get_embedly_code({'id':self.request.get('wid'),"url":fields['embedly_url'],"type":"embedly"})
            deferred.defer(get_embedly_code,{'id':self.request.get('wid'),"url":fields['embedly_url'],"type":"embedly"})
         if self.request.get('wtype') == 'googlemaps':
            fields = simplejson.loads(self.request.get('wcontents'))
            deferred.defer(get_embedly_code,{'id':self.request.get('wid'),"url":fields['googlemaps_link'],"type":"googlemaps"})
         if not widget:
             widget = Widget(key_name=key_name,
                             id = key_name,
                             type = self.request.get('wtype'),
                             name = self.request.get('wname'),
                             page = page,
                             contents = self.request.get('wcontents'),
                             last_modified_by = user
                            )
             fields = simplejson.loads(self.request.get('wcontents'))
             for k,v in fields.iteritems():
                 db_type = k.split('__')
                 try:
                     db_type = db_type[1]
                 except IndexError:
                     db_type = None
                 logging.info(db_type)
                 if db_type == 'text':
                     setattr(widget, k, db.Text(v))
                 else:
                     setattr(widget, k, v)
         else:
             widget.name = self.request.get('wname')
             widget.contents = self.request.get('wcontents')
             widget.last_modified_by = user
             fields = simplejson.loads(self.request.get('wcontents'))
             for k,v in fields.iteritems():
                 db_type = k.split('__')
                 try:
                     db_type = db_type[1]
                 except IndexError:
                     db_type = None
                 logging.info(db_type)
                 if db_type == 'text':
                     setattr(widget, k, db.Text(v))
                 else:
                     setattr(widget, k, v)
         
         try:
             db.put(widget)
             self.response.out.write('True')
         except:
             self.response.out.write('False')
     if method == 'saveoption':
         try:
             option = Option.get_by_id(int(self.request.get('id')))
         except:
             option = None
         if self.request.get('otype') == 'page':
             link = Page.get_by_key_name(self.request.get('opageid'))
         if not option:
             option = Option(
                             name = self.request.get('oname'),
                             value = self.request.get('ovalue'),
                             type = self.request.get('otype'),
                             type_reference = link
                            )
         else:
             option.value = self.request.get('ovalue')
             
         try:
             db.put(option)
             self.response.out.write('True')
         except:
             self.response.out.write('False')
     if method == 'upgradedowngrade':
       try:
         username = self.get_config('saasy','username')
         password = self.get_config('saasy','password')
         product = self.get_config('saasy','product')
         qty = str(self.request.get('qty'))
         basic_auth = base64.b64encode('%s:%s' % (username, password)) 
         xml_data = "<subscription><productPath>/%s</productPath><quantity>%s</quantity><no-end-date/></subscription>" % (product,qty)
         subscriber_info=simplejson.loads(self.current_user.subscriber_info)
         url = "https://api.fastspring.com/company/seedprod/subscription/%s" % subscriber_info['reference']
         response = urlfetch.fetch(url=url,payload=xml_data,headers={'Authorization': 'Basic %s' % basic_auth ,'Content-Type': 'application/xml' },method=urlfetch.PUT)
         if response.status_code == 200:
           # Update Pages
           upgraded_pages = self.request.get('pages').split(',')
           pages = Page.get(user.pages)
           batch = []
           for p in pages:
             if p.id in upgraded_pages:
               p.upgraded = '1'
               p.upgraded_by = user
             else:
               if p.upgraded_by:
                 if p.upgraded_by.id == user.id:
                   p.upgraded = '0'
                   p.upgraded_by = None
             batch.append(p)
           db.put(batch)
                        
           self.response.out.write('True')
         else:
           self.response.out.write('False')
       except:
         self.response.out.write('False')