Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from weppy import App, session, now
- from weppy.orm import Model, Field, belongs_to, has_many, Database
- from weppy.tools import Auth
- from weppy.tools.auth import AuthUser
- class User(AuthUser):
- has_many('posts', 'comments')
- class Post(Model):
- belongs_to('user')
- has_many('comments')
- title = Field()
- text = Field.text()
- date = Field.datetime()
- default_values = {
- 'user': lambda: session.auth.user_id,
- 'date': lambda: now
- }
- validation = {
- 'title': {'presence': True},
- 'text': {'presence': True}
- }
- fields_rw = {
- 'user': False,
- 'date': False
- }
- class Comment(Model):
- belonds_to('user', 'post')
- text = Field.text()
- date = Field.datetime()
- default_values = {
- 'user': lambda: session.auth.user_id,
- 'date': lambda: now
- }
- validation = {
- 'text': {'presence': True}
- }
- field_rw = {
- 'user': False,
- 'post': False,
- 'date': False
- }
- app = App(__name__)
- app.config.auth.single_template = True
- app.config.auth.registration_verification = True
- app.config.auth.hmac_key = "MassiveDynamicRules"
- db = Database(app, auto_migrate=True)
- auth = Auth(app, db, user_model=User)
- db.define_models(Post, Comment)
- @app.command('setup')
- def setup():
- user = User.create(
- email="walter@massivedynamics.com",
- first_name="Walter",
- last_name="Bishop",
- password="pocketuniverse"
- )
- admins = auth.create_group("admin")
- auth.add_membership(admins, user.id)
- db.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement