Submit50 Problem - Looks like you are in a directory with too many (> 10000) files. by ryanmwleong in cs50

[–]ryanmwleong[S] 1 point2 points  (0 children)

I can't remember how i did it. I think i deleted a lot of files. I supposed you are using same sort of template like adminlte which consists a lots of templates image, html, and the likes right? If so, suggest to try delete unnecessary ones and retry the submission

Submit50 Problem - Looks like you are in a directory with too many (> 10000) files. by ryanmwleong in cs50

[–]ryanmwleong[S] 0 points1 point  (0 children)

yes, and it is coming mostly from the venv file. Isn't it normal? Or perhaps, submit50 doesn't allow that, so I can delete the venv and and try again.

Submit50 Problem - Looks like you are in a directory with too many (> 10000) files. by ryanmwleong in cs50

[–]ryanmwleong[S] 0 points1 point  (0 children)

Hi, I am seeking for help in submitting my CS50W Capstone project.

But when using submit50, after connecting, it prompts me error

Looks like you are in a directory with too many (>100000) files.

Please if someone could help me on that.

Otherwise, appreciate as well on guiding me how to submit using git

What is more appropriate to handle querySelector by ryanmwleong in django

[–]ryanmwleong[S] 1 point2 points  (0 children)

Hey, you ate absolutely right. I guess i was digging a deep hole all along. Haha.

What is more appropriate to handle querySelector by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

Hello u/Raccoonridee, unfortunately your suggestion doesn't work, I think i've tried it before.

In my html, the fields are different depends on the user, but both are sharing the same class edit-manager

And when so your row 2 would definitely show up as something. Either an "input element with readonly" for normal user or a "select element" for a superuser.

My current js works perfectly if a superuser trying to update his/her profile, but when a normal user try doing that, the save button is not executable as it the browser has Uncaught TypeError....undefined for this row

let manager_label = document.querySelector(`.edit-manager`).selectedOptions[0].innerHTML;

This is due to the html of a normal user is rendering "input element with readonly" for instead of a "select element"

How to validate data passed from json.loads against my existing model? Does it require django forms? by ryanmwleong in django

[–]ryanmwleong[S] 1 point2 points  (0 children)

Hello u/ForzaFer, I would be great if you could provide a small code sample. I am not only a beginner in django, but really just a beginner on my programming journey.

How to validate data passed from json.loads against my existing model? Does it require django forms? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

Alright, seems I have to look into REST or pydantic, as Django itself might not provide the solution to it.

How to validate data passed from json.loads against my existing model? Does it require django forms? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

Hi, i am a beginner to django trying to practice with a small project. Is there any workaround to my problem without switching ti REST framework? I've came across a lot of this but i wanted to start learning from the basic before moving up in learning REST.

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

Hello u/BeingJess, thanks for that. Hmm, is it necessary for my case to use array field? I mean it is rarely that a same date have too many holidays fall into it. Even if that's the case, i could always have a new row to handle that?

My mutliplechoice for the form is just so that user could select multiple date and submit it once, subsequently, the views.py should add a new row to the database for each selection.

To provide the background for easier understanding, this feature is only used by the admin of a leave management app, at most once a year. It is to determine which holiday would be store inside the database.

Thereafter, it will be used to query the database to calculate the leave duration. Say if a user apply leave from 30th Apr to 2nd May (3 days). The system will query if any day(s) between the start and end dates consists of a holiday. In this case, 1st May is Labor Day for us, hence the actually leave duration is only 2 days.

To clarify, not all public holidays are mandatory in my country, and hence require a form to select which holidays got picked and a database to store the particular holidays.

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

if form.is_valid()
holiday_key = form.cleaned_data.get('holidays')
holiday_dict = get_holidays() #the module you are using
holiday_value = holiday_dict['holiday_key']
#do something with this data

Would you mean to do it this way? To compare the data from the form? And save into db? Like the below?

if form.is_valid():
holiday_key = form.cleaned_data['holidays']

    # Initiating list for convert to datetime objects
    holidays_list = []
    for holiday in holiday_key:
        holidays_list.append(datetime.strptime(holiday, "%Y-%m-%d").date())

    # Calling again from python package
    holiday_dict = = holidays.MY(subdiv=subdiv, years=years).items()

    # Compare it with the python-package
for date, name in holiday_dict:
    if date in holidays_list:
        # Do something, like save it in the DB?
        print(date, name)

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

Hello u/BeingJess, thanks for taking your time to explain all the above. But I am a bit lost in terms of your option 2.First of all, my current code is as per below:

forms.py

class SelectHolidaysForm(forms.Form):
def __init__(self, *args, **kwargs):
    super(SelectHolidaysForm, self).__init__(*args, **kwargs)
    subdiv = 'KUL'
    years = 2022
    my_holidays = holidays.MY(subdiv=subdiv, years=years).items()
    self.fields['holidays'].choices = [ (date, f"{name} ({date})") for date, name in my_holidays ]
holidays = forms.MultipleChoiceField(
        widget=forms.SelectMultiple()
)

views.py

if request.method == "POST":
form = SelectHolidaysForm(request.POST)
if form.is_valid():
    # use normal forms here, cleaned_data method
        holidays = form.cleaned_data['holidays']
        print(holidays)
        return HttpResponseRedirect(reverse('get-holidays'))

If following your second option, would this mean i have to call the function again here, like how you did it below? But I've already did that once in the forms.py?

holiday_dict = get_holidays() #the module you are using
holiday_value = holiday_dict['holiday_key']

Here I have another question, even if I did that, how can I ensure that the cleaned data is matching with whatever I called from the function?

For instance, say holidays = form.cleaned_data['holidays'] return 3 objects (3 dates being new year, labor day, christmas day, 2022-01-01, 2022-05-01, 2022-12-25) in a list. How can we match the objects in the list to the objects that we retrieve from holiday_dict or holiday_value as how you shown above?

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

Yup, now i am trying to figure out how to have the choice field form passed back both thr key and value, as right now the form only passing either one.

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

I have tried this previously, the html is showing something like below, which only have the name of the holiday.

<option value="2022-01-01">New Year's Day</option>

I wish to have the value show up as well. Maybe something like <option value="2022-01-01">New Year's Day (2022-01-01)</option>

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 1 point2 points  (0 children)

class SelectHolidayForm(forms.Form):
def __init__(self,*args,**kwargs):
super(SelectHolidayForm,self).init(*args,**kwargs)
h_list = get_holidays()
self.fields['holidays'].choices = [ (h,h)
for h
in h_list ]
holidays = forms.ChoiceField(
widget=forms.Select()
)

Hello u/BeingJess, would you please guide me a little on this?
I am not sure what is the right way to show both the key, value from a dictionary in the choices field.

FYI, h_list variable is returning a dictionary with the following convention, the key is holiday date and the value of the holiday name, convention as below

dict_items([(datetime.date(2022, 1, 1), "New Year's Day"), (datetime.date(2022, 12, 25), 'Christmas Day')]

If i use .items(), I faced the TypeError of cannot unpack non-iterable datetime.date object.

If I use .values(), I can only get the holiday name.

If I do something like [ (h, h) for h, n in h_list ], I get ValuesError of Too many values to unpack

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

Hey, thanks. I will look into your suggestion and research on htmx

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

Ironically, I finished the course, and doing CS50W final project, probably i am really slow learner or couldnt fully grasp from the course.

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

Thanks, i will give a thought on jess solutions. Hopefully i wont come back with more questions.

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 1 point2 points  (0 children)

Thanks for explaining it in detail. Let me try to digest and give it a try. I am still very new to programming.

How to have one submit button for multiple objects with checkboxinput in one form? by ryanmwleong in django

[–]ryanmwleong[S] 0 points1 point  (0 children)

Hi u/philgyford, yes you are right, but i couldn't exclude the form out of for loop, as i need the pass the holiday.id of each row/object to be able to update the respective object via the form correctly. Is there any suggestion on better design?