Francisco Hidalgo
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Geoximity ## Stack The tech stack to use in the backend will be: - Django >= 2.2.6 - Django ORM mixed with SQLAlchemy - Celery - Django-rest-framework The tech stack to use in the frontend will be: - Vue 2 ## Components ### DB #### Current status The main DB is a PostgreSQL (PostGIS). The data is managed through Django framework with the ORM. #### Drawbacks TBD #### Solution The main DB will be a PostgreSQL (PostGIS). The data will be managed with a mix of SQLAlchemy and Django ORM. ### Models #### Current status The Proximity's model changes for each client, the main core is re-used but there are many differences between clients. #### Drawbacks - Problems with the code, it's little scalable and a mess. - Every new custom field for a specific customer will add a new column for every customer, even when this column won't be used #### Solution The Proximity's model changes for each client, the main core is re-used but there are many differences between clients, because of this it's needed to build a dynamic model, these models can be developed using a set of pre-defined fields or using a third-party packages as: - django-mutant - eav-django - django-hstore After the last discussion, we won't use special packages, JSON or HSTORE. We will use meta-models that overwrite the Django's base model in order to add custom fields, these custom fields will be set by a custom configuration. The following code shows an approximation of the solution: ```python from django.db.models.base import ModelBase from django.db import models CONF = { 'aux_str_1': { 'name': 'zone_name', 'type': models.CharField(max_length=200, db_column='aux_str_1') } } class ShopMetaClass(ModelBase): def __new__(cls, name, bases, attrs): for field in CONF: attrs[CONF[field]['name']] = CONF[field]['type'] return super(ShopTestMetaClass, cls).__new__(cls, name, bases, attrs) class Shop(metaclass=ShopMetaClass): name = models.CharField(max_length=200) ``` > Luis comment on 2019-10-16 > > I was thinking in something more similar to the following. Field types and > initialization should not be editable, just fields involving no database > operations. > > ```python > from django.db.models.base import ModelBase > from django.db import models > > CONF = { > 'aux_str_1': { > 'name': 'zone_name', > 'kwargs': { > "max_length": 32 > } > }, > 'aux_fk_1': { > 'name': 'updated_by', > 'kwargs': { > 'to': 'auth.User' > } > } > } > > class ShopMetaClass(ModelBase): > > class AdvertCustomFieldTypes: > TEXT = { > "field": models.TextField, > "enforced_kwargs": {}, > "default_kwargs": {"max_length": 256}, > "db_columns": set(`aux_str_{x}` for x in range(1,5)) > ) > INTEGER = { > "field": models.IntegerField, > "enforced_kwargs": {}, > "default_kwargs": {}, > "db_columns": set(`aux_int_{x}` for x in range(1,5)) > ) > FOREIGN_KEY = { > "field": models.ForeignKey, > "enforced_kwargs": {"db_constraint": False}, > "default_kwargs": {}, > "db_columns": set(`aux_fk_{x}` for x in range(1,5)) > ) > > @classmethod > def field_types(cls): > return sorted(x for x in dir(cls) if isintance(x, dict) and 'field' in x) > > @classmethod > def db_columns(cls): > return sorted(chain(*(getattr(cls, field_type)['db_columns'] for field_type in cls.field_types))) > > @classmethod > def attr_field_type(cls, attr_name): > for field_type in cls.field_types: > if attr_name in getattr(field_type, field_type)['db_columns']: > return field_type > raise AttributeError('Field not found') > > @classmethod > def attr_field_conf(cls, attr_name): > field_type = cls.attr_field_type(attr_name) > return getattr(cls, field_type) > > > > def __new__(cls, name, bases, attrs): > # In order to have properly working transactions, we have to add > # all fields to the model, even if they are not used. > for column_name in AdvertCustomFieldTypes.db_columns: > field_conf = AdvertCustomFieldTypes.attr_field_conf(column_name) > kwargs = field_conf['default_kwargs'] > > if column_name in CONF: > attr_name = CONF[column_name][name] > kwargs.update(CONF[column_name]['kwargs']) > else: > attr_name = column_name > > kwargs.update(field_conf['enforced_kwargs']) > kwargs['db_column'] = field_name > > attrs[attr_name] = field_conf['field'](**kwargs) > > return super(ShopTestMetaClass, cls).__new__(cls, name, bases, attrs) > > > class Shop(metaclass=ShopMetaClass): > name = models.CharField(max_length=200) > ``` #### Other solutions - Use JSON fields (performance it's not bad at all). - Use a NO-SQL DB. ### API #### Current status The project uses django-rest-framework. #### Solution The project will use django-rest-framework. It can be useful use drf-yasg as Swagger automatic provider. ### Extensibility #### Current status Each client has a different instance with their models and their business logic. #### Drawbacks - In order to not repeat code, you must know every client models and logic. - Not maintainable. #### Solution Maybe, the best approach is creating a new Django application for every client, these apps will use the core models and specific models, but all models are accesible always. After the last discussion, we will use the signals system in order to inject attrs to the serializers and inject data to the core data retrieved. ### Apps management #### Current status Each client has a specific instance deployed with the apps that needed. #### Solution The idea behind this component is allowing to activate or deactivate some apps (understanding that the business logic is encapsulated under an app). After the last discussion, all features are available for all clients, the startup of these features will be determined via data extracted from the DB for each client. #### Info In Django 2.2, we can do some operations in order to load apps (https://stackoverflow.com/a/57897422). ### User management #### Current status The users are managed by the Django framework. #### Solution The users users will continue to be managed by the Django framework. ### XY integration #### Current status The XY integration is used for some features through the util. #### Solution Maybe, a more elegant solution can be used XY as standalone application. After the last discussion, maybe will be needed an XY refactor to share the geospatial model with Proximity, in this way, the performance will be better because we use the DB directly without using an API. ### Multi-tenancy #### Current status There is not a multi-tenancy system. The Django's "site framework" seems to be used. #### Drawbacks - The "site framework" helps but it doesn't give you the necessary to be a completed multi-tenant system. - Though Django provides some mechanisms in order to use multiple databases (https://docs.djangoproject.com/en/2.2/topics/db/multi-db/), these mechanisms are not linked with the "site framework" but thanks to some ugly hacks we can force the link between sites and multi-databases (https://stackoverflow.com/a/12353583). #### Solution After the last discussion, initially we will deploy multiple instances, it can be very interesting to use global info for the site info and other shared data (geospatial data shared with XY). With the previous approach (using the site framework), there will be problems with the feature load, if this load is determined by the settings is complicated to use because the load is executed at the start and not at runtime. #### Other solutions - Use a third-party package as: - django-tenant-schemas - django-tenants - django-multitenant - Deploy a standalone instance with some apps enabled only. #### Info - https://buildmedia.readthedocs.org/media/pdf/building-multi-tenant-applications-with-django/latest/building-multi-tenant-applications-with-django.pdf #### Examples ```python DATABASES = { 'bk': { 'NAME': 'bk', 'ENGINE': 'django.db.backends.postgresql', 'USER': 'postgres_user', 'PASSWORD': 's3krit' }, 'bmw': { 'NAME': 'bmw', 'ENGINE': 'django.db.backends.postgresql', 'USER': 'postgres_user', 'PASSWORD': 's3krit' }, } class BKRouter: def db_for_read(self, model, **hints): if model._meta.app_label == 'bk': return 'bk' return None def db_for_write(self, model, **hints): if model._meta.app_label == 'bk': return 'bk' return None DATABASE_ROUTERS = ['path.to.BKRouter',] ``` Using multiple databases with site trick: ```python DATABASES = { 'default': { 'NAME': 'default', 'ENGINE': 'django.db.backends.postgresql', 'USER': 'postgres_user', 'PASSWORD': 's3krit' }, 'bmw': { 'NAME': 'bmw', 'ENGINE': 'django.db.backends.postgresql', 'USER': 'postgres_user', 'PASSWORD': 's3krit' }, } def get_current_site(): SITE_ID = getattr(settings, 'SITE_ID', 1) site_name = Site.objects.get(id=SITE_ID) return site_name class BMWRouter(object): def db_for_read(self, model, **hints): site_name = get_current_site() if site_name in ['bmw']: return 'bmw' return 'default' def db_for_write(self, model, **hints): site_name = get_current_site() if site_name in ['bmw']: return 'bmw' return 'default' DATABASE_ROUTERS = ['path.to.BMWRouter',] ``` ### Tasks #### Current status The tasks are managed by a Django app called django-background-tasks. #### Drawbacks - This package has multiple lacks mainly related to the fact that it's not a distributed task queue. #### Solution The tasks management will be managed by Celery. ### Tests #### Current status The tests are developed under the Django test strategy. #### Solution The tests will continue to be managed by the Django's test system, for the e2e tests, we will use a strategy to populate the data in order to test always with "fake-real" data. #### Other solutions - Can be useful to use projects as "Tavern". - Hypothesis.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully