Skip to content

Commit

Permalink
Merge pull request #1591 from rafalkowalski/dev
Browse files Browse the repository at this point in the history
adding pages fixed
  • Loading branch information
niranjan94 authored Jul 13, 2016
2 parents 02f1b64 + c98f3ff commit 0570539
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 38 deletions.
35 changes: 35 additions & 0 deletions migrations/versions/047f7c3db184_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""empty message
Revision ID: 047f7c3db184
Revises: dd24d9e90809
Create Date: 2016-07-12 11:28:08.051094
"""

# revision identifiers, used by Alembic.
revision = '047f7c3db184'
down_revision = 'dd24d9e90809'

from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils
from sqlalchemy.dialects import postgresql

def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('pages',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('title', sa.String(), nullable=True),
sa.Column('url', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.Column('place', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('pages')
### end Alembic commands ###
15 changes: 15 additions & 0 deletions open_event/helpers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from ..models.user import User, ORGANIZER
from ..models.user_detail import UserDetail
from ..models.users_events_roles import UsersEventsRoles
from ..models.page import Page


class DataManager(object):
Expand Down Expand Up @@ -1343,6 +1344,20 @@ def update_user_event_role(form, uer):
save_to_db(uer, "Event saved")
record_activity('update_role', role=role, user=user, event_id=uer.event_id)

@staticmethod
def create_page(form):

page = Page(name=form.get('name', ''), title=form.get('title', ''), description=form.get('description', ''),
url=form.get('url', ''), place=form.get('place', ''))
save_to_db(page, "Page created")

def update_page(self, page, form):
page.name = form.get('name', '')
page.title = form.get('title', '')
page.description = form.get('description', '')
page.url = form.get('url', '')
page.place = form.get('place', '')
save_to_db(page, "Page updated")

def save_to_db(item, msg="Saved to db", print_error=True):
"""Convenience function to wrap a proper DB save
Expand Down
10 changes: 10 additions & 0 deletions open_event/helpers/data_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from ..models.mail import Mail
from ..models.activity import Activity
from ..models.setting import Setting
from ..models.page import Page
from .language_list import LANGUAGE_LIST
from .static import EVENT_TOPICS, EVENT_LICENCES
from open_event.helpers.helpers import get_event_id
Expand Down Expand Up @@ -580,3 +581,12 @@ def get_upcoming_events(event_id):
.filter(Event.start_time >= datetime.datetime.now()).filter(Event.end_time >= datetime.datetime.now()) \
.filter(Event.in_trash == False)

@staticmethod
def get_all_pages():
return Page.query.all()

@staticmethod
def get_page_by_id(page_id):
return Page.query.get(page_id)


40 changes: 40 additions & 0 deletions open_event/models/page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Copyright 2016 Rafal Kowalski"""
from . import db


class Page(db.Model):
"""Page model class"""
__tablename__ = 'pages'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False)
title = db.Column(db.String)
url = db.Column(db.String, nullable=False)
description = db.Column(db.String)
place = db.Column(db.String)
def __init__(self, name=None,title=None, description=None, url=None, place=None):
self.name = name
self.description = description
self.title = title
self.url = url
self.place = place

def __repr__(self):
return '<Page %r>' % self.name

def __str__(self):
return unicode(self).encode('utf-8')

def __unicode__(self):
return self.name

@property
def serialize(self):
"""Return object data in easily serializeable format"""
return {
'id': self.id,
'name': self.name,
'description': self.description,
'title': self.title,
'url': self.url,
'place': self.place
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<form class="admin-form form-horizontal" action="/admin/pages/create" method="POST">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Page Details</h4>
</div>
<div class="modal-body">

<div class="item form-group">
<label>NAME</label>
<input type="text" class="form-control col-md-7 col-xs-12" name="name"/>
</div>
<div class="item form-group">
<label>TITLE</label>
<input type="text" class="form-control col-md-7 col-xs-12" name="title"/>
</div>
<div class="item form-group">
<label>URL</label>
<input type="text" class="form-control col-md-7 col-xs-12" name="url"/>
</div>
<div class="item form-group">
<label>DESCRIPTION</label>
<textarea type="text" class="form-control col-md-7 col-xs-12" name="description"> </textarea>
</div>
<div class="item form-group">
<label>PLACE</label>
<select type="text" class="form-control col-md-7 col-xs-12" name="place">
<option value="use_open_event">Use Open Event</option>
<option value="footer_menu">Footer Menu</option>
</select>
</div>


<br>
<span id="import_status"></span>
<span id="import_error" class="red"></span>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" id="btnImportEvent" onclick="">Create Page</button>
</div>
</div>
</div>
</form>
</div>

<script>


</script>
83 changes: 47 additions & 36 deletions open_event/templates/gentelella/admin/super_admin/pages/pages.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,54 @@

{% block content %}

<div class="row">
<div class="col-md-4">
<h3 class="pull-left">Pages</h3>
<button class="btn btn-info pull-right" style="color: #FFFFFF; margin: 0;" data-toggle="modal" data-target="#add-role">Create Page</button><div style="clear:both"></div>
<ul class="list-group">
<li class="list-group-item">/how_it_works</li>
<li class="list-group-item">/pricing</li>
<li class="list-group-item">/mobile_apps</li>
<li class="list-group-item">/sitemaps</li>
<li class="list-group-item active">/about</li>
</ul>
<div class="row">
<div class="col-md-4">
<h3 class="pull-left">Pages</h3>
<button class="btn btn-info pull-right" style="color: #FFFFFF; margin: 0;" data-toggle="modal" data-target="#importModal">Create Page</button><div style="clear:both"></div>
<ul class="list-group">
{% for page in pages %}
<li class="list-group-item {{ 'active' if current_page.id==page.id else '' }}"><a href="/admin/pages/{{page.id}}" {{'style=color:white' if current_page.id==page.id else '' }}>{{page.url}} </a>
<a {{'style=color:white' if current_page.id==page.id else '' }} class="pull-right"
data-toggle="tooltip" data-placement="top"
onclick="return confirm('Are you sure you want to delete this record?');"
href="{{ get_url('sadmin_pages.trash_view', page_id=page.id) }}" title="Delete record">
<i class="glyphicon glyphicon-trash"></i>
</a></li>
{% endfor %}
</ul>
</div>
<div class="col-md-8">
{% if current_page %}
<form class="admin-form form-horizontal" action="/admin/pages/{{current_page.id}}" method="POST">
<div class="item form-group">
<label>NAME</label>
<input type="text" class="form-control col-md-7 col-xs-12" name="name" value="{{current_page.name}}"/>
</div>
<div class="item form-group">
<label>TITLE</label>
<input type="text" class="form-control col-md-7 col-xs-12" name="title" value="{{current_page.title}}"/>
</div>
<div class="item form-group">
<label>URL</label>
<input type="text" class="form-control col-md-7 col-xs-12" name="url" value="{{current_page.url}}"/>
</div>
<div class="item form-group">
<label>DESCRIPTION</label>
<textarea type="text" class="form-control col-md-7 col-xs-12" name="description">{{current_page.description}}</textarea>
</div>
<div class="item form-group">
<label>PLACE</label>
<select type="text" class="form-control col-md-7 col-xs-12" name="place" value="{{current_page.place}}">
<option value="use_open_event">Use Open Event</option>
<option value="footer_menu">Footer Menu</option>
</select>
</div>
<button class="btn btn-success">Update</button>
</form>
{% endif %}
</div>
</div>
<div class="col-md-8">
<form class="admin-form form-horizontal">
<div class="item form-group">
<label>TITLE</label>
<input type="text" class="form-control col-md-7 col-xs-12"/>
</div>
<div class="item form-group">
<label>URL</label>
<input type="text" class="form-control col-md-7 col-xs-12"/>
</div>
<div class="item form-group">
<label>DESCRIPTION</label>
<textarea type="text" class="form-control col-md-7 col-xs-12"> </textarea>
</div>
<div class="item form-group">
<label>PLACE</label>
<select type="text" class="form-control col-md-7 col-xs-12">
<option>Use Open Event</option>
<option>Footer Menu</option>
</select>
</div>

</form>
</div>
</div>
{% include 'gentelella/admin/super_admin/pages/_create_page_modal.html' %}
{% endblock %}

{% block tail_js %}
Expand Down
30 changes: 28 additions & 2 deletions open_event/views/admin/super_admin/pages.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
from flask import redirect, request, url_for
from flask_admin import expose
from open_event.views.admin.super_admin.super_admin_base import SuperAdminBaseView

from ....helpers.data_getter import DataGetter
from ....helpers.data import DataManager, delete_from_db

class SuperAdminPagesView(SuperAdminBaseView):
@expose('/')
def index_view(self):
return self.render('/gentelella/admin/super_admin/pages/pages.html')
pages = DataGetter.get_all_pages()
return self.render('/gentelella/admin/super_admin/pages/pages.html', pages=pages)

@expose('/create', methods=['POST'])
def create_view(self):
DataManager.create_page(request.form)
return redirect(url_for('sadmin_pages.index_view'))

@expose('/<page_id>', methods=['GET', 'POST'])
def details_view(self, page_id):
page = DataGetter.get_page_by_id(page_id)
if request.method == 'POST':
print request.form
DataManager().update_page(page, request.form)
return redirect(url_for('sadmin_pages.details_view', page_id=page_id ))
pages = DataGetter.get_all_pages()
return self.render('/gentelella/admin/super_admin/pages/pages.html',
pages=pages,
current_page=page)

@expose('/<page_id>/trash', methods=['GET'])
def trash_view(self, page_id):
page = DataGetter.get_page_by_id(page_id)
delete_from_db(page, "Page has already deleted")
return redirect(url_for('sadmin_pages.index_view'))

0 comments on commit 0570539

Please sign in to comment.