Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 14 2021 16:11
    @MadLittleMods banned @Rehmanjeff
Kizito Njoku
@nkizito92
Does anyone know why I don't get the POST request data for my reducer in react, but the request is still a success for the backEnd?
import { createSlice } from '@reduxjs/toolkit'
export const cardReducer = createSlice({
    name: 'cards',
    initialState: {
        cards: [],
        isLoading: false
    },
    reducers: {
        getCardsFetch: (state) => {
            state.isLoading = true;
        },
        getCardsSuccess: (state, action) => {
            state.cards = action.payload;
            state.isLoading = false
        },
 # This is where the Post request data is added to the state
        newCardPost: (state, action) => {
            return {
                ...state, cards: [...state.cards, action.payload]
            }
        },
        updateCardSuccess: (state, action) => {
            const idx = state.cards.findIndex(card => card.id === Number(action.payload.id))
            const newState = [...state.cards]
            newState.splice(idx, 1, action.payload)
            return {
                ...state, cards: [...newState],
            }
        },
        deleteCardSuccess: (state, action) => {
            return {
                ...state,
                cards: [...state.cards.filter(card => card.id !== Number(action.payload.id))]
            }
        },
        getCardsFailure: (state) => {
            state.isLoading = false;
        }
    }

});
Kizito Njoku
@nkizito92
Python code from views.py
# Create a Word
@api_view(['POST'])
def addWord(request):
    newWord = request.data
    # How to create an object
    word = Word.objects.create(
        name=newWord['word']['name'], definition=newWord['word']['definition']
    )
    serializer = WordSerializer(word, many=False)
    # To debug first import pdb then from desired line type pdb.set_trace()
    return Response(serializer.data)
Kizito Njoku
@nkizito92
RobertDowneyJrFrustratedGIF.gif
So everything is working, but the new object I create is undefined for the state until I refresh the page. I checked the actions payload and everything the user sent is there.
Julian Gonggrijp
@jgonggrijp
@nkizito92 I see nothing problematic in the Python part. The JS part is also more complex, so I suspect the cause of the problem is somewhere in there. However, I don't know enough about React or Redux to identify the problem easily. Perhaps take it to a dedicated React/Redux room.
Kizito Njoku
@nkizito92
I knew nothing was wrong with the Python part. I don't get why the React part doesn't. I will do some more research on this. @jgonggrijp Thanks tho.
Kizito Njoku
@nkizito92
I got it to work
Julian Gonggrijp
@jgonggrijp
@nkizito92 Well done. Please share the answer if you don't mind.
Kizito Njoku
@nkizito92
So it was in my Post request all I added was yield workGetCardsFetch()
to get the data from the backend
here is the full code
function* workGetCardsFetch() {
    // const cards = yield call(() => fetch('http://127.0.0.1:8000/'))
    // const formattedCards = yield cards.json();
    const cards = yield call(() => axios.get('http://127.0.0.1:8000/'))
    yield put(getCardsSuccess(cards.data))
}

function* workCreateCard(action) {
    try {
        const word = action.payload
        const options = {headers: { "content-type": "application/json" }}
        yield call(() => axios.post('http://127.0.0.1:8000/words/new/', { word }, options))
# here is what I added in the Post request    
    yield workGetCardsFetch()
    } catch (error) {
        console.log(error.message)
    }
}
Kizito Njoku
@nkizito92
So the problem was the reducer wouldn't get the new id for the state the backend created for the new object, all I did was make the generate function* workCreateCard call the generate function* workGetCardsFetch to get all the data including the new one to display
Julian Gonggrijp
@jgonggrijp
@nkizito92 Clear! Thx
ghobona
@ghobona

The Open Geospatial Consortium (OGC) invites software developers to the July 2022 OGC API Code Sprint, aka ‘The Vector Data Code Sprint’, to be held virtually from July 12th-14th, 2022. Registration closes July 12.

The Vector Data Code Sprint will focus on the following standards, which are mostly related to vector data and their associated attributes:

Register at https://developer.ogc.org/sprints/17

Note for django developers, some of the participating projects (e.g. pygeoapi) have implemented OGC API Standards using django and other python-based libraries. So the code sprint will be a good opportunity to find out above those projects.

kalaLokia
@kalaLokia
What is the best way to create unique order number for a django ecommerce web application?
using uuid4 is good or bad choice?
SERP!CO
@serpic0:matrix.org
[m]
@kalaLokia: The shortuuid library has been useful to me for many years
https://pypi.org/project/shortuuid/
Ken-tech-max
@Ken-tech-max
Hello @everyone is there any example of Django-react pdf reader in github or any blog?
Rens Houben
@rhouben:vac.systemec.nl
[m]

Hokay, I've got kind of a convoluted setup here that I need to modify.

Core point for this is that I have a class 'Connection' and a class 'NAS', and a lot of both. Now because of orders from On High I need to be able to define, per Connection, which NAS elements are valid for that particular Connection. I think a ManyToManyField may do what I want but I'm not 100% sure.

Ideally, I'd want to represent it in the frontend with one of those dropdown-with-radio elements, because while the number of NAS objects will be limited I can't predict how many there will be.
Rens Houben
@rhouben:vac.systemec.nl
[m]

... Also, while updating my test suite I'm suddenly getting a whole shitload of error messages like this:

RuntimeError: Model class urania.radius.models.Version doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

and I'm not sure what's causing them since I don't see them when I run the tests on my local machine.

Rens Houben
@rhouben:vac.systemec.nl
[m]
:point_up: Edit: Never mind, this was a typo in the rsync command.
Piyush
@piexpie
hi
is there any library that can automatically generate CRUD APIs for django models?
Django rest framework is there but it still requires writing separate serializers and views for each model...
I would prefer an automatic CRUD API from the models
Piyush
@piexpie
@everyone
Chris Maggiulli
@cmaggiulli
Hi everyone. I have a fairly complex design question related to our hierarchical group role access control implementation, built on top of Django Guardian. I essentially need a recommendation on how to implement user object and group object create permissions. We have a very robust implementation of view, delete, edit but add is difficult because there is no object to apply the the permission to. I'm thinkin maybe a pre-save handler that checks if certain conditions are meant and applies the permission? Is there a place I could long form discuss this?
2 replies
SERP!CO
@serpic0:matrix.org
[m]
@cmaggiulli: What you're looking for is called Signals. Pretty straight forward if you follow the official documentation.
Chris Maggiulli
@cmaggiulli
@serpic0:matrix.org thanks for the reply. We use signals fairly extensively, if I show you my PoC could you see if it aligns with what youre thinking?
I went with a signals impl
I was debating signals or middleware
SERP!CO
@serpic0:matrix.org
[m]
if it's permissions check before an 'add', I'd keep it simple and use pre_save signal for the add class.
8 replies
Mohit Full Stack Developer
@mohit0812
Hello all
I need one help. I am trying to deploy django channel app to aws. App is working fine. But websockets are not working. I am trying to run it through nginx, Daphne app server and redis server.
Any suggestion to debug it?
SERP!CO
@serpic0:matrix.org
[m]
@mohit0812: try making it work on WS only not WSS to start your trouble shooting. In other words with no SSL. Once you get it working on WS, then focus on SSL which seems to be the thing that most get stuck on when implementing Channel.
Mohit Full Stack Developer
@mohit0812
Hello @serpic0:matrix.org
Thanks for your advice.
I tried to run it on ip without ssl. And it is working fine. BUt again using ssl same issues. Any idea
My Homework Help
@MyHomeworkHelp1_twitter
It is my privilege to join this chat room, as I am an online Python tutor assisting students worldwide with their assignment solutions. The whole process of learning should never be tedious. The experts here take care of it. The fundamentals of each topic should be firmly in the students' grasp. This is something the tutors strongly believe in. The material offered is highly engaging and students can learn a lot from them. With the help provided by talented coding tutors, students may also look forward to participating in other activities and hobbies. It is really important to survive in today's competitive world, My Homework Help provides this opportunity to the students. Check out there: https://myhomeworkhelp.com/online-python-homework-help/
aarushkuk
@aarushkuk
Just wanted to share a cool project in the works, attempting to connect turbulence to biology: https://github.com/aarushkuk/Turbulence-in-Flocking-Behavior-Versus-Fuel-Injector
Sirius Sufiev
@sc0der
hey everyone )
What should I do to become a contributor in django ?
SERP!CO
@serpic0:matrix.org
[m]
@sc0der: contact the Django foundation directly. They have their contact on their official website. If your skillset is up to snuff, they ll give you something to work on and you work your way up from there :).
Good luck!
LiteWait
@LiteWait
Two things I am struggling with. 1. I am trying to prove all my middleware supports async (logger.debug('Synchronous %s adapted.', name) is never displayed, even with test middleware that explicit says its synchronous. 2. How do I know my view is running async (as opposed to being wrapped in sync_to_async).
DeVon Jackson
@devo-wm
Does anyone understand why UniqueConstraints don't trigger form validation errors?
do I have to add an additional query to the clean() method on the form to resolve? :(
DeVon Jackson
@devo-wm

aaah:

In general constraints are not checked during full_clean(), and do not raise ValidationErrors. Rather you’ll get a database integrity error on save(). UniqueConstraints without a condition (i.e. non-partial unique constraints) are different in this regard, in that they leverage the existing validate_unique() logic, and thus enable two-stage validation. In addition to IntegrityError on save(), ValidationError is also raised during model validation when the UniqueConstraint is violated.

jasukanhasoft
@jasukanhasoft

We have an in-house team of software developers for various technologies including ReactJS, NextJS, Typescript, NodeJS, VueJS, Angular, YII, Python(Django), PHP, Laravel, YII, CodeIgniter Javascript, React Native, Android, iOS, and many more.

Hire now at https://www.kanhasoft.com/

We can also share references of our clients so that you can connect with them directly and ask about our service and work ethics.

Hire the best developer for your business needs.

jasukanhasoft
@jasukanhasoft

Hope you are doing fantastic!

It will take just a min. of yours, Do you need web and mobile developers/team?
Collaborate with us and get 8 hours free trial of web and mobile developer/team.

Kind Regards,
www.kanhasoft.com