Commit 0b32801cff5ffdc06e20e5f39152869b524c8dcc
1 parent
7ce858cd
Exists in
master
and in
3 other branches
added open in new window logic for pdf files
Showing
9 changed files
with
126 additions
and
12 deletions
Show diff stats
... | ... | @@ -0,0 +1,21 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10.4 on 2017-02-09 17:34 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.db import migrations, models | |
6 | +import django.db.models.deletion | |
7 | + | |
8 | + | |
9 | +class Migration(migrations.Migration): | |
10 | + | |
11 | + dependencies = [ | |
12 | + ('mural', '0005_mural_edited'), | |
13 | + ] | |
14 | + | |
15 | + operations = [ | |
16 | + migrations.AlterField( | |
17 | + model_name='comment', | |
18 | + name='post', | |
19 | + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='comment_post', to='mural.Mural', verbose_name='Post'), | |
20 | + ), | |
21 | + ] | ... | ... |
pdf_file/forms.py
... | ... | @@ -24,7 +24,7 @@ class PDFFileForm(forms.ModelForm): |
24 | 24 | tags = forms.CharField(label = _('Tags'), required = False) |
25 | 25 | class Meta: |
26 | 26 | model = PDFFile |
27 | - fields = ['name', 'file', 'brief_description', 'all_students', 'students', 'groups', 'visible'] | |
27 | + fields = ['name', 'file', 'brief_description','show_window', 'all_students', 'students', 'groups', 'visible'] | |
28 | 28 | labels = { |
29 | 29 | 'name': _('File name'), |
30 | 30 | } | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10.4 on 2017-02-09 17:34 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.db import migrations, models | |
6 | +import pdf_file.models | |
7 | + | |
8 | + | |
9 | +class Migration(migrations.Migration): | |
10 | + | |
11 | + dependencies = [ | |
12 | + ('pdf_file', '0001_initial'), | |
13 | + ] | |
14 | + | |
15 | + operations = [ | |
16 | + migrations.AlterField( | |
17 | + model_name='pdffile', | |
18 | + name='file', | |
19 | + field=models.FileField(upload_to='files/', validators=[pdf_file.models.validate_file_extension], verbose_name='File'), | |
20 | + ), | |
21 | + ] | ... | ... |
pdf_file/models.py
... | ... | @@ -16,6 +16,7 @@ def validate_file_extension(value): |
16 | 16 | |
17 | 17 | class PDFFile(Resource): |
18 | 18 | file = models.FileField(_('File'), upload_to='files/', validators = [validate_file_extension]) |
19 | + | |
19 | 20 | class Meta: |
20 | 21 | verbose_name = "PDFFile" |
21 | 22 | verbose_name_plural = "PDFFiles" | ... | ... |
pdf_file/templates/pdf_file/_form.html
... | ... | @@ -87,6 +87,29 @@ |
87 | 87 | {% endif %} |
88 | 88 | </div> |
89 | 89 | |
90 | + <div class="form-group{% if form.has_error %} has-error {% endif %}"> | |
91 | + <div class=" checkbox"> | |
92 | + <label for="{{ form.show_window.auto_id }}"> | |
93 | + {% render_field form.show_window %} {{ form.show_window.label }} | |
94 | + </label> | |
95 | + </div> | |
96 | + | |
97 | + <span id="helpBlock" class="help-block">{{ form.show_window.help_text }}</span> | |
98 | + | |
99 | + {% if form.show_window.errors %} | |
100 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
101 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
102 | + <span aria-hidden="true">×</span> | |
103 | + </button> | |
104 | + <ul> | |
105 | + {% for error in form.show_window.errors %} | |
106 | + <li>{{ error }}</li> | |
107 | + {% endfor %} | |
108 | + </ul> | |
109 | + </div> | |
110 | + {% endif %} | |
111 | + </div> | |
112 | + | |
90 | 113 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> |
91 | 114 | <label for="{{ form.tags.auto_id }}">{{ form.tags.label }}</label> |
92 | 115 | {% render_field form.tags class='form-control' data-role="tagsinput" %} | ... | ... |
pdf_file/templates/pdf_file/view.html
... | ... | @@ -17,13 +17,16 @@ |
17 | 17 | |
18 | 18 | {% breadcrumb topic 'subjects:topic_view' topic.subject.slug topic.slug %} |
19 | 19 | |
20 | - {% trans 'Edit: ' as bread %} | |
21 | - {% with bread|add:pdf_file.name as bread_slug %} | |
22 | - {% breadcrumb bread_slug 'pdf_file:update' topic.slug pdf_file.slug %} | |
23 | - {% endwith %} | |
20 | + | |
24 | 21 | {% endblock %} |
25 | 22 | |
26 | 23 | |
27 | 24 | {% block content %} |
28 | - {{context\pdf_file}} | |
25 | + | |
26 | +<object width="100%" height="100%" type="application/pdf" data="{{pdf_file.file.path}}" id="pdf_content"> | |
27 | + <p>Insert your error message here, if the PDF cannot be displayed.</p> | |
28 | + </object> | |
29 | + | |
30 | + <embed src="{{pdf_file.file.path}}" width="100%" height="100%"> | |
31 | + | |
29 | 32 | {% endblock content %} |
30 | 33 | \ No newline at end of file | ... | ... |
pdf_file/views.py
... | ... | @@ -32,6 +32,12 @@ class ViewPDFFile(generic.TemplateView): |
32 | 32 | |
33 | 33 | return super(ViewPDFFile, self).dispatch(request, *args, **kwargs) |
34 | 34 | |
35 | + def get_context_data(self, **kwargs): | |
36 | + context = super(ViewPDFFile, self).get_context_data(**kwargs) | |
37 | + slug = self.kwargs.get('slug', '') | |
38 | + pdf_file = PDFFile.objects.get(slug=slug) | |
39 | + context['pdf_file'] = pdf_file | |
40 | + return context | |
35 | 41 | |
36 | 42 | |
37 | 43 | def render_to_response(self, context, **response_kwargs): |
... | ... | @@ -40,10 +46,18 @@ class ViewPDFFile(generic.TemplateView): |
40 | 46 | |
41 | 47 | if not path.exists(pdf_file.file.path): |
42 | 48 | raise Http404() |
43 | - | |
44 | - response = HttpResponse(open(pdf_file.file.path, 'rb').read(),content_type = 'application/pdf') | |
45 | - | |
46 | - return response | |
49 | + if pdf_file.show_window: | |
50 | + response = HttpResponse(open(pdf_file.file.path, 'rb').read(),content_type = 'application/pdf') | |
51 | + return response | |
52 | + | |
53 | + | |
54 | + response_kwargs.setdefault('content_type', self.content_type) | |
55 | + return self.response_class( | |
56 | + request = self.request, | |
57 | + template = self.get_template_names(), | |
58 | + context = context, | |
59 | + **response_kwargs | |
60 | + ) | |
47 | 61 | |
48 | 62 | class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): |
49 | 63 | form_class = PDFFileForm | ... | ... |
subjects/views.py
... | ... | @@ -566,9 +566,9 @@ class SubjectSearchView(LoginRequiredMixin, LogMixin, ListView): |
566 | 566 | q = q | Q(tags__name__unaccent__iexact=word ) |
567 | 567 | |
568 | 568 | subjects = Subject.objects.filter(q).distinct() |
569 | + self.resources = Resource.objects.select_related('link', 'filelink', 'webpage', 'ytvideo', 'pdffile').filter(q ).distinct() | |
570 | + | |
569 | 571 | |
570 | - self.resources = Resource.objects.select_related('link', 'filelink', 'webpage', 'ytvideo').filter(q).distinct() | |
571 | - | |
572 | 572 | self.totals = {'resources': self.resources.count(), 'my_subjects': subjects.count()} |
573 | 573 | |
574 | 574 | option = self.kwargs.get('option') | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10.4 on 2017-02-09 17:34 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.db import migrations, models | |
6 | +import themes.models | |
7 | + | |
8 | + | |
9 | +class Migration(migrations.Migration): | |
10 | + | |
11 | + dependencies = [ | |
12 | + ('themes', '0004_themes_favicon'), | |
13 | + ] | |
14 | + | |
15 | + operations = [ | |
16 | + migrations.AlterField( | |
17 | + model_name='themes', | |
18 | + name='favicon', | |
19 | + field=models.ImageField(blank=True, null=True, upload_to='themes/', validators=[themes.models.validate_img_extension], verbose_name='Favicon'), | |
20 | + ), | |
21 | + migrations.AlterField( | |
22 | + model_name='themes', | |
23 | + name='large_logo', | |
24 | + field=models.ImageField(blank=True, null=True, upload_to='themes/', validators=[themes.models.validate_img_extension], verbose_name='Large Logo'), | |
25 | + ), | |
26 | + migrations.AlterField( | |
27 | + model_name='themes', | |
28 | + name='small_logo', | |
29 | + field=models.ImageField(blank=True, null=True, upload_to='themes/', validators=[themes.models.validate_img_extension], verbose_name='Small Logo'), | |
30 | + ), | |
31 | + ] | ... | ... |