Beispiel #1
0
    def save(self, *args, **kwargs):
        orig = None
        if self.pk is not None:
            orig = Project.objects.get(pk=self.pk)
            if not orig.published and self.published:
                self.published_date = datetime.utcnow().replace(tzinfo=pytz.timezone("America/Sao_Paulo"))
                if self.email:
                    mailer = NonprofitMail(self.nonprofit)
                    mailer.sendProjectApproved(self)
                # -- ----- ----- ----- ----- -----
                # -- # Sending welcome email on project creation
                # -- plaintext = get_template('email/projectApproved.txt')
                # -- htmly     = get_template('email/projectApproved.html')
                # -- d = Context()
                # -- subject, from_email, to = u"Seu ato já está no ar.", '*****@*****.**', self.email
                # -- text_content = plaintext.render(d)
                # -- html_content = htmly.render(d)
                # -- msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
                # -- msg.attach_alternative(html_content, "text/html")
                # -- if self.email:
                # --   msg.send()
                # -- ----- ----- ----- ----- -----
            if not orig.closed and self.closed:
                self.closed_date = datetime.now()
            if not orig.deleted and self.deleted:
                self.deleted_date = datetime.now()

        # If _committed == False, it means the image is not uploaded to s3 yet
        # (will be uploaded on super.save()). This means the image is being updated
        # So we update other images accordingly
        if (not self.image._committed) or (orig is not None and (self.image != orig.image)):
            self.image_small = self.image._file  # ._file because we need the InMemoryUploadedFile instance
            self.image_medium = self.image._file
            self.image_large = self.image._file

        self.modified_date = datetime.utcnow().replace(tzinfo=pytz.timezone("America/Sao_Paulo"))

        # If there is no description, take 100 chars from the details
        if not self.description and len(self.details) > 100:
            self.description = self.details[0:100]

        return super(Project, self).save(*args, **kwargs)
Beispiel #2
0
    def save(self, *args, **kwargs):
        # If _committed == False, it means the image is not uploaded to s3 yet
        # (will be uploaded on super.save()). This means the image is being updated
        # So we update other images accordingly
        if not self.image._committed:
            self.image_small = self.image._file  # ._file because we need the InMemoryUploadedFile instance
            self.image_medium = self.image._file
            self.image_large = self.image._file

        if self.pk is not None:
            orig = Nonprofit.objects.get(pk=self.pk)
            if not orig.published and self.published:
                self.published_date = datetime.utcnow().replace(tzinfo=pytz.timezone("America/Sao_Paulo"))

                mailer = NonprofitMail(self)
                mailer.sendApproved()

            if not orig.deleted and self.deleted:
                self.deleted_date = datetime.now()

        return super(Nonprofit, self).save(*args, **kwargs)