def form_before_create_or_update(self, values, extra_values):
     """ Dismiss any pending status message, to avoid multiple
     messages when multiple forms are present on same page.
     """
     if extra_values.get("profile_photo"):
         self.main_object.partner_id.image = compress_big_images(
             extra_values["profile_photo"])
     self.o_request.website.get_status_message()
示例#2
0
 def form_after_create_or_update(self, values, extra_values):
     if values["deadline"] < datetime.now().date():
         raise InvalidDateException
     if values.get("cover_photo"):
         values["cover_photo"] = compress_big_images(values["cover_photo"])
     for key in [
             "presentation_video", "facebook_url", "twitter_url",
             "instagram_url", "personal_web_page_url"
     ]:
         values[key] = ProjectCreationWizard.sanitized_url(values, key)
     super().form_after_create_or_update(values, extra_values)
示例#3
0
    def form_after_create_or_update(self, values, extra_values):
        super().form_after_create_or_update(values, extra_values)
        if self.participant_id:
            config = self.env.ref(
                "crowdfunding_compassion.config_project_join").sudo()
            participant = self.participant_id.sudo()
            partner = participant.partner_id.sudo()

        else:
            config = self.env.ref(
                "crowdfunding_compassion.config_project_confirmation").sudo()
            participant = self.main_object.sudo().participant_ids
            partner = self.main_object.sudo().project_owner_id.sudo()

        if extra_values.get('partner_image'):
            extra_values["partner_image"] = compress_big_images(
                extra_values["partner_image"])
            partner.write({"image": extra_values["partner_image"]})
        else:
            path = "crowdfunding_compassion/static/src/img/guy.png"
            if partner.title.gender == "F":
                path = "crowdfunding_compassion/static/src/img/lady.png"
            partner.write({"image": b64encode(file_open(path, "rb").read())})

        extra_values.update(values)
        participant_values = {
            key.replace("participant_", ""): val
            for key, val in extra_values.items()
            if key.startswith("participant_") and val
        }
        participant.sudo().write(participant_values)
        comm_obj = self.env["partner.communication.job"].sudo()
        comm_obj.create({
            "config_id": config.id,
            "partner_id": partner.id,
            "object_ids": self.main_object.sudo().id,
        })

        # Notify staff of new participant
        settings = self.env["res.config.settings"].sudo()
        notify_ids = settings.get_param("new_participant_notify_ids")
        if notify_ids:
            user = self.env["res.partner"].sudo().browse(notify_ids[0][2]) \
                       .mapped("user_ids")[:1]
            participant.partner_id.sudo().activity_schedule(
                'mail.mail_activity_data_todo',
                summary="New Crowdfunding participant",
                note=
                f"{participant.partner_id.name} created or joined a project. "
                f"A user may need to be created if he doesn't have access",
                user_id=user.id)
 def form_after_create_or_update(self, values, extra_values):
     if values.get("name") or values.get("description"):
         # Notify responsible of the changes, for validation.
         settings = self.env["res.config.settings"].sudo()
         if values.get("cover_photo"):
             values["cover_photo"] = compress_big_images(
                 values["cover_photo"])
         notify_ids = settings.get_param("new_participant_notify_ids")
         if notify_ids:
             user = self.env["res.partner"].sudo().browse(notify_ids[0][2]) \
                        .mapped("user_ids")[:1]
             self.main_object.sudo().activity_schedule(
                 'mail.mail_activity_data_todo',
                 summary="Verify project information.",
                 note=f"{self.main_object.project_owner_id.name} updated the "
                 f"name and description of the project. "
                 f"Please check if the information is good enough.",
                 user_id=user.id)
    def _compute_homepage_context(self, year, **kwargs):

        project_obj = request.env["crowdfunding.project"].sudo()
        current_year_projects = project_obj.get_active_projects(year=year)
        active_funds = current_year_projects.mapped("product_id")
        impact = {
            "sponsorship": sponsorship_card_content()
        }
        for fund in active_funds:
            impact[fund.name] = {
                "type": "fund",
                "value": 0,
                "name": fund.crowdfunding_impact_text_active,
                "text": fund.crowdfunding_impact_text_passive_singular,
                "description": fund.crowdfunding_description,
                "icon_image": fund.image_medium or SPONSOR_ICON,
                # the header is a small image so we can compress it to save space
                "header_image":
                    compress_big_images(
                        fund.image_large,
                        max_bytes_size=2e4,
                        max_width=400
                    ) if fund.image_large else SPONSOR_HEADER,

            }

        for project in current_year_projects:
            impact["sponsorship"]["value"] += project.number_sponsorships_reached
            project_fund = project.product_id.name
            if project_fund in impact:
                impact[project_fund]["value"] += project.product_number_reached

        for fund in active_funds:
            if impact[fund.name]["value"] > 1:
                impact[fund.name]["text"] = fund.crowdfunding_impact_text_passive_plural

        if impact["sponsorship"]["value"] > 1:
            impact["sponsorship"]["text"] = _("sponsored children")

        return {
            "projects": current_year_projects[:8],
            "impact": {k: v for k, v in impact.items() if v['value']},
            "base_url": request.website.domain
        }
import base64
import time
from datetime import datetime
import logging

from odoo import _
from odoo.http import request, route, Controller
from odoo.tools.misc import file_open

from odoo.addons.website_compassion.tools.image_compression import compress_big_images

SPONSOR_HEADER = compress_big_images(base64.b64encode(file_open(
    "crowdfunding_compassion/static/src/img/sponsor_children_banner.jpg", "rb"
).read()), max_bytes_size=2e4, max_width=400)

SPONSOR_ICON = base64.b64encode(file_open(
    "crowdfunding_compassion/static/src/img/icn_children.png", "rb").read())

_logger = logging.getLogger(__name__)


def sponsorship_card_content():
    return {"type": "sponsorship",
            "value": 0,
            "name": _("Sponsor children"),
            "text": _("sponsored child"),
            "description": _("""
For 42 francs a month, you're opening the way out of poverty for a child. Sponsorship
 ensures that the child is known, loved and protected. In particular, it gives the child
 access to schooling, tutoring, regular balanced meals, medical care and training in the
 spiritual field, hygiene, etc. Every week, the child participates in the activities of