Пример #1
0
 def test_subdomain_static_route(self):
     return
     # FIXME: static routes are static, generation is flaky
     self.assertEqual(  # static path, different domain
         url('/waffo', sub_domain='m'), "https://m.civicboom.com/waffo")
     self.assertEqual(  # static path, same domain
         url('/waffo', sub_domain='www'), "/waffo")
Пример #2
0
 def test_proto_named_route(self):
     self.assertEqual(
         url('member', id='shish', format='rss', protocol="http"),
         "http://www.civicboom.com/members/shish.rss")
     self.assertEqual(
         url('member', id='shish', format='rss', protocol="https"),
         "https://www.civicboom.com/members/shish.rss")
Пример #3
0
 def test_subdomain_named_route(self):
     self.assertEqual(  # named route, same domain
         url('member', id='shish', format='rss', sub_domain='www'),
         "/members/shish.rss")
     self.assertEqual(  # named route, different domain
         url('member', id='shish', format='rss', sub_domain='m'),
         "https://m.civicboom.com/members/shish.rss")
Пример #4
0
def worker_workout():
    print "worker_workout():"

    print '*** Session ***'
    print '>>> Session.query(Content).first()'
    print Session.query(Content).first()

    print '*** I18n ***'
    print '>>> _("This is a workout of internationalisation in the worker")'
    print _("This is a workout of internationalisation in the worker")

    print '*** Config ***'
    print '>>> cbutils.worker.config["debug"]'
    import cbutils.worker
    print cbutils.worker.config["debug"]

    print '*** Template ***'
    print '>>> ?'

    print '*** URL Generation ***'
    print '>>> url(controller="misc", action="about", id="civicboom")'
    print url(controller="misc", action="about", id="civicboom")
    print url(host='moo', controller="misc", action="about", id="civicboom")
    print url(protocol='test', host='cake', controller="misc", action="about", id="civicboom")
    print url(protocol='test', controller="misc", action="about", id="civicboom")
    print url(sub_domain='subdom', controller="misc", action="about", id="civicboom")

    return True
Пример #5
0
 def test_front_page_synonyms(self):
     self.assertEqual(url('/'), "/")
     self.assertEqual(url('/', qualified=True),
                      "https://www.civicboom.com/")
     self.assertEqual(url(controller='misc', action='titlepage'), "/")
     self.assertEqual(
         url(controller='misc', action='titlepage', qualified=True),
         "https://www.civicboom.com/")
Пример #6
0
def url_pair(*args, **kwargs):
    # Defensive copying
    #args   = copy.copy(args)
    #kwargs = copy.copy(kwargs)
    gen_format = kwargs.pop('gen_format')

    href             = url(*args, **kwargs)
    kwargs['format'] = gen_format
    href_formatted   = url(*args, **kwargs)
    
    return (href, href_formatted)
Пример #7
0
 def test_subdomain_regular_route(self):
     self.assertEqual(  # different subdomain = do have full URL
         url(controller='misc', action='foo', sub_domain="m"),
         "https://m.civicboom.com/misc/foo")
     self.assertEqual(  # same subdomain = don't have full URL
         url(controller='misc', action='foo', sub_domain="www"),
         "/misc/foo")
     self.assertEqual(  # unless qualified=True
         url(controller='misc',
             action='foo',
             sub_domain="www",
             qualified=True), "https://www.civicboom.com/misc/foo")
Пример #8
0
 def test_host(self):
     # setting hosts is broken weirdly
     self.assertEqual(
         url(controller='misc', action='foo', host="pie.civicboom.com"),
         "https://pie.civicboom.com/misc/foo")
     self.assertEqual(
         url(controller='misc', action='foo', host="www.civicboom.com"),
         "https://www.civicboom.com/misc/foo")
     self.assertEqual(
         url(controller='misc',
             action='foo',
             host="www.civicboom.com",
             qualified=True,
             sub_domain="www"), "https://www.civicboom.com/misc/foo")
Пример #9
0
 def test_rest_routes(self):
     self.assertEqual(url('content', id=123), "/contents/123")
     self.assertEqual(url('edit_content', id=123), "/contents/123/edit")
     self.assertEqual(url('edit_content', id=123, format="json"),
                      "/contents/123/edit.json")
     self.assertEqual(url('contents'), "/contents")
     self.assertEqual(url('new_content'), "/contents/new")
     self.assertEqual(url('member', id='shish'), "/members/shish")
     self.assertEqual(url('member_action', id='shish', action='follow'),
                      "/members/shish/follow")
Пример #10
0
def get_janrain(lang='en', theme='', return_url=None, **kargs):
    """
    Generate Janrain IFRAME component
    """
    if not return_url:
        return_url = urllib.quote_plus(url('current', host=c.host, protocol='https')) #controller='account', action='signin',
    query_params = ""
    for karg in kargs:
        query_params += karg+"="+str(kargs[karg])
    if query_params != "":
        query_params = urllib.quote_plus("?"+query_params)
    scheme = current_protocol()
    return literal(
        """<iframe src="%s://civicboom.rpxnow.com/openid/embed?token_url=%s&language_preference=%s"  scrolling="no"  frameBorder="no"  allowtransparency="true"  style="width:400px;height:240px"></iframe>""" % (scheme, return_url+query_params, lang)
    )
Пример #11
0
 def replace_member_link(matchobj):
     return """<a href="%(url)s" data-frag='%(url_frag)s' class="link_new_frag">%(text)s</a>""" % {\
         'url'     : url('member', id=matchobj.group(1)               ) ,
         'url_frag': url('member', id=matchobj.group(1), format='frag') ,
         'text'    : matchobj.group(2) ,
     }
Пример #12
0
def secure_link(href, value='Submit', value_formatted=None, title=None, method='post', form_data=None, link_data=None, link_class='', parent_id=None, force_profile=False):
#def secure_link(href, value='Submit', value_formatted=None, css_class='', title=None, rel=None, confirm_text=None, method='POST', json_form_complete_actions='', modal_params=None, data={}):
    """
    Create two things:
      - A visible HTML form which POSTs some data along with an auth token
      - An invisible pretty-looking plain-text link which calls form.submit()
    Then use javascript to hide the form and show the pretty link
    
    @param href      - can be supplied as a string or a tuple in the format (args, kwargs), this tuple will then be used to automatically create href_json
    @param href_json - an optional JSON url to post to can be provided, this will then activate an AJAX call, this is normally set automatically by providing a tuple for href (see above)
    @param javascript_json_complete_actions - a string of javascript that is activated on a successful AJAX call. Normally used to refresh parts of the page that have been updated from the successful AJAX call.
    """
    if not value_formatted:
        value_formatted = value
    else:
        value_formatted = literal(value_formatted)
    if not form_data:
        form_data = {}
    if not link_data:
        link_data = {}
    
    # Setup Get string href ----
    # the href could be passed a a tuple of (args,kwargs) for form() to create a JSON version to submit to
    # we need a text compatable href reguardless
    href_original = copy.deepcopy(href)
    if isinstance(href, tuple):
        args = href[0]
        kwargs = href[1]
        form_href = url(*args, **kwargs)
        kwargs['format'] = 'json'
        data_json = url(*args, **kwargs)
        #form_data = dict([(key.replace('_', '-' if '_' in key else key, form_data[key])) for key in form_data.keys()])
        
        # GregM: Work out what to do is json_complete has not been defined manually, this could and will fail on odd cercumstances
        if not form_data.get('json_complete'):
            args = list(args)
            args[0] = action_single_map.get(args[0], args[0])
            if kwargs.get('format'):
                del kwargs['format']
            kwargs['action'] = 'show'
            action1 = ['remove'] if method == 'DELETE' or method == 'delete' else ['update']
            action2 = ['update', [url(*args, **kwargs)], None, None]
            if parent_id:
                kwargs['id'] = parent_id
                action2[1].append(url(*args, **kwargs))
            if args[0] == 'member' or force_profile:
                action2[1].append('/profile')
            form_data['json_complete'] = json.dumps([action1, action2]).replace('"',"'")
    # Do magic to convert all form & link _data to kwargs
    form_data = dict([ ('data-%s' % k.replace('_','-'), v if isinstance(v, basestring) else json.dumps(v)) for (k,v) in form_data.items() ])
    link_data = dict([ ('data-%s' % k.replace('_','-'), v if isinstance(v, basestring) else json.dumps(v)) for (k,v) in link_data.items() ])
            
        

    # Keep track of number of secure links created so they can all have unique hash's
    #hhash = hashlib.md5(uniqueish_id(href, value, vals)).hexdigest()[0:6]
    # GregM: Semi-unique ids required for selenium, these will be unique to every action (multiple of same action can exist)
#    hhash = re.sub(funky_chars, '_', re.sub(link_matcher, '', href)) + '_' + method

    # Create Form --------
    #AllanC: without the name attribute here the AJAX/JSON does not function, WTF! took me ages to track down :( NOTE: if the name="submit" jQuery wont submit! a known problem!?
    hf = form(href_original, method=method, class_='hide_if_js', **form_data) + \
            HTML.input(type="submit", value=value, name=value) + \
        end_form() #,

    hl = HTML.a(
        value_formatted ,
        href    = '#',
        class_  = link_class + ' hide_if_nojs link_secure', # GregM: secure_show means js will show element and remove class (to stop dup processing of same element)
        title   = title,
        **link_data
    )
    
    return HTML.span(hf+hl, class_="secure_link") #+json_submit_script
Пример #13
0
 def test_normal_formats(self):
     self.assertEqual(
         url(controller='mobile', action='media_init', format="json"),
         "/mobile/media_init.json")
Пример #14
0
 def url(self):
     from civicboom.lib.web import url
     return url('member', id=self.id, qualified=True)
Пример #15
0
 def url(self):
     from pylons import url, app_globals
     return url('content', id=self.id, qualified=True)
Пример #16
0
def flag(obj,
         raising_member=None,
         type="automated",
         comment=None,
         url_base=None,
         delay_commit=False,
         moderator_address=None):
    """
    if url_base is included an alternate URL generator to avert the use of the pylons one
    """
    flag = FlaggedEntity()
    flag.raising_member = get_member(raising_member)

    if isinstance(obj, Content):
        flag.offending_content = obj
    if isinstance(obj, Member):
        flag.offending_member = obj
    if isinstance(obj, Message):
        flag.offending_message = obj

    flag.comment = strip_html_tags(comment)
    flag.type = type
    Session.add(flag)
    if not delay_commit:
        Session.commit()
    else:
        Session.flush()

    # Send email to alert moderator
    raising_member_username = '******'
    try:
        raising_member_username = flag.raising_member.id
    except:
        pass

    # Base email text
    email_text_dict = {
        "raising_member": raising_member_username,
        "type": type,
        "comment": flag.comment,
        "action_ignore": '',
        "action_delete": '',
    }
    email_text = """
--- Report ---

Reporter: %(raising_member)s
Category: %(type)s

%(comment)s

--- Actions ---

If the content is ok, click here to remove the flag:
  %(action_ignore)s

If the content is not ok, click here to hide it from the site:
  %(action_delete)s

"""

    # Additional Content text
    if flag.offending_content:
        email_text_dict.update({
            "creator_name":
            flag.offending_content.creator.id,
            "creator_url":
            url('member',
                id=flag.offending_content.creator.id,
                qualified=True,
                sub_domain="www"),
            "content_url":
            url('content',
                id=flag.offending_content.id,
                qualified=True,
                sub_domain="www"),
            "content_title":
            flag.offending_content.title,
            "content_body":
            flag.offending_content.content,
            "action_ignore":
            url("admin/moderate?kay=yay&content_id=%s" %
                flag.offending_content.id,
                qualified=True),  #sub_domain="www"),
            "action_delete":
            url("admin/moderate?kay=nay&content_id=%s" %
                flag.offending_content.id,
                qualified=True),  #sub_domain="www"),
        })
        email_text = email_text + """
--- Reported Content ---

Title:  %(content_title)s
        %(content_url)s
Author: %(creator_name)s
        %(creator_url)s

%(content_body)s
"""

    if flag.offending_member:
        log.error('member flaging not implemented yet')

    if flag.offending_message:
        log.error('message flaging not implemented yet')

    email_text = email_text % email_text_dict
    send_email(
        moderator_address,
        subject='flagged content [%s]' % type,
        content_text=email_text,
        content_html="<pre>" + email_text + "</pre>",
    )
Пример #17
0
 def test_proto_static_route(self):
     self.assertEqual(url('/waffo', protocol="http"),
                      "http://www.civicboom.com/waffo")
     self.assertEqual(url('/waffo', protocol="https"),
                      "https://www.civicboom.com/waffo")
Пример #18
0
 def test_custom_routes(self):
     self.assertEqual(  # /about/(.*) = /misc/about?id=$1
         url(controller='misc', action='about', id="civicboom"),
         "/about/civicboom")
     self.assertEqual(url(controller='misc', action='titlepage'), "/")
Пример #19
0
 def test_blank(self):
     self.assertEqual(url(''), "")
     self.assertEqual(url('', qualified=True), "https://www.civicboom.com/")
Пример #20
0
 def test_proto_regular_route(self):
     self.assertEqual(url(controller='misc', action='foo', protocol="http"),
                      "http://www.civicboom.com/misc/foo")
     self.assertEqual(
         url(controller='misc', action='foo', protocol="https"),
         "https://www.civicboom.com/misc/foo")
Пример #21
0
 def __link__(self):
     from civicboom.lib.web import url
     return url('message', id=self.id, sub_domain='www', qualified=True)
Пример #22
0
 def test_current(self):
     self.assertEqual(url('current'), "/")
     self.assertEqual(url('current', qualified=True),
                      "https://www.civicboom.com/")
     self.assertEqual(  # changing the subdomain should imply qualified
         url('current', sub_domain="m"), "https://m.civicboom.com/")