Commit c3e75301a18a810a50e56764d269a69c5e164c6e
1 parent
00e3357b
Exists in
master
and in
3 other branches
created replicate subject, but tagsinput is not working on replicate, still have to fix that
Showing
3 changed files
with
26 additions
and
4 deletions
Show diff stats
subjects/templates/subjects/subject_card.html
... | ... | @@ -19,7 +19,7 @@ |
19 | 19 | <i class="fa fa-ellipsis-v" aria-hidden="true"></i> |
20 | 20 | </a> |
21 | 21 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
22 | - <li><a href="#"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | |
22 | + <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | |
23 | 23 | <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
24 | 24 | <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> |
25 | 25 | </ul> |
... | ... | @@ -80,7 +80,7 @@ |
80 | 80 | <i class="fa fa-ellipsis-v" aria-hidden="true"></i> |
81 | 81 | </a> |
82 | 82 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
83 | - <li><a href="#"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | |
83 | + <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | |
84 | 84 | <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
85 | 85 | <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> |
86 | 86 | </ul> | ... | ... |
subjects/urls.py
... | ... | @@ -6,4 +6,5 @@ urlpatterns = [ |
6 | 6 | url(r'^$', views.IndexView.as_view(), name='index'), |
7 | 7 | url(r'^(?P<option>[\w_-]+)/$', views.IndexView.as_view(), name='index'), |
8 | 8 | url(r'^create/(?P<slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='create'), |
9 | + url(r'^replicate/(?P<subject_slug>[\w_-]+)$', views.SubjectCreateView.as_view(), name='replicate'), | |
9 | 10 | ] |
10 | 11 | \ No newline at end of file | ... | ... |
subjects/views.py
... | ... | @@ -122,14 +122,35 @@ class SubjectCreateView(CreateView): |
122 | 122 | |
123 | 123 | def get_initial(self): |
124 | 124 | initial = super(SubjectCreateView, self).get_initial() |
125 | - initial['category'] = Category.objects.all().filter(slug=self.kwargs['slug']) | |
125 | + if self.kwargs.get('slug'): #when the user creates a subject | |
126 | + initial['category'] = Category.objects.all().filter(slug=self.kwargs['slug']) | |
127 | + | |
128 | + if self.kwargs.get('subject_slug'): #when the user updates a subject | |
129 | + subject = get_object_or_404(Subject, slug = self.kwargs['subject_slug']) | |
130 | + initial = initial.copy() | |
131 | + initial['category'] = subject.category | |
132 | + initial['description'] = subject.description | |
133 | + initial['name'] = subject.name | |
134 | + initial['visible'] = subject.visible | |
135 | + initial['professor'] = subject.professor.all() | |
136 | + initial['tags'] = subject.tags.all() | |
137 | + initial['init_date'] = subject.init_date | |
138 | + initial['end_date'] = subject.end_date | |
139 | + initial['students'] = subject.students.all() | |
140 | + initial['description_brief'] = subject.description_brief | |
141 | + | |
142 | + | |
126 | 143 | |
127 | 144 | return initial |
128 | 145 | |
129 | 146 | def get_context_data(self, **kwargs): |
130 | 147 | context = super(SubjectCreateView, self).get_context_data(**kwargs) |
131 | 148 | context['title'] = _('Create Subject') |
132 | - context['slug'] = self.kwargs['slug'] | |
149 | + if self.kwargs.get('slug'): | |
150 | + context['slug'] = self.kwargs['slug'] | |
151 | + if self.kwargs.get('subject_slug'): | |
152 | + subject = get_object_or_404(Subject, slug = self.kwargs['subject_slug']) | |
153 | + context['slug'] = subject.category.slug | |
133 | 154 | context['subjects_menu_active'] = 'subjects_menu_active' |
134 | 155 | |
135 | 156 | return context | ... | ... |