forked from netbox-community/netbox
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request netbox-community#1026 from digitalocean/image-atta…
…chments netbox-community#152: Image attachments
- Loading branch information
Showing
22 changed files
with
330 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.6 on 2017-04-03 15:55 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import extras.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contenttypes', '0002_remove_content_type_name'), | ||
('extras', '0004_topologymap_change_comma_to_semicolon'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='ImageAttachment', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('object_id', models.PositiveIntegerField()), | ||
('image', models.ImageField(height_field=b'image_height', upload_to=extras.models.image_upload, width_field=b'image_width')), | ||
('image_height', models.PositiveSmallIntegerField()), | ||
('image_width', models.PositiveSmallIntegerField()), | ||
('name', models.CharField(blank=True, max_length=50)), | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), | ||
], | ||
options={ | ||
'ordering': ['name'], | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.conf.urls import url | ||
|
||
from extras import views | ||
|
||
|
||
urlpatterns = [ | ||
|
||
# Image attachments | ||
url(r'^image-attachments/(?P<pk>\d+)/edit/$', views.ImageAttachmentEditView.as_view(), name='imageattachment_edit'), | ||
url(r'^image-attachments/(?P<pk>\d+)/delete/$', views.ImageAttachmentDeleteView.as_view(), name='imageattachment_delete'), | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.contrib.auth.mixins import PermissionRequiredMixin | ||
from django.shortcuts import get_object_or_404 | ||
|
||
from utilities.views import ObjectDeleteView, ObjectEditView | ||
from .forms import ImageAttachmentForm | ||
from .models import ImageAttachment | ||
|
||
|
||
class ImageAttachmentEditView(PermissionRequiredMixin, ObjectEditView): | ||
permission_required = 'extras.change_imageattachment' | ||
model = ImageAttachment | ||
form_class = ImageAttachmentForm | ||
|
||
def alter_obj(self, imageattachment, request, args, kwargs): | ||
if not imageattachment.pk: | ||
# Assign the parent object based on URL kwargs | ||
model = kwargs.get('model') | ||
imageattachment.obj = get_object_or_404(model, pk=kwargs['object_id']) | ||
return imageattachment | ||
|
||
def get_return_url(self, imageattachment): | ||
return imageattachment.obj.get_absolute_url() | ||
|
||
|
||
class ImageAttachmentDeleteView(PermissionRequiredMixin, ObjectDeleteView): | ||
permission_required = 'dcim.delete_imageattachment' | ||
model = ImageAttachment | ||
|
||
def get_return_url(self, imageattachment): | ||
return imageattachment.obj.get_absolute_url() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.