Commit ab4f6331ba2828ec1ad928f08f0be37fe119c060
1 parent
56cc5632
Exists in
master
and in
3 other branches
Adding webpage render after creation
Showing
7 changed files
with
119 additions
and
2 deletions
Show diff stats
subjects/templates/subjects/view.html
| ... | ... | @@ -88,4 +88,10 @@ |
| 88 | 88 | {% include 'topics/list.html' with subject=subject %} |
| 89 | 89 | </div> |
| 90 | 90 | </div> |
| 91 | + | |
| 92 | + <script type="text/javascript"> | |
| 93 | + {% if resource_new_page %} | |
| 94 | + window.open("{{ resource_new_page_url }}"); | |
| 95 | + {% endif %} | |
| 96 | + </script> | |
| 91 | 97 | {% endblock content %} |
| 92 | 98 | \ No newline at end of file | ... | ... |
subjects/views.py
| ... | ... | @@ -38,7 +38,6 @@ class HomeView(LoginRequiredMixin, ListView): |
| 38 | 38 | paginate_by = 10 |
| 39 | 39 | total = 0 |
| 40 | 40 | |
| 41 | - | |
| 42 | 41 | def get_queryset(self): |
| 43 | 42 | if self.request.user.is_staff: |
| 44 | 43 | subjects = Subject.objects.all().order_by("name") |
| ... | ... | @@ -338,6 +337,14 @@ class SubjectDetailView(LoginRequiredMixin, DetailView): |
| 338 | 337 | context = super(SubjectDetailView, self).get_context_data(**kwargs) |
| 339 | 338 | context['title'] = self.object.name |
| 340 | 339 | |
| 340 | + resources = self.request.session.get('resources', None) | |
| 341 | + | |
| 342 | + if resources: | |
| 343 | + context['resource_new_page'] = resources['new_page'] | |
| 344 | + context['resource_new_page_url'] = resources['new_page_url'] | |
| 345 | + | |
| 346 | + self.request.session['resources'] = None | |
| 347 | + | |
| 341 | 348 | return context |
| 342 | 349 | |
| 343 | 350 | ... | ... |
| ... | ... | @@ -0,0 +1,66 @@ |
| 1 | +{% extends 'subjects/view.html' %} | |
| 2 | + | |
| 3 | +{% load static i18n pagination permissions_tags %} | |
| 4 | +{% load django_bootstrap_breadcrumbs %} | |
| 5 | + | |
| 6 | +{% block javascript%} | |
| 7 | + {{ block.super }} | |
| 8 | +{% endblock%} | |
| 9 | + | |
| 10 | +{% block breadcrumbs %} | |
| 11 | + {{ block.super }} | |
| 12 | + {% breadcrumb topic 'subjects:view' subject.slug %} | |
| 13 | + {% breadcrumb webpage 'webpages:view' webpage.slug %} | |
| 14 | +{% endblock %} | |
| 15 | + | |
| 16 | +{% block content %} | |
| 17 | + {% if messages %} | |
| 18 | + {% for message in messages %} | |
| 19 | + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | |
| 20 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 21 | + <span aria-hidden="true">×</span> | |
| 22 | + </button> | |
| 23 | + <p>{{ message }}</p> | |
| 24 | + </div> | |
| 25 | + {% endfor %} | |
| 26 | + {% endif %} | |
| 27 | + | |
| 28 | + {% subject_permissions request.user subject as has_subject_permissions %} | |
| 29 | + | |
| 30 | + {% if subject.visible %} | |
| 31 | + <div class="panel panel-info subject-panel"> | |
| 32 | + <div class="panel-heading"> | |
| 33 | + {% elif has_subject_permissions %} | |
| 34 | + <div class="panel panel-info subject-panel-invisible"> | |
| 35 | + <div class="panel-heading panel-invisible"> | |
| 36 | + {% endif %} | |
| 37 | + <div class="row"> | |
| 38 | + <div class="col-md-12 category-header"> | |
| 39 | + <h4 class="panel-title" style="margin-top: 10px; margin-bottom: 8px"> | |
| 40 | + <span>{{subject.name}}</span> | |
| 41 | + </h4> | |
| 42 | + | |
| 43 | + <div class="col-md-5 pull-right category-card-items"> | |
| 44 | + {% if request.user in subject.professor.all or request.user in subject.category.coordinators.all or request.user.is_staff %} | |
| 45 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | |
| 46 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | |
| 47 | + </a> | |
| 48 | + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | |
| 49 | + <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | |
| 50 | + <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | |
| 51 | + <li><a href="{% url 'groups:index' subject.slug %}"><i class="fa fa-group fa-fw" aria-hidden="true"></i>{% trans 'Groups' %}</a></li> | |
| 52 | + <li><a href="javascript:delete_subject.get('{% url 'subjects:delete' subject.slug %}?view=index','#subject','#modal_subject')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
| 53 | + </ul> | |
| 54 | + {% endif %} | |
| 55 | + <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | |
| 56 | + <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | |
| 57 | + <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> | |
| 58 | + <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a> | |
| 59 | + </div> | |
| 60 | + </div> | |
| 61 | + </div> | |
| 62 | + </div> | |
| 63 | + <div id="{{subject.slug}}" class="panel-collapse in collapse category-panel-content"> | |
| 64 | + {{ webpage.content }} | |
| 65 | + </div> | |
| 66 | +{% endblock %} | ... | ... |
webpage/urls.py
| ... | ... | @@ -5,4 +5,6 @@ from . import views |
| 5 | 5 | |
| 6 | 6 | urlpatterns = [ |
| 7 | 7 | url(r'^create/(?P<slug>[\w_-]+)/$', views.CreateView.as_view(), name = 'create'), |
| 8 | + url(r'^window_view/(?P<slug>[\w_-]+)/$', views.NewWindowView.as_view(), name = 'window_view'), | |
| 9 | + url(r'^view/(?P<slug>[\w_-]+)/$', views.InsideView.as_view(), name = 'view'), | |
| 8 | 10 | ] | ... | ... |
webpage/views.py
| ... | ... | @@ -12,6 +12,32 @@ from topics.models import Topic |
| 12 | 12 | from .forms import WebpageForm, InlinePendenciesFormset |
| 13 | 13 | from .models import Webpage |
| 14 | 14 | |
| 15 | +class NewWindowView(LoginRequiredMixin, generic.DetailView): | |
| 16 | + login_url = reverse_lazy("users:login") | |
| 17 | + redirect_field_name = 'next' | |
| 18 | + | |
| 19 | + template_name = 'webpages/window_view.html' | |
| 20 | + model = Webpage | |
| 21 | + context_object_name = 'webpage' | |
| 22 | + | |
| 23 | +class InsideView(LoginRequiredMixin, generic.DetailView): | |
| 24 | + login_url = reverse_lazy("users:login") | |
| 25 | + redirect_field_name = 'next' | |
| 26 | + | |
| 27 | + template_name = 'webpages/view.html' | |
| 28 | + model = Webpage | |
| 29 | + context_object_name = 'webpage' | |
| 30 | + | |
| 31 | + def get_context_data(self, **kwargs): | |
| 32 | + context = super(InsideView, self).get_context_data(**kwargs) | |
| 33 | + | |
| 34 | + context['title'] = self.object.name | |
| 35 | + | |
| 36 | + context['topic'] = self.object.topic | |
| 37 | + context['subject'] = self.object.topic.subject | |
| 38 | + | |
| 39 | + return context | |
| 40 | + | |
| 15 | 41 | class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
| 16 | 42 | login_url = reverse_lazy("users:login") |
| 17 | 43 | redirect_field_name = 'next' |
| ... | ... | @@ -102,4 +128,13 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
| 102 | 128 | def get_success_url(self): |
| 103 | 129 | messages.success(self.request, _('The Webpage "%s" was added to the Topic "%s" of the virtual environment "%s" successfully!')%(self.object.name, self.object.topic.name, self.object.topic.subject.name)) |
| 104 | 130 | |
| 105 | - return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
| 106 | 131 | \ No newline at end of file |
| 132 | + success_url = reverse_lazy('webpages:view', kwargs = {'slug': self.object.slug}) | |
| 133 | + | |
| 134 | + if self.object.show_window: | |
| 135 | + self.request.session['resources'] = {} | |
| 136 | + self.request.session['resources']['new_page'] = True | |
| 137 | + self.request.session['resources']['new_page_url'] = reverse('webpages:window_view', kwargs = {'slug': self.object.slug}) | |
| 138 | + | |
| 139 | + success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
| 140 | + | |
| 141 | + return success_url | |
| 107 | 142 | \ No newline at end of file | ... | ... |