Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.0][mig] website_event_snippet_calendar #213

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EventRegistrationCancelReason(models.Model):
_name = "event.registration.cancel.reason"
_description = "Event Registration Cancel Reason"

name = fields.Char(string="Reason", required=True, translate=True)
name = fields.Char("Reason", required=True, translate=True)
event_type_ids = fields.Many2many(
comodel_name="event.type",
string="Event types",
Expand Down
6 changes: 6 additions & 0 deletions setup/website_event_snippet_calendar/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
92 changes: 92 additions & 0 deletions website_event_snippet_calendar/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
==========================================
Event Calendar and List Snippet and Iframe
==========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github
:target: https://github.com/OCA/event/tree/13.0/website_event_snippet_calendar
:alt: OCA/event
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/event-13-0/event-13-0-website_event_snippet_calendar
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/199/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

When you install this addon, you will be able to drop a events calendar and
list in any website page.

Additionally, you'll have that available to embed in any ``<iframe>`` in
``/website_event_snippet_calendar/embed``.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

#. Go to any website page.
#. Edit.
#. Drag and drop the *Feature > Events Calendar and List* snippet.
#. You can click on the list and use the options dropdown to add or remove
initial events to show.
#. Save.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/event/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/event/issues/new?body=module:%20website_event_snippet_calendar%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Tecnativa

Contributors
~~~~~~~~~~~~

* `Tecnativa <https://www.tecnativa.com>`__:

* Jairo Llopis <jairo.llopis@tecnativa.com>
* Alexandre Díaz <alexandre.diaz@tecnativa.com>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/event <https://github.com/OCA/event/tree/13.0/website_event_snippet_calendar>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions website_event_snippet_calendar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from . import controllers
from . import models
15 changes: 15 additions & 0 deletions website_event_snippet_calendar/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2018 Tecnativa - Jairo Llopis
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Event Calendar and List Snippet and Iframe",
"summary": "Browsable calendar with events list for your website",
"version": "13.0.1.0.0",
"category": "Website",
"website": "https://github.com/OCA/event",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": ["website_event"],
"data": ["templates/assets.xml", "templates/embed.xml", "templates/snippets.xml"],
}
3 changes: 3 additions & 0 deletions website_event_snippet_calendar/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from . import main
94 changes: 94 additions & 0 deletions website_event_snippet_calendar/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright 2018 Tecnativa - Jairo Llopis
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from datetime import date, timedelta
from urllib.parse import parse_qsl

from odoo.fields import Date
from odoo.http import Controller, request, route


class EventCalendar(Controller):
@route(
"/website_event_snippet_calendar/days_with_events",
auth="public",
type="json",
website=True,
)
def days_with_events(self, start, end):
"""Let visitors know when are there going to be any events.

:param start string:
Search events from that date.

:param end string:
Search events until that date.
"""
events = request.env["event.event"].search(
["|", ("date_begin", "<=", end), ("date_end", ">=", start)]
)
days = set()
one_day = timedelta(days=1)
start = Date.from_string(start)
end = Date.from_string(end)
for event in events:
now = max(Date.from_string(event.date_begin), start)
event_end = min(Date.from_string(event.date_end), end)
while now <= event_end:
days.add(now)
now += one_day
return [Date.to_string(day) for day in days]

@route(
"/website_event_snippet_calendar/events_for_day",
auth="public",
type="json",
website=True,
)
def events_for_day(self, day=None, limit=None, searches=None):
"""List events for a given day.

:param day string:
Date in a string. If ``None``, we'll search for upcoming events
from today up to specified limit.

:param limit int:
How many results to return.
"""

searches = parse_qsl(searches[1:])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is error-prone. If you do None[1:] you'll get an error.

BTW I think it would be better if the JS client calls this argument directly with an array of results. Passing in a query string as a JSON argument doesn't seem very ergonomic.

ref = day or Date.to_string(date.today())
domain = [
("date_end", ">=", ref),
]
if day:
domain.append(("date_begin", "<=", ref))

for search in searches:
if search[0] == "type":
try:
value = int(search[1])
except ValueError:
value = 0
if value:
domain.append(("event_type_id", "=", int(search[1])))
Comment on lines +67 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all you're using searches for is for filtering by type, it would be better if the parameter were called type directly and got an int or List[int].

return request.env["event.event"].search_read(
domain=domain,
limit=limit,
fields=[
"date_begin_pred_located",
"name",
"event_type_id",
"website_published",
"website_url",
],
)

@route(
"/website_event_snippet_calendar/embed",
auth="public",
type="http",
website=True,
)
def embed(self, *args, **kwargs):
return request.render("website_event_snippet_calendar.embed")
87 changes: 87 additions & 0 deletions website_event_snippet_calendar/i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_event_snippet_calendar
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-26 13:13+0000\n"
"PO-Revision-Date: 2018-02-26 13:15+0000\n"
"Last-Translator: Jairo Llopis <yajo.sk8@gmail.com>\n"
"Language-Team: \n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.0.3\n"

#. module: website_event_snippet_calendar
#: model_terms:ir.ui.view,arch_db:website_event_snippet_calendar.snippet_options
msgid "<i class=\"fa fa-minus\"/> Remove one event"
msgstr ""

#. module: website_event_snippet_calendar
#: model_terms:ir.ui.view,arch_db:website_event_snippet_calendar.snippet_options
msgid "<i class=\"fa fa-plus\"/> Add one event"
msgstr ""

#. module: website_event_snippet_calendar
#: model_terms:ir.ui.view,arch_db:website_event_snippet_calendar.loading
msgid "<i class=\"fa fa-spinner fa-spin\"/> Loading..."
msgstr ""

#. module: website_event_snippet_calendar
#: model_terms:ir.ui.view,arch_db:website_event_snippet_calendar.s_event_calendar_list
msgid "All events"
msgstr "Alle Veranstaltungen"

#. module: website_event_snippet_calendar
#: model_terms:ir.ui.view,arch_db:website_event_snippet_calendar.s_event_calendar
msgid "Calendar visible only when you save"
msgstr ""

#. module: website_event_snippet_calendar
#: model:ir.model.fields,field_description:website_event_snippet_calendar.field_event_event__date_begin_pred_located
msgid "Date Begin Pred Located"
msgstr ""

#. module: website_event_snippet_calendar
#: model:ir.model,name:website_event_snippet_calendar.model_event_event
#, fuzzy
#| msgid "Events"
msgid "Event"
msgstr "Veranstaltungen"

#. module: website_event_snippet_calendar
#: model_terms:ir.ui.view,arch_db:website_event_snippet_calendar.s_event_list
msgid "Event list visible only when you save."
msgstr ""

#. module: website_event_snippet_calendar
#: model_terms:ir.ui.view,arch_db:website_event_snippet_calendar.s_event_calendar_list
msgid "Events"
msgstr "Veranstaltungen"

#. module: website_event_snippet_calendar
#: model_terms:ir.ui.view,arch_db:website_event_snippet_calendar.s_event_calendar_list
msgid "Events Calendar"
msgstr "Veranstaltungskalender"

#. module: website_event_snippet_calendar
#: model_terms:ir.ui.view,arch_db:website_event_snippet_calendar.s_event_list
msgid "It will display up to the closest <b class=\"js_amount\">4</b> events."
msgstr ""

#. module: website_event_snippet_calendar
#: model_terms:ir.ui.view,arch_db:website_event_snippet_calendar.s_event_calendar_list
msgid "List"
msgstr "Liste"

#. module: website_event_snippet_calendar
#. openerp-web
#: code:addons/website_event_snippet_calendar/static/src/xml/snippets.xml:22
#, python-format
msgid "unpublished"
msgstr ""
Loading