Commit c3e75301a18a810a50e56764d269a69c5e164c6e

Authored by Felipe Henrique de Almeida Bormann
1 parent 00e3357b

created replicate subject, but tagsinput is not working on replicate, still have to fix that

subjects/templates/subjects/subject_card.html
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 <i class="fa fa-ellipsis-v" aria-hidden="true"></i> 19 <i class="fa fa-ellipsis-v" aria-hidden="true"></i>
20 </a> 20 </a>
21 <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> 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 <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> 23 <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li>
24 <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp;{% trans 'Remove' %}</a></li> 24 <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp;{% trans 'Remove' %}</a></li>
25 </ul> 25 </ul>
@@ -80,7 +80,7 @@ @@ -80,7 +80,7 @@
80 <i class="fa fa-ellipsis-v" aria-hidden="true"></i> 80 <i class="fa fa-ellipsis-v" aria-hidden="true"></i>
81 </a> 81 </a>
82 <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> 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 <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> 84 <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li>
85 <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp;{% trans 'Remove' %}</a></li> 85 <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp;{% trans 'Remove' %}</a></li>
86 </ul> 86 </ul>
subjects/urls.py
@@ -6,4 +6,5 @@ urlpatterns = [ @@ -6,4 +6,5 @@ urlpatterns = [
6 url(r'^$', views.IndexView.as_view(), name='index'), 6 url(r'^$', views.IndexView.as_view(), name='index'),
7 url(r'^(?P<option>[\w_-]+)/$', views.IndexView.as_view(), name='index'), 7 url(r'^(?P<option>[\w_-]+)/$', views.IndexView.as_view(), name='index'),
8 url(r'^create/(?P<slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='create'), 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 \ No newline at end of file 11 \ No newline at end of file
subjects/views.py
@@ -122,14 +122,35 @@ class SubjectCreateView(CreateView): @@ -122,14 +122,35 @@ class SubjectCreateView(CreateView):
122 122
123 def get_initial(self): 123 def get_initial(self):
124 initial = super(SubjectCreateView, self).get_initial() 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 return initial 144 return initial
128 145
129 def get_context_data(self, **kwargs): 146 def get_context_data(self, **kwargs):
130 context = super(SubjectCreateView, self).get_context_data(**kwargs) 147 context = super(SubjectCreateView, self).get_context_data(**kwargs)
131 context['title'] = _('Create Subject') 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 context['subjects_menu_active'] = 'subjects_menu_active' 154 context['subjects_menu_active'] = 'subjects_menu_active'
134 155
135 return context 156 return context