Giter Site home page Giter Site logo

raagin / django-streamfield Goto Github PK

View Code? Open in Web Editor NEW
119.0 119.0 11.0 1.23 MB

This is a simple realisation of StreamField's idea from Wagtail CMS for plain Django admin or with Grappelli skin.

License: Other

Python 42.57% JavaScript 5.27% HTML 9.92% Vue 28.90% Sass 13.33%
django-admin django-streamfield

django-streamfield's People

Contributors

andywar65 avatar dependabot[bot] avatar htmlmak avatar igor-zmitrovich avatar raagin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-streamfield's Issues

How to create formatting panel for Streamfield?

Hello! Do you know how to create formatting panel for Streamfield or enable ckeditor for text formatting? I need it for RichText. Here is my code:

class About(models.Model):
stream = StreamField(
model_list=[
RichText,
ImageWithText
],
popup_size=(1000, 500),
verbose_name="Блок обо мне",
)

Feature Request: Moving multiple blocks at once

Hello! We love the StreamField in Django but we often find ourselves having to reorder sections in a blog article. Each section usually contains 8-10 different blocks and is extremely time-consuming having to move one by one.

Would it be possible to add the functionality to select and move multiple blocks at once?

Not working with CSRF_USE_SESSIONS=True

django-streamfield seems not to work with the global setting CSRF_USE_SESSIONS=True (see https://docs.djangoproject.com/en/5.0/ref/settings/#std-setting-CSRF_USE_SESSIONS) due to

headers: {"X-CSRFToken": Cookies.get('csrftoken')}

Adding new blocks or saving changes in blocks in the admin UI works - but saving a model instance after deleting blocks fails with:

Forbidden (403)
CSRF verification failed. Request aborted.

Browser debug console shows:

Uncaught (in promise) 
Object { stack: "I@https://www.xxx.xx/static/dde6e8f9/streamfield/streamfield_widget.js:1:261104\n
...
message: "Request failed with status code 403", name: "AxiosError", code: "ERR_BAD_REQUEST", config: {…}, request: XMLHttpRequest, response: {…} }
​code: "ERR_BAD_REQUEST"
​config: Object { timeout: 0, xsrfCookieName: "XSRF-TOKEN", xsrfHeaderName: "X-XSRF-TOKEN", … }
​message: "Request failed with status code 403"
​name: "AxiosError"

It would be probably smart if the app can automatically use the cookie name from the settings if possible. Bear in mind that the name of both the CSRF and the Session cookie can be freely configured via Django settings (see https://docs.djangoproject.com/en/5.0/ref/settings/#session-cookie-name and https://docs.djangoproject.com/en/5.0/ref/settings/#csrf-cookie-name)

Can't delete/reorder blocks in admin

Hello!

For some reason my blocks in Django Admin look different then ones in the README.md screenshot.

There is no blocks' names and it is not possible to change order via drag-and-drop or delete them.

Change-content

The project runs Django 2.2.

Ajax issue

I got this while I open page of layout page. Seems like ajax issue while getting static js
screenshot

404 After deleting Stream Block inline

I'd like to report a bug:

If you created a streamblock without adding content, then deleting it again, trying to save the entity containing the streamfield, it'll still try to delete the not yet created streamblock resulting in a query like this: http://localhost:8000/streamfield/admin-instance/absolutemodifier/-1/delete/

That obiously results in a 404 failing the attempt to save the entity

[Question] Compatibility

Can I use this app together with django-polymorphic app, is it compatible?
Docs: https://django-polymorphic.readthedocs.io/en/stable/index.html
Code: https://github.com/django-polymorphic/django-polymorphic

I have polymorphic-based section models. I would like to attach streamfield to all of them (with different set of available blocks per section type). So user may create section and add some blocks there.

Suggestion also: move all code inside of StreamBlocksAdmin(admin.ModelAdmin) to StreamBlocksAdminMixin(object) and add StreamBlocksAdmin(StreamBlocksAdminMixin, admin.ModelAdmin).

Error 404 inside the popup when clicking "+ Add content" button if the streamblocks model has not fields.

Hello @raagin,
thank you for this great application.

I have some streamblocks models that have not fields (because their template includes another existing template which uses some templatetags), in this case when clicking the "+ Add content" in the backend it results in a 404 error inside the popup.

I think that the right solution is to hide "+ Add content" button if the streamblocks model has not fields.

Deleting object from stream causes error when contenttypes and streamblocks use different databases

Deleting object from streamfield cause ProgrammingError.

Example traceback:

Traceback (most recent call last):
  File ".../site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File ".../site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File ".../site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File ".../site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File ".../site-packages/streamfield/views.py", line 58, in delete_instance
    obj = t.get_object_for_this_type(pk=pk)
  File ".../site-packages/django/contrib/contenttypes/models.py", line 168, in get_object_for_this_type
    return self.model_class()._base_manager.using(self._state.db).get(**kwargs)
    ...
    ...
  File ".../site-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'accounts.streamblocks_imagewithtext' doesn't exist")

The problem appears, because for my project contenttypes are in the accounts database, however streamblocks models are stored in the default. The t.get_object_for_this_type function runs queryset with .using(self._state.db), where self._state.db=="accounts".

Orphaned/existing blocks

This is really great!

I wonder if there is anyway to cleanup orphaned blocks, though. Deleting blocks, or the page, don't delete underlying column or text objects.

I know it's a limitation of streamfield and nosql. However, my users are going to create hundreds/thousands of orphaned blocks, if they have the chance.

It'd also be nice to link to existing blocks.

Can be used in a dango view

It is just what I was looking for, but I see that it is only for the django manager, I would like to use it in a django view, or be able to add elements without the manager, I have not seen documentation on this. thank you so much.

Not Found: /folder/7909375238_n.jpg

Hello! Thanks for this amazing package. I would like to use it for my existing app but this message appears
when I click on post detail page after successfully saving post in admin:
Not Found: /folder/7909375238_n.jpg

I can see my file is saved well in project root's "folder" directory but I don't know why it can't load the image.

Thanks for your help in advance.

`ValueError`: The file 'streamfield/vendor/vuedraggable.umd.min.js.map' could not be found with `ManifestStaticFilesStorage` object.

Hi,
thank you for this great package.

The following error is raised when using ManifestStaticFilesStorage and running python manage.py collectstatic:

ValueError: The file 'streamfield/vendor/vuedraggable.umd.min.js.map' could not be found with <django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at 0x7f3137437d00>.

The cause is that vuedraggable.umd.min.js contains a reference to vuedraggable.umd.min.js.map and django tries to solve but it doesn't find the file:
https://github.com/raagin/django-streamfield/blob/master/streamfield/static/streamfield/vendor/vuedraggable.umd.min.js

Python version: 3.8
Django version: 4.1

How to create streamblocks and add them to stream field programatically?

I have an Article model looking something like this:

class Article(Model):
    title = models.CharField(max_length=255)
    content = StreamField(
        verbose_name='Blocks',
        model_list=[Text, Header, SubHeader, ImageSingle, ImageDouble, Video, InfoBox, MultiUse],
    )

Now I want to programmatically create the streamfields and add them to the article

# Create article
article = Article()
article.title = 'This is my title'

#Create text blocks
text1 = RichText(text='<p>This is the first block of text<p>')
text2 = RichText(text='<p>This is the second block of text<p>')
text1.save()
text2.save()

# Add text to article
article.content = [text1, text2]     #This doesn't work

article.content.add(text1)   # This doesn't work either
article.content.add(text2)   # This doesn't work either

# Save article to database
article.save()

How can I programmatically add the streamblocks to the article?

Add API integration section to the docs.

Thank you for this great package!

Could you add an API integration section in the documentation?
I would like to integrate this package with django-ninja, but I'm getting the following error:

TypeError: Object of type PageTitle is not JSON serializable

This is my schema:

class PageSchema(Schema):
    id: int
    stream: List[dict]

    def resolve_stream(self, obj):
        return obj.stream.as_list()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.