Exemple #1
0
def cred_icon(iconname, txtfield=None, imgfield=None, tagid=None):
    try:
        data = get_icon_data()[iconname]
    except KeyError:
        data = get_icon_data()[settings.CRED_ICON_DEFAULT]

    blankimg = settings.STATIC_URL + settings.CRED_ICON_CLEAR
    classes = ['rattic-icon', data['css-class']]

    if txtfield is not None or imgfield is not None:
        classes.append('rattic-icon-clickable')

    tag = '<img '
    tag += 'src="%s" ' % blankimg
    tag += 'data-icon-name="%s" ' % data['filename']
    if tagid is not None:
        tag += 'id="%s" ' % tagid
    if txtfield is not None:
        tag += 'data-txt-field="%s" ' % txtfield
    if imgfield is not None:
        tag += 'data-img-field="%s" ' % imgfield
    if 'rattic-icon-clickable' in classes:
        tag += 'data-dismiss="modal" '
    tag += 'class="%s" ' % ' '.join(classes)
    tag += '>'

    return tag
Exemple #2
0
 def test_password_edit_logo(self):
     timeout = 4
     self.login_as(self.data.unorm.username, self.data.normpass)
     self.selenium.get('%s%s' % (self.live_server_url,
         reverse('cred.views.edit', args=(self.data.cred.id,))))
     self.waitforload()
     elemlogo = self.selenium.find_element_by_id('id_iconname')
     currlogo = elemlogo.get_attribute('value')
     otherimg = self.selenium.find_element_by_xpath('.//*[@id=\'logoModal\']/div[2]/div/img[8]')
     # Check Logo
     self.assertEqual(currlogo, self.data.cred.iconname)
     # Click change logo button
     self.selenium.find_element_by_id('choosebutton').click()
     # Wait for dialog
     WebDriverWait(self.selenium, timeout).until(
         lambda driver: otherimg.is_displayed())
     # Pick the third logo
     otherimg.click()
     # Wait for dialog to go
     WebDriverWait(self.selenium, timeout).until(
         lambda driver: not otherimg.is_displayed())
     # Check the new iconname is in the list
     iconname = self.selenium.find_element_by_id('id_iconname').get_attribute('value')
     icondata = get_icon_data()[iconname]
     # Validate the logo is shown correctly
     logodisplay = self.selenium.find_element_by_id('logodisplay')
     logoclasses = logodisplay.get_attribute('class')
     self.assertIn(icondata['css-class'], logoclasses)
     self.assertNotIn('rattic-icon-clickable', logoclasses)
     # Save the credential
     logodisplay.submit()
     self.waitforload()
     # Check it has the right data now
     chgcred = Cred.objects.get(id=self.data.cred.id)
     self.assertEqual(chgcred.iconname, iconname)
Exemple #3
0
def cred_icon(iconname, txtfield=None, imgfield=None, tagid=None):
    """
    Generates the HTML used to display an icon. If the icon cannot be found
    it reverts to the default icon mentioned in settings CRED_ICON_DEFAULT.
    It is used on the details pages and as part of the CredIconChooser widget.
    """

    # Get info for the icon, if that wont work, get info for the default icon
    try:
        data = get_icon_data()[iconname]
    except KeyError:
        data = get_icon_data()[settings.CRED_ICON_DEFAULT]

    # Get the URL for the blank image (goes in the href)
    blankimg = settings.STATIC_URL + settings.CRED_ICON_CLEAR
    #blankimg = "{% static 'rattic/img/rattic/img/clear.gif' %}"

    # What CSS classes does our icon need
    classes = ['rattic-icon', data['css-class']]

    # If the icon is clickable append the clickable class
    if txtfield is not None or imgfield is not None:
        classes.append('rattic-icon-clickable')

    # Build the HTML
    tag = '<img '
    tag += 'src="%s" ' % blankimg
    tag += 'data-icon-name="%s" ' % data['filename']
    if tagid is not None:
        tag += 'id="%s" ' % tagid
    if txtfield is not None:
        tag += 'data-txt-field="%s" ' % txtfield
    if imgfield is not None:
        tag += 'data-img-field="%s" ' % imgfield
    if 'rattic-icon-clickable' in classes:
        tag += 'data-dismiss="modal" '
    tag += 'class="%s" ' % ' '.join(classes)
    tag += '>'

    return tag
Exemple #4
0
def cred_icon(iconname, txtfield=None, imgfield=None, tagid=None):
    """
    Generates the HTML used to display an icon. If the icon cannot be found
    it reverts to the default icon mentioned in settings CRED_ICON_DEFAULT.
    It is used on the details pages and as part of the CredIconChooser widget.
    """

    # Get info for the icon, if that wont work, get info for the default icon
    try:
        data = get_icon_data()[iconname]
    except KeyError:
        data = get_icon_data()[settings.CRED_ICON_DEFAULT]

    # Get the URL for the blank image (goes in the href)
    blankimg = settings.STATIC_URL + settings.CRED_ICON_CLEAR

    # What CSS classes does our icon need
    classes = ['rattic-icon', data['css-class']]

    # If the icon is clickable append the clickable class
    if txtfield is not None or imgfield is not None:
        classes.append('rattic-icon-clickable')

    # Build the HTML
    tag = '<img '
    tag += 'src="%s" ' % blankimg
    tag += 'data-icon-name="%s" ' % data['filename']
    if tagid is not None:
        tag += 'id="%s" ' % tagid
    if txtfield is not None:
        tag += 'data-txt-field="%s" ' % txtfield
    if imgfield is not None:
        tag += 'data-img-field="%s" ' % imgfield
    if 'rattic-icon-clickable' in classes:
        tag += 'data-dismiss="modal" '
    tag += 'class="%s" ' % ' '.join(classes)
    tag += '>'

    return tag
Exemple #5
0
def cred_icon(iconname, field=None):
    try:
        data = get_icon_data()[iconname]
    except KeyError:
        return ''

    alt = 'alt="%s"' % iconname
    stylesize = 'height: %spx; width: %spx; ' % (data['height'], data['width'])
    bgurl = settings.STATIC_URL + settings.CRED_ICON_SPRITE
    stylebg = 'background: url(%s) -%spx -%spx; ' % (bgurl, data['xoffset'], data['yoffset'])
    style = 'style="' + stylesize + stylebg + '"'
    src = 'src="' + settings.STATIC_URL + settings.CRED_ICON_CLEAR + '"'

    onclick = ''

    if field is not None:
        onclick = 'onclick="$(\'input#id_%s\').val(\'%s\');$(\'#logoModal\').modal(\'hide\')"' % (field, iconname)

    return '<img %s %s %s %s>' % (alt, style, src, onclick)
Exemple #6
0
 def test_password_edit_logo(self):
     timeout = 4
     self.login_as(self.data.unorm.username, self.data.normpass)
     self.selenium.get('%s%s' %
                       (self.live_server_url,
                        reverse('cred:edit', args=(self.data.cred.id, ))))
     self.waitforload()
     elemlogo = self.selenium.find_element_by_id('id_iconname')
     currlogo = elemlogo.get_attribute('value')
     otherimg = self.selenium.find_element_by_xpath(
         './/*[@id=\'logoModal\']/div[2]/div/img[8]')
     # Check Logo
     self.assertEqual(currlogo, self.data.cred.iconname)
     # Click change logo button
     self.selenium.find_element_by_id('choosebutton').click()
     # Wait for dialog
     WebDriverWait(self.selenium,
                   timeout).until(lambda driver: otherimg.is_displayed())
     # Pick the third logo
     otherimg.click()
     # Wait for dialog to go
     WebDriverWait(
         self.selenium,
         timeout).until(lambda driver: not otherimg.is_displayed())
     # Check the new iconname is in the list
     iconname = self.selenium.find_element_by_id(
         'id_iconname').get_attribute('value')
     icondata = get_icon_data()[iconname]
     # Validate the logo is shown correctly
     logodisplay = self.selenium.find_element_by_id('logodisplay')
     logoclasses = logodisplay.get_attribute('class')
     self.assertIn(icondata['css-class'], logoclasses)
     self.assertNotIn('rattic-icon-clickable', logoclasses)
     # Save the credential
     logodisplay.submit()
     self.waitforload()
     # Check it has the right data now
     chgcred = Cred.objects.get(id=self.data.cred.id)
     self.assertEqual(chgcred.iconname, iconname)