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

Umstrukturierung - HTTP Konfiguration sauber trennen #14

Open
schlamar opened this issue Nov 21, 2017 · 0 comments
Open

Umstrukturierung - HTTP Konfiguration sauber trennen #14

schlamar opened this issue Nov 21, 2017 · 0 comments

Comments

@schlamar
Copy link

Hier ein Vorschlag, wie ich mir so eine saubere Trennung zwischen der HTTP Konfiguration und dem restlichen Code vorstellen könnte (s. #13).

- channels
- ...
- website
  - static
  - templates
  __init__.py

Die Flask Sachen würde ich dann nur in website/__init__.py machen. So als Beispiel:

class Website:
    ...

    def register_url(self):
        self.app.add_url_rule('/',
                              view_func=self.index)
        self.app.add_url_rule('/api/system',
                              view_func=self.sysinfo_api)

    def index(self):
        return render_template('index.html')

    def sysinfo_api(self):
        return jsonify(sysinfo.get())  # --> Funktion ausgelagert


class ChannelsApi:

    def __init__(self, wlanthermo):
        ...
        self.channels = channels.Channels()  # --> vorhandene Klasse ohne Flask Konfiguration

    def register_api(self):
        self.app.add_url_rule('/api/colors',
                              view_func=self.channels.get_colors_api)
        self.app.add_url_rule('/api/channels/<int:module_id>/<int:channel_id>',
                              methods=['POST'],
                              view_func=self.channels.register_channel_api)
        self.app.add_url_rule('/api/channels/<int:module_id>/<int:channel_id>',
                              view_func=self.channels.get_channels_api)
        self.app.add_url_rule('/api/channels/<int:module_id>',
                              view_func=self.channels.get_channels_api)
        ...

Manche Sachen fände ich noch als Modul eleganter (z.B. settings.py anstatt settings/__init__.py), aber das ist Geschmackssache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant