def upload_icon_font(self):
        UserModel = get_user_model()
        admin_user = UserModel.objects.get(username='******')
        with self.login_user_context(admin_user):
            filename = os.path.join(os.path.dirname(__file__),
                                    'assets/fontello-b504201f.zip')
            with open(filename, 'rb') as zipfile:
                uploaded_file = SimpleUploadedFile(
                    'fontello-b504201f.zip',
                    zipfile.read(),
                    content_type='application/zip')
            request = self.get_request(reverse('admin:filer-ajax_upload'))
            request.FILES.update(file=uploaded_file)
            response = ajax_upload(request)
            self.assertEqual(response.status_code, 200)
            content = json.loads(response.content.decode('utf-8'))

            # save the form and submit the remaining fields
            add_iconfont_url = reverse('admin:cmsplugin_cascade_iconfont_add')
            data = {
                'identifier': "Fontellico",
                'zip_file': content['file_id'],
                '_continue': "Save and continue editing",
            }
            response = self.client.post(add_iconfont_url, data)
            self.assertEqual(response.status_code, 302)
        self.assertEqual(IconFont.objects.count(), 1)
Beispiel #2
0
def builder_media_upload(request):
    if request.method == 'POST':
        response = ajax_upload(request)
        res = json.loads(response.content)
        if 'error' in res:
            return redirect(defaults.HttpResponseServerError)
        description = request.POST.get("description")
        if description:
            filer_file = filemodels.File.objects.filter(
                id=res["file_id"]).first()
            filer_file.description = description
            filer_file.save()
    return redirect('builder_media')
Beispiel #3
0
    def test_add_font(self):
        with self.login_user_context(self.admin_user):
            # upload the zipfile into the filer's clipboard
            filename = os.path.join(os.path.dirname(__file__),
                                    'assets/fontello-b504201f.zip')
            with open(filename, 'rb') as zipfile:
                uploaded_file = SimpleUploadedFile(
                    'fontello-b504201f.zip',
                    zipfile.read(),
                    content_type='application/zip')
            request = self.get_request(reverse('admin:filer-ajax_upload'))
            self.assertTrue(request.user.is_staff, "User is not a staff user")
            request.FILES.update(file=uploaded_file)
            response = ajax_upload(request)
            self.assertEqual(response.status_code, 200)
            content = json.loads(response.content.decode('utf-8'))
            self.assertDictContainsSubset({'label': 'fontello-b504201f.zip'},
                                          content)

            # save the form and submit the remaining fields
            add_iconfont_url = reverse('admin:cmsplugin_cascade_iconfont_add')
            data = {
                'identifier': "Fontellico",
                'zip_file': content['file_id'],
                '_continue': "Save and continue editing",
            }
            response = self.client.post(add_iconfont_url, data)
            self.assertEqual(response.status_code, 302)
            resolver_match = resolve(response.url)
            self.assertEqual(resolver_match.url_name,
                             'cmsplugin_cascade_iconfont_change')

            # check the content of the uploaded file
            icon_font = IconFont.objects.get(pk=resolver_match.args[0])
            self.assertEqual(icon_font.identifier, "Fontellico")
            self.assertEqual(icon_font.config_data['name'], 'fontelico')
            self.assertEqual(len(icon_font.config_data['glyphs']), 34)

            # check if the uploaded fonts are rendered inside Preview Icons
            response = self.client.get(response.url)
            self.assertEqual(response.status_code, 200)
            soup = BeautifulSoup(response.content, 'lxml')
            preview_iconfont = soup.find('div', class_="preview-iconfont")
            icon_items = preview_iconfont.ul.find_all('li')
            self.assertEqual(len(icon_items), 34)
            self.assertListEqual(icon_items[0].i.attrs['class'],
                                 ['icon-emo-happy'])
            self.assertListEqual(icon_items[33].i.attrs['class'],
                                 ['icon-marquee'])

            # create container
            container_model = add_plugin(
                self.placeholder,
                BootstrapContainerPlugin,
                'en',
                glossary={'breakpoints': BS3_BREAKPOINT_KEYS})
            container_plugin = container_model.get_plugin_class_instance()
            self.assertIsInstance(container_plugin, BootstrapContainerPlugin)

            # add icon as child to this container
            glossary = {
                "font_size": "10em",
                "color": ["", "#88258e"],
                "background_color": ["on", "#c8ffcd"],
                "symbol": "emo-wink",
                "icon_font": icon_font.pk,
                "border_radius": "50%",
                "border": ["", "solid", "#000000"]
            }
            icon_model = add_plugin(self.placeholder,
                                    FramedIconPlugin,
                                    'en',
                                    target=container_model,
                                    glossary=glossary)
            icon_plugin = icon_model.get_plugin_class_instance()
            self.assertIsInstance(icon_plugin, FramedIconPlugin)

            # render the plugins
            plugin_list = [container_model, icon_model]
            build_plugin_tree(plugin_list)
            html = self.get_html(container_model, self.get_request_context())
            soup = BeautifulSoup(html, 'lxml')

            # look for the icon symbol
            style = soup.find('span',
                              class_='icon-emo-wink').attrs['style'].split(';')
            self.assertIn('color:#88258e', style)
            self.assertIn('display:inline-block', style)

            # look for the CSS file
            response = self.client.get(
                container_model.placeholder.page.get_absolute_url() + '?edit')
            self.assertEqual(response.status_code, 200)
            soup = BeautifulSoup(response.content, 'lxml')
            links = soup.head.find_all('link')
            for link in links:
                if link.attrs['href'].endswith('fontelico.css'):
                    break
            else:
                self.fail("No CSS file with font definition found")
    def test_add_font(self):
        with self.login_user_context(self.admin_user):
            # upload the zipfile into the filer's clipboard
            filename = os.path.join(os.path.dirname(__file__), 'assets/fontello-b504201f.zip')
            with open(filename, 'rb') as zipfile:
                uploaded_file = SimpleUploadedFile('fontello-b504201f.zip', zipfile.read(), content_type='application/zip')
            request = self.get_request(reverse('admin:filer-ajax_upload'))
            self.assertTrue(request.user.is_staff, "User is not a staff user")
            request.FILES.update(file=uploaded_file)
            response = ajax_upload(request)
            self.assertEqual(response.status_code, 200)
            content = json.loads(response.content.decode('utf-8'))
            self.assertDictContainsSubset({'label': 'fontello-b504201f.zip'}, content)

            # save the form and submit the remaining fields
            add_iconfont_url = reverse('admin:cmsplugin_cascade_iconfont_add')
            data = {
                'identifier': "Fontellico",
                'zip_file': content['file_id'],
                '_continue': "Save and continue editing",
            }
            response = self.client.post(add_iconfont_url, data)
            self.assertEqual(response.status_code, 302)
            resolver_match = resolve(response.url)
            self.assertEqual(resolver_match.url_name, 'cmsplugin_cascade_iconfont_change')

            # check the content of the uploaded file
            icon_font = IconFont.objects.get(pk=resolver_match.args[0])
            self.assertEqual(icon_font.identifier, "Fontellico")
            self.assertEqual(icon_font.config_data['name'], 'fontelico')
            self.assertEqual(len(icon_font.config_data['glyphs']), 34)

            # check if the uploaded fonts are rendered inside Preview Icons
            response = self.client.get(response.url)
            self.assertEqual(response.status_code, 200)
            soup = BeautifulSoup(response.content, 'lxml')
            preview_iconfont = soup.find('div', class_="preview-iconfont")
            icon_items = preview_iconfont.ul.find_all('li')
            self.assertEqual(len(icon_items), 34)
            self.assertListEqual(icon_items[0].i.attrs['class'], ['icon-emo-happy'])
            self.assertListEqual(icon_items[33].i.attrs['class'], ['icon-marquee'])

            # select icon font from toolbar
            self.placeholder.page.cascadepage.icon_font = icon_font
            self.placeholder.page.cascadepage.save()

            # create container
            container_model = add_plugin(self.placeholder, BootstrapContainerPlugin, 'en',
                                         glossary={'breakpoints': BS3_BREAKPOINT_KEYS})
            container_plugin = container_model.get_plugin_class_instance()
            self.assertIsInstance(container_plugin, BootstrapContainerPlugin)

            # add icon as child to this container
            glossary = {"font_size": "10em", "color": ["","#88258e"], "background_color": ["on","#c8ffcd"],
                        "symbol": "emo-wink", "icon_font": icon_font.pk,
                        "border_radius":"50%","border":["","solid","#000000"]}
            icon_model = add_plugin(self.placeholder, FramedIconPlugin, 'en', target=container_model,
                                    glossary=glossary)
            icon_plugin = icon_model.get_plugin_class_instance()
            self.assertIsInstance(icon_plugin, FramedIconPlugin)

            # render the plugins
            plugin_list = [container_model, icon_model]
            build_plugin_tree(plugin_list)
            html = self.get_html(container_model, self.get_request_context())
            soup = BeautifulSoup(html, 'lxml')

            # look for the icon symbol
            style = soup.find('span', class_='icon-emo-wink').attrs['style'].split(';')
            self.assertIn('color:#88258e', style)
            self.assertIn('display:inline-block', style)

            # look for the CSS file
            response = self.client.get(container_model.placeholder.page.get_absolute_url() + '?edit')
            self.assertEqual(response.status_code, 200)
            soup = BeautifulSoup(response.content, 'lxml')
            links = soup.head.find_all('link')
            for link in links:
                if link.attrs['href'].endswith('fontelico.css'):
                    break
            else:
                self.fail("No CSS file with font definition found")