Пример #1
0
def gallery_image_download(request, project_slug, project_step_number):
    # Load and send thumbnails of existing files
    project = get_object_or_404(Project, slug=project_slug)
    project_step = get_object_or_404(
        ProjectStep, project=project, _order=project_step_number
    )
    images = project_step.gallery.all()
    return AjaxResponse(request, ProjectImage.serialize(images))
Пример #2
0
def gallery_image_download(request, project_slug, project_step_number):
    # Load and send thumbnails of existing files
    project = get_object_or_404(Project, slug=project_slug)
    project_step = get_object_or_404(ProjectStep,
                                     project=project,
                                     _order=project_step_number)
    images = project_step.gallery.all()
    return AjaxResponse(request, ProjectImage.serialize(images))
Пример #3
0
 def test_multiple_images(self):
     project_image1 = self.create_project_image(
         project_step=self.project_step)
     project_image2 = self.create_project_image(
         project_step=self.project_step)
     project_image3 = self.create_project_image(
         project_step=self.project_step)
     project_images = (project_image1, project_image2, project_image3)
     response = self.client.get(self.url, is_ajax=True)
     response_data = json.loads(response.content)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         response_data, ProjectImage.serialize(project_images),
         'Response should contain the image data for images 1-3')
Пример #4
0
def gallery_image_create(request, project_slug=None, project_step_number=None):
    project_step = None
    if project_slug and project_step_number:
        project = get_object_or_404(Project, slug=project_slug)
        project_step = get_object_or_404(ProjectStep,
                                         project=project,
                                         _order=project_step_number)
        if not project.is_editable(request):
            return HttpResponseForbidden(
                'You are not the owner of this project.')
    form = ProjectImageForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        image = form.save()
        if project_step is not None:
            project_step.gallery.add(image)
        return AjaxResponse(request, ProjectImage.serialize(image))
    # A post was made without any files, just return False
    return AjaxResponse(request, False)
Пример #5
0
def gallery_image_create(request, project_slug=None, project_step_number=None):
    project_step = None
    if project_slug and project_step_number:
        project = get_object_or_404(Project, slug=project_slug)
        project_step = get_object_or_404(
            ProjectStep, project=project, _order=project_step_number
        )
        if not project.is_editable(request):
            return HttpResponseForbidden(
                'You are not the owner of this project.'
            )
    form = ProjectImageForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        image = form.save()
        if project_step is not None:
            project_step.gallery.add(image)
        return AjaxResponse(request, ProjectImage.serialize(image))
    # A post was made without any files, just return False
    return AjaxResponse(request, False)