Exemplo n.º 1
0
    def pre_dispatch(self, request, *args, **kwargs):
        response = super().pre_dispatch(request, *args, **kwargs)

        site_id = kwargs.get('site_pk', request.site.id if request and request.site.id else 1)

        self.form = EventsGalleryForm(initial={'site_id': site_id})

        return response
Exemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        edit_url = reverse('corp-site.events-gallery-edit',
                           kwargs={'gallery_pk': self.gallery.pk})

        if 'edit' in request.POST:
            self.edit_form = EventsGalleryForm(request.POST,
                                               gallery=self.gallery)

            if self.edit_form.is_valid():
                gallery = CorpEventsGallery.objects.filter(pk=self.gallery.pk)
                try:
                    gallery.update(**self.edit_form.cleaned_data)
                except IntegrityError:
                    messages.add_message(request, messages.ERROR,
                                         _('An error occured.'))
                else:
                    messages.add_message(request, messages.SUCCESS,
                                         _('Changes saved.'))
                    return redirect(edit_url)
        elif 'upload' in request.POST:
            self.upload_form = ImageUploadForm(request.POST, request.FILES)

            if self.upload_form.is_valid():
                files = request.FILES.getlist('file')
                for image_file in files:
                    CorpEventsGalleryImage.objects.create(gallery=self.gallery,
                                                          image=image_file)
                messages.add_message(request, messages.SUCCESS,
                                     _('Images uploaded.'))
                return redirect('{}?edit-images'.format(edit_url))
        elif 'reorder' in request.POST:
            for i, pk in enumerate(request.POST.getlist('pk', [])):
                try:
                    image = self.gallery.images.get(pk=pk)
                except CorpEventsGalleryImage.DoesNotExist:
                    pass
                else:
                    image.sort = i
                    image.save()
            messages.add_message(request, messages.SUCCESS,
                                 _('Images re-ordered.'))
            return redirect('{}?edit-images'.format(edit_url))

        return self.get(request, *args, **kwargs)
Exemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        self.form = EventsGalleryForm(data=request.POST)

        if self.form.is_valid():
            try:
                gallery = CorpEventsGallery.objects.create(**self.form.cleaned_data)
            except IntegrityError:
                messages.add_message(request, messages.ERROR, _('An error occured.'))
            else:
                edit_url = reverse('corp-site.events-gallery-edit',
                                   kwargs={'gallery_pk': gallery.pk})
                messages.add_message(request, messages.SUCCESS, _('Events gallery was created.'))
                return redirect(edit_url)
        else:
            messages.add_message(
                request, messages.ERROR, '{}'.format(self.form.errors)
            )

        return self.get(request, *args, **kwargs)
Exemplo n.º 4
0
class EventsGalleryAddView(EventsGalleryView):
    template = 'cms/corp_site/events-gallery-add.jinja'
    form = None

    def pre_dispatch(self, request, *args, **kwargs):
        response = super().pre_dispatch(request, *args, **kwargs)

        site_id = kwargs.get(
            'site_pk', request.site.id if request and request.site.id else 1)

        self.form = EventsGalleryForm(initial={'site_id': site_id})

        return response

    def get_extra_context(self, request, *args, **kwargs):
        context = super().get_extra_context(request, *args, **kwargs)
        # import IPython; IPython.embed();
        context.update({'form': self.form})
        return context

    def get_breadcrumbs(self, request, *args, **kwargs):
        crumbs = super().get_breadcrumbs(request, *args, **kwargs)
        return crumbs + [
            (reverse('corp-site.events-gallery-add'), _('Add New'))
        ]

    def post(self, request, *args, **kwargs):
        self.form = EventsGalleryForm(data=request.POST)

        if self.form.is_valid():
            try:
                gallery = CorpEventsGallery.objects.create(
                    **self.form.cleaned_data)
            except IntegrityError:
                messages.add_message(request, messages.ERROR,
                                     _('An error occured.'))
            else:
                edit_url = reverse('corp-site.events-gallery-edit',
                                   kwargs={'gallery_pk': gallery.pk})
                messages.add_message(request, messages.SUCCESS,
                                     _('Events gallery was created.'))
                return redirect(edit_url)
        else:
            messages.add_message(request, messages.ERROR,
                                 '{}'.format(self.form.errors))

        return self.get(request, *args, **kwargs)
Exemplo n.º 5
0
 def pre_dispatch(self, request, *args, **kwargs):
     response = super().pre_dispatch(request, *args, **kwargs)
     self.edit_form = EventsGalleryForm(gallery=self.gallery)
     self.upload_form = ImageUploadForm()
     return response
Exemplo n.º 6
0
class EventsGalleryEditView(EventsGalleryDetailsView):
    template = 'cms/corp_site/events-gallery-edit.jinja'
    edit_form = None
    upload_form = None

    def pre_dispatch(self, request, *args, **kwargs):
        response = super().pre_dispatch(request, *args, **kwargs)
        self.edit_form = EventsGalleryForm(gallery=self.gallery)
        self.upload_form = ImageUploadForm()
        return response

    def get_extra_context(self, request, *args, **kwargs):
        context = super().get_extra_context(request, *args, **kwargs)
        context.update({
            'edit_form': self.edit_form,
            'upload_form': self.upload_form
        })
        return context

    def get_breadcrumbs(self, request, *args, **kwargs):
        crumbs = super().get_breadcrumbs(request, *args, **kwargs)
        edit_url = reverse('corp-site.events-gallery-edit',
                           kwargs={'gallery_pk': self.gallery.pk})
        return crumbs + [(edit_url, _('Edit'))]

    def post(self, request, *args, **kwargs):
        edit_url = reverse('corp-site.events-gallery-edit',
                           kwargs={'gallery_pk': self.gallery.pk})

        if 'edit' in request.POST:
            self.edit_form = EventsGalleryForm(request.POST,
                                               gallery=self.gallery)

            if self.edit_form.is_valid():
                gallery = CorpEventsGallery.objects.filter(pk=self.gallery.pk)
                try:
                    gallery.update(**self.edit_form.cleaned_data)
                except IntegrityError:
                    messages.add_message(request, messages.ERROR,
                                         _('An error occured.'))
                else:
                    messages.add_message(request, messages.SUCCESS,
                                         _('Changes saved.'))
                    return redirect(edit_url)
        elif 'upload' in request.POST:
            self.upload_form = ImageUploadForm(request.POST, request.FILES)

            if self.upload_form.is_valid():
                files = request.FILES.getlist('file')
                for image_file in files:
                    CorpEventsGalleryImage.objects.create(gallery=self.gallery,
                                                          image=image_file)
                messages.add_message(request, messages.SUCCESS,
                                     _('Images uploaded.'))
                return redirect('{}?edit-images'.format(edit_url))
        elif 'reorder' in request.POST:
            for i, pk in enumerate(request.POST.getlist('pk', [])):
                try:
                    image = self.gallery.images.get(pk=pk)
                except CorpEventsGalleryImage.DoesNotExist:
                    pass
                else:
                    image.sort = i
                    image.save()
            messages.add_message(request, messages.SUCCESS,
                                 _('Images re-ordered.'))
            return redirect('{}?edit-images'.format(edit_url))

        return self.get(request, *args, **kwargs)