Пример #1
0
def create_connected_story_template():
    """
    Create the connected stories template

    This is essentially a programatic fixture for creating the 
    connected story template
    """
    story = create_story(title="Connected Story Template",
                         language="en",
                         status="published",
                         is_template=True)
    layout = SectionLayout.objects.get(
        sectionlayouttranslation__name="Side by Side")
    section = create_section(title="Photo and Image",
                             language="en",
                             story=story,
                             layout=layout)
    asset1 = create_external_asset(title="Mock Image Asset",
                                   type='image',
                                   url='http://exampledomain.com/fake.png')
    asset2 = create_html_asset(title="Mock Text Asset", type='text')
    left = Container.objects.get(name='left')
    right = Container.objects.get(name='right')
    SectionAsset.objects.create(section=section, asset=asset1, container=left)
    SectionAsset.objects.create(section=section, asset=asset2, container=right)
    return create_story_template(
        title="Connected Story",
        story=story,
        slug=settings.STORYBASE_CONNECTED_STORY_TEMPLATE)
Пример #2
0
 def test_normalize_for_view(self):
     user = User.objects.create_user('test', '*****@*****.**', 'test')
     user.first_name = "Test"
     user.last_name = "User"
     user.save()
     project = create_project(name="Test Project", description="Test Description")
     featured_asset = create_external_asset(type='image', title='',
             url='http://fakedomain.com/uploads/image.jpg')
     project.featured_assets.add(featured_asset)
     normalized = project.normalize_for_view(img_width=335)
     self.assertEqual(normalized['title'], "Test Project")
     self.assertNotIn('author', normalized)
     self.assertEqual(normalized['date'], project.created)
     self.assertIn('http://fakedomain.com/uploads/image.jpg',
             normalized['image_html'])
     self.assertEqual(normalized['excerpt'], "Test Description")
     self.assertEqual(normalized['url'], project.get_absolute_url())
Пример #3
0
    def save(self, commit=True):
        instance = super(StoryAggregatorModelFormBase, self).save(commit)
        through_field_name = self._meta.model._meta.object_name.lower()
        for user in self.cleaned_data.get('members'):
            through_kwargs = {
                'user': user,
                through_field_name: instance,
                'member_type': 'member',
            }
            self._meta.model.members.through.objects.create(**through_kwargs)
        image_asset = None
        img_val = self.cleaned_data.get('image', None)
        if img_val:
            if is_file(img_val):
                image_asset = create_local_image_asset('image', img_val,
                                                       img_val.name)
            else:
                image_asset = create_external_asset('image', url=img_val)

            instance.featured_assets.add(image_asset)
        return instance
Пример #4
0
    def save(self, commit=True):
        instance = super(StoryAggregatorModelFormBase, self).save(commit)
        through_field_name = self._meta.model._meta.object_name.lower()
        for user in self.cleaned_data.get('members'):
            through_kwargs = {
                'user': user,
                through_field_name: instance,
                'member_type': 'member',
            }
            self._meta.model.members.through.objects.create(
                    **through_kwargs)
        image_asset = None
        img_val = self.cleaned_data.get('image', None)
        if img_val: 
            if is_file(img_val):
                image_asset = create_local_image_asset('image', img_val, img_val.name)
            else:
                image_asset = create_external_asset('image',
                        url=img_val)

            instance.featured_assets.add(image_asset)
        return instance