# Path: gramps_connect/handlers/handlers.py
# class BaseHandler(tornado.web.RequestHandler):
#     def __init__(self, *args, **kwargs):
#         self.log = logging.getLogger(".Handler")
#         self.database = None
#         self.sitename = None
#         self.opts = None
#         for name in ["database", "sitename", "opts"]:
#             if name in kwargs:
#                 setattr(self, name, kwargs[name])
#                 del kwargs[name]
#         super().__init__(*args, **kwargs)
#         self._ = _
# 
#     def get_current_user(self):
#         return self.get_secure_cookie("user")
# 
#     def set_language(self, language):
#         if language == GrampsLocale.DEFAULT_TRANSLATION_STR:
#             language = None
#         locale = GrampsLocale(lang=language)
#         self._ = locale.translation.gettext
# 
#     def get_template_dict(self, **kwargs):
#         dict = {
#             "database": self.database,
#             "menu": [],
#             "action": "view",
#             "user": self.current_user,
#             "sitename": self.sitename,
#             "opts": self.opts,
#             "css_theme": "Web_Mainz.css",
#             "gramps_version": VERSION,
#             "messages": [],
#             "_": self._,
#             "next": self.get_argument("next", None),
#         }
#         dict.update(template_functions)
#         dict.update(kwargs)
#         return dict
# 
#     def get_form(self, table):
#         """
#         Return the proper form, give a table name.
#         """
#         from ..forms import PersonForm, FamilyForm
#         if table == "person":
#             form = PersonForm
#         elif table == "family":
#             form = FamilyForm
#         else:
#             raise Exception("invalid form")
#         return form
# 
# Path: gramps_connect/forms/eventform.py
# class EventForm(Form):
#     """
#     A form for listing, viewing, and editing a Person object.
#     """
#     _class = Event
#     view = "event"
#     tview = "Event"
# 
#     # Fields for editor:
#     edit_fields = [
#         "type",
#         "text.string",
#         "gramps_id",
#         "tag_list",
#         "private",
#     ]
# 
#     # URL for page view rows:
#     link = "/event/%(handle)s"
# 
#     # Search fields to use if not specified:
#     default_search_fields = [
#         "text.string",
#         "gramps_id",
#     ]
# 
#     # Search fields, list is OR
#     search_terms = {
#         "text": "text.string",
#         "id": "gramps_id",
#     }
# 
#     order_by = [("gramps_id", "ASC")]
# 
#     # Fields for page view; width sum = 95%:
#     select_fields = [
#         ("gramps_id", 10),
#         ("type", 5),
#         ("description", 25),
#         ("date", 20),
#         ("change", 20),
#         ("private", 5),
#     ]
# 
#     # Other fields needed to select:
#     env_fields = [
#         "handle",
#     ]


from gramps.gen.lib import Event
from gramps.gen.utils.grampslocale import GrampsLocale, _
from .handlers import BaseHandler
from ..forms import EventForm
import tornado.web
        page = int(self.get_argument("page", 1))
        search = self.get_argument("search", "")
        if "/" in path:
            handle, action= path.split("/", 1)
        else:
            handle, action = path, "view"
        if handle:
            if handle == "add":
                event = Event()
                action = "edit"
            else:
                event = self.database.get_event_from_handle(handle)
            if event:
                self.render("event.html",
                            **self.get_template_dict(tview=_("event detail"),
                                                     action=action,
                                                     page=page,
                                                     search=search,
                                                     form=EventForm(self.database, _, instance=event),
                                                     logform=None))
                return
            else:
                self.clear()
                self.set_status(404)
                self.finish("<html><body>No such event</body></html>")
                return
        self.render("page_view.html",
                    **self.get_template_dict(tview=_("event view"),
                                             page=page,
                                             search=search,

# Path: gramps_connect/handlers/handlers.py
# class BaseHandler(tornado.web.RequestHandler):
#     def __init__(self, *args, **kwargs):
#         self.log = logging.getLogger(".Handler")
#         self.database = None
#         self.sitename = None
#         self.opts = None
#         for name in ["database", "sitename", "opts"]:
#             if name in kwargs:
#                 setattr(self, name, kwargs[name])
#                 del kwargs[name]
#         super().__init__(*args, **kwargs)
#         self._ = _
# 
#     def get_current_user(self):
#         return self.get_secure_cookie("user")
# 
#     def set_language(self, language):
#         if language == GrampsLocale.DEFAULT_TRANSLATION_STR:
#             language = None
#         locale = GrampsLocale(lang=language)
#         self._ = locale.translation.gettext
# 
#     def get_template_dict(self, **kwargs):
#         dict = {
#             "database": self.database,
#             "menu": [],
#             "action": "view",
#             "user": self.current_user,
#             "sitename": self.sitename,
#             "opts": self.opts,
#             "css_theme": "Web_Mainz.css",
#             "gramps_version": VERSION,
#             "messages": [],
#             "_": self._,
#             "next": self.get_argument("next", None),
#         }
#         dict.update(template_functions)
#         dict.update(kwargs)
#         return dict
# 
#     def get_form(self, table):
#         """
#         Return the proper form, give a table name.
#         """
#         from ..forms import PersonForm, FamilyForm
#         if table == "person":
#             form = PersonForm
#         elif table == "family":
#             form = FamilyForm
#         else:
#             raise Exception("invalid form")
#         return form
# 
# Path: gramps_connect/forms/eventform.py
# class EventForm(Form):
#     """
#     A form for listing, viewing, and editing a Person object.
#     """
#     _class = Event
#     view = "event"
#     tview = "Event"
# 
#     # Fields for editor:
#     edit_fields = [
#         "type",
#         "text.string",
#         "gramps_id",
#         "tag_list",
#         "private",
#     ]
# 
#     # URL for page view rows:
#     link = "/event/%(handle)s"
# 
#     # Search fields to use if not specified:
#     default_search_fields = [
#         "text.string",
#         "gramps_id",
#     ]
# 
#     # Search fields, list is OR
#     search_terms = {
#         "text": "text.string",
#         "id": "gramps_id",
#     }
# 
#     order_by = [("gramps_id", "ASC")]
# 
#     # Fields for page view; width sum = 95%:
#     select_fields = [
#         ("gramps_id", 10),
#         ("type", 5),
#         ("description", 25),
#         ("date", 20),
#         ("change", 20),
#         ("private", 5),
#     ]
# 
#     # Other fields needed to select:
#     env_fields = [
#         "handle",
#     ]


# Path: gramps_connect/handlers/eventhandler.py
from gramps.gen.lib import Event
from gramps.gen.utils.grampslocale import GrampsLocale, _
from .handlers import BaseHandler
from ..forms import EventForm
import tornado.web

        page = int(self.get_argument("page", 1))
        search = self.get_argument("search", "")
        if "/" in path:
            handle, action= path.split("/", 1)
        else:
            handle, action = path, "view"
        if handle:
            if handle == "add":
                event = Event()
                action = "edit"
            else:
                event = self.database.get_event_from_handle(handle)
            if event:
                self.render("event.html",
                            **self.get_template_dict(tview=_("event detail"),
                                                     action=action,
                                                     page=page,
                                                     search=search,
                                                     form=EventForm(self.database, _, instance=event),
                                                     logform=None))
                return
            else:
                self.clear()
                self.set_status(404)
                self.finish("<html><body>No such event</body></html>")
                return
        self.render("page_view.html",
                    **self.get_template_dict(tview=_("event view"),
                                             page=page,
                                             search=search,

                                             form=EventForm(self.database, _, table="Event"),