commit b5caa4bf2c0e525bc021555523af8e76b5bff892
parent 86e6f424a17825a0fc819fab653c90b43a3a0064
Author: Friedel Schön <[email protected]>
Date: Fri, 15 Apr 2022 20:23:45 +0200
fucking circular imports
Diffstat:
10 files changed, 55 insertions(+), 60 deletions(-)
diff --git a/insert.py b/insert.py
@@ -1,4 +0,0 @@
-from pgmles import bcrypt, db, models
-
-db.session.add(models.User(type='admin', username='admin', email='[email protected]',
- password=bcrypt.generate_password_hash('password').decode('utf-8')))
diff --git a/pgmles/__init__.py b/pgmles/__init__.py
@@ -1,18 +0,0 @@
-from flask import Flask
-from flask_bcrypt import Bcrypt
-from flask_login import LoginManager
-from flask_sqlalchemy import SQLAlchemy
-
-from .flaskcalendar import Calendar
-
-app = Flask(__name__)
-app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245'
-app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
-db = SQLAlchemy(app)
-bcrypt = Bcrypt(app)
-login_manager = LoginManager(app)
-login_manager.login_view = 'login'
-login_manager.login_message_category = 'info'
-calendar = Calendar()
-
-from pgmles import routes
diff --git a/pgmles/coursecalendar.py b/pgmles/coursecalendar.py
@@ -0,0 +1,32 @@
+import random
+from calendar import Calendar as Month
+from datetime import datetime
+
+lesson_names = [ 'Python', 'C', 'C++', 'Java', 'JavaScript', None, None, None, None, None, None, None, None ]
+
+lessons = [ None ] * 31
+
+
+class Calendar:
+ weekdays = enumerate(['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo'])
+ nextlesson = ''
+ rows = []
+
+ def __init__(self):
+ today = datetime.today()
+
+ m = Month()
+
+ for day in m.itermonthdays(today.year, today.month):
+ if day != 0:
+ lessons[day] = random.choice(lesson_names)
+
+ for day, lesson in enumerate(lessons[today.day:]):
+ if lesson is not None:
+ self.nextlesson = lesson
+ break
+
+ for days in m.monthdayscalendar(today.year, today.month):
+ self.rows.append([(i, d, lessons[d]) for i, d in enumerate(days)])
+
+# print(self.rows)
diff --git a/pgmles/flaskcalendar.py b/pgmles/flaskcalendar.py
@@ -1,32 +0,0 @@
-import random
-from calendar import Calendar as Month
-from datetime import datetime
-
-lesson_names = [ 'Python', 'C', 'C++', 'Java', 'JavaScript', None, None, None, None, None, None, None, None ]
-
-lessons = [ None ] * 31
-
-
-class Calendar:
- weekdays = list(enumerate(['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo']))
- nextlesson = ''
- rows = []
-
- def __init__(self):
- today = datetime.today()
-
- m = Month()
-
- for day in m.itermonthdays(today.year, today.month):
- if day != 0:
- lessons[day] = random.choice(lesson_names)
-
- for day, lesson in enumerate(lessons[today.day:]):
- if lesson is not None:
- self.nextlesson = lesson
- break
-
- for days in m.monthdayscalendar(today.year, today.month):
- self.rows.append([(i, d, lessons[d]) for i, d in enumerate(days)])
-
-# print(self.rows)
diff --git a/pgmles/forms.py b/pgmles/forms.py
@@ -6,7 +6,6 @@ from wtforms.validators import DataRequired, Email, EqualTo, Length, ValidationE
from .models import User
-
class RegistrationForm(FlaskForm):
username = StringField('Username', validators=[ DataRequired(), Length(min=2, max=20) ])
email = StringField('Email', validators=[ DataRequired(), Email() ])
diff --git a/pgmles/models.py b/pgmles/models.py
@@ -1,9 +1,9 @@
from datetime import datetime
from flask_login import UserMixin
+from flask_sqlalchemy import SQLAlchemy
-from . import db, login_manager
-
+from .server import db, login_manager
@login_manager.user_loader
def load_user(user_id):
diff --git a/pgmles/routes.py b/pgmles/routes.py
@@ -5,7 +5,7 @@ from flask import flash, redirect, render_template, request, url_for
from flask_login import current_user, login_required, login_user, logout_user
from PIL import Image
-from . import app, bcrypt, calendar, db
+from .server import app, bcrypt, calendar, db
from .forms import LoginForm, NewCourseForm, RegistrationForm, SubscribeForm, UnsubscribeForm, UpdateAccountForm
from .models import Course, CourseMember, User
diff --git a/pgmles/server.py b/pgmles/server.py
@@ -0,0 +1,18 @@
+from flask import Flask
+from flask_bcrypt import Bcrypt
+from flask_login import LoginManager
+from flask_sqlalchemy import SQLAlchemy
+
+app = Flask(__name__)
+app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245'
+app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
+db = SQLAlchemy(app)
+bcrypt = Bcrypt(app)
+login_manager = LoginManager(app)
+login_manager.login_view = 'login'
+login_manager.login_message_category = 'info'
+
+from .coursecalendar import Calendar
+calendar = Calendar()
+
+from .routes import *
diff --git a/readme.md b/readme.md
@@ -1,3 +1,3 @@
-```pip3 install flask wtforms flask_sqlalchemy flask-wtf email_validator flask-bcrypt flask-login Pillow```
+```pip3 install flask wtforms flask_sqlalchemy flask-wtf email_validator flask-bcrypt flask-login pillow```
```python3 run.py```
\ No newline at end of file
diff --git a/run.py b/run.py
@@ -1,4 +1,4 @@
-from pgmles import app
+from pgmles.server import app
if __name__ == '__main__':
app.run(debug=True)