# 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/familyform.py
# class FamilyForm(Form):
#     """
#     """
#     _class = Family
#     view = "family"
#     tview = "Family"
# 
#     # Fields for editor:
#     edit_fields = [
#     ]
# 
#     # URL for page view rows:
#     link = "/family/%(handle)s"
# 
#     # Fields for page view; width sum = 95%:
#     select_fields = [
#         ("gramps_id", 10),
#         ("father_handle", 30),
#         ("mother_handle", 30),
#         ("type.string", 25),
#     ]
# 
#     # Default order_by:
#     order_by = [("father_surname", "ASC"), ("father_given", "ASC")]
# 
#     # Search fields, list is OR:
#     search_terms = {
#         "father": ["father_surname", "father_given"], 
#         "mother": ["mother_surname", "mother_given"], 
#         "id": "gramps_id",
#     }
# 
#     # Search fields to use if not specified:
#     default_search_fields = [
#         "father_handle.primary_name.surname_list.0.surname",
#         "father_handle.primary_name.first_name",
#         "mother_handle.primary_name.surname_list.0.surname",
#         "mother_handle.primary_name.first_name",
#     ]
# 
#     # Other fields needed to select:
#     env_fields = [
#         "handle",
#     ]
# 
#     def set_post_process_functions(self):
#         self.post_process_functions = {
#             "father_handle": self.get_person_from_handle,
#             "mother_handle": self.get_person_from_handle,
#             #"tag_list": self.get_tag_from_handle:name
#         }


from gramps.gen.lib import Family
from gramps.gen.utils.grampslocale import GrampsLocale, _
from .handlers import BaseHandler
from ..forms import FamilyForm
import tornado.web
                            **self.get_template_dict(tview=_("family detail"),
                                                     page=page,
                                                     action=action,
                                                     form=FamilyForm(self.database, _, instance=family),
                                                     logform=None))
                return
            else:
                self.clear()
                self.set_status(404)
                self.finish("<html><body>No such family</body></html>")
                return
        self.render("page_view.html",
                    **self.get_template_dict(tview=_("family view"),
                                             page=page,
                                             search=search,
                                             form=FamilyForm(self.database, _, table="Family"),
                                         )
                )

    @tornado.web.authenticated
    def post(self, path):
        if "/" in path:
            handle, action = path.split("/")
        else:
            handle, action = path, "view"
        if handle == "add":
            family = Family()
            family.handle = handle = create_id()
        else:
            family = self.database.get_family_from_handle(handle)

# 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/familyform.py
# class FamilyForm(Form):
#     """
#     """
#     _class = Family
#     view = "family"
#     tview = "Family"
# 
#     # Fields for editor:
#     edit_fields = [
#     ]
# 
#     # URL for page view rows:
#     link = "/family/%(handle)s"
# 
#     # Fields for page view; width sum = 95%:
#     select_fields = [
#         ("gramps_id", 10),
#         ("father_handle", 30),
#         ("mother_handle", 30),
#         ("type.string", 25),
#     ]
# 
#     # Default order_by:
#     order_by = [("father_surname", "ASC"), ("father_given", "ASC")]
# 
#     # Search fields, list is OR:
#     search_terms = {
#         "father": ["father_surname", "father_given"], 
#         "mother": ["mother_surname", "mother_given"], 
#         "id": "gramps_id",
#     }
# 
#     # Search fields to use if not specified:
#     default_search_fields = [
#         "father_handle.primary_name.surname_list.0.surname",
#         "father_handle.primary_name.first_name",
#         "mother_handle.primary_name.surname_list.0.surname",
#         "mother_handle.primary_name.first_name",
#     ]
# 
#     # Other fields needed to select:
#     env_fields = [
#         "handle",
#     ]
# 
#     def set_post_process_functions(self):
#         self.post_process_functions = {
#             "father_handle": self.get_person_from_handle,
#             "mother_handle": self.get_person_from_handle,
#             #"tag_list": self.get_tag_from_handle:name
#         }


# Path: gramps_connect/handlers/familyhandler.py
from gramps.gen.lib import Family
from gramps.gen.utils.grampslocale import GrampsLocale, _
from .handlers import BaseHandler
from ..forms import FamilyForm
import tornado.web

                            **self.get_template_dict(tview=_("family detail"),
                                                     page=page,
                                                     action=action,
                                                     form=FamilyForm(self.database, _, instance=family),
                                                     logform=None))
                return
            else:
                self.clear()
                self.set_status(404)
                self.finish("<html><body>No such family</body></html>")
                return
        self.render("page_view.html",
                    **self.get_template_dict(tview=_("family view"),
                                             page=page,
                                             search=search,
                                             form=FamilyForm(self.database, _, table="Family"),
                                         )
                )

    @tornado.web.authenticated
    def post(self, path):
        if "/" in path:
            handle, action = path.split("/")
        else:
            handle, action = path, "view"
        if handle == "add":
            family = Family()
            family.handle = handle = create_id()
        else:
            family = self.database.get_family_from_handle(handle)

        form = FamilyForm(self.database, _, instance=family)