Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 25 attribution change #48

Draft
wants to merge 24 commits into
base: refactor
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Form update
Created CreateResourceForm in forms.py and updated views.py to utilize the new custom form. This form will more appropriately handle multiselect fields. Still need to add the ability to add a new author.
brandon.rosenbloom committed May 21, 2021
commit 4befbe2a3be69c39eb21edf0b7eb30e60d8dd6b4
41 changes: 41 additions & 0 deletions python-in-edu/resources/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django import forms
from .models import Resource, ResourceType, ResourceAudience, Device, ResourceUseType, ResourceLanguage


class CreateResourceForm(forms.ModelForm):
class Meta:
model = Resource
# fields = '__all__'
fields = [
'title',
'description',
'requires_signup',
'license',
]

description = forms.Textarea()

resource_types = forms.ModelMultipleChoiceField(
queryset=ResourceType.objects.all(),
widget=forms.CheckboxSelectMultiple
)

audience = forms.ModelMultipleChoiceField(
queryset=ResourceAudience.objects.all(),
widget=forms.CheckboxSelectMultiple
)

devices = forms.ModelMultipleChoiceField(
queryset=Device.objects.all(),
widget=forms.CheckboxSelectMultiple
)

use_type = forms.ModelMultipleChoiceField(
queryset=ResourceUseType.objects.all(),
widget=forms.CheckboxSelectMultiple
)

languages = forms.ModelMultipleChoiceField(
queryset=ResourceLanguage.objects.all(),
widget=forms.CheckboxSelectMultiple
)
4 changes: 2 additions & 2 deletions python-in-edu/resources/views.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect
from .forms import CreateResourceForm


from .models import Profile, Resource, Author
@@ -56,8 +57,7 @@ def get_context_data(self, **kwargs):

class ResourceCreateView(LoginRequiredMixin, generic.CreateView):
model = Resource
fields = ['title', 'url1', 'url_description1', 'url2', 'url_description2', 'url3', 'url_description3', 'resource_type', 'audience', 'devices', 'requires_signup', 'use_type', 'python_related',
'description', 'author', 'language', 'license', 'contact']
form_class = CreateResourceForm
template_name = 'resources/add_resource.html'

def get_success_url(self, instance):