Skip to content

Commit

Permalink
First admin moztn#92
Browse files Browse the repository at this point in the history
  • Loading branch information
asmasma21 committed Feb 8, 2015
1 parent 2782fb1 commit 8dbe463
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
25 changes: 15 additions & 10 deletions slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_admin(kwargs):
def first_run():
import first_run
first_run.init()
return redirect(url_for("index"))
return redirect(url_for("admin"))

@app.route('/addCategory', methods=['GET', 'POST'])
@login_required
Expand Down Expand Up @@ -125,8 +125,8 @@ def add_slide():
# status=status,
# message='This slide already exists'
# )


@app.route('/deleteslide', methods=['GET', 'POST'])
@login_required
def delete_slide():
Expand Down Expand Up @@ -169,7 +169,7 @@ def delete_category():
s.category = uc.id
db_session.add(s)
category_controller.delete(category_id)

db_session.commit()


Expand Down Expand Up @@ -236,7 +236,7 @@ def update_category():
try:
category_id = request.form['id']
c = CategoryModel.query.get(category_id)

if c.name == "Uncategorised":
return render_template(
'admin.html',
Expand All @@ -248,7 +248,7 @@ def update_category():
)

c.name = request.form['title']

db_session.add(c)
db_session.commit()
status = True
Expand All @@ -266,7 +266,7 @@ def update_category():
'admin.html',
status = False,
categories = category_controller.list(),
message ="This Categorie already exists ! ")
message ="This Categorie already exists ! ")

# retrives slides for a given category
@app.template_filter('getSlides')
Expand All @@ -288,7 +288,7 @@ def isValidURL(url):
# Check if the branch 'gh-pages' exists
import requests
res = requests.get(url+'/tree/gh-pages')

if(not res.ok):
return "You have to create a 'gh-pages' branch"

Expand All @@ -309,7 +309,7 @@ def admin():
current_app.logger.debug("debug admin")
status = -1
if request.method == 'GET':
login = request.args.get('login')
login = request.args.get('login')
return render_template('admin.html',
categories=category_controller.list(),
login=login)
Expand All @@ -319,7 +319,12 @@ def admin():
categories=category_controller.list(),
status=status
)

@app.route('/registration')
def registration():
return render_template(
'registration.html',
categories=category_controller.list()
)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html')
Expand Down
33 changes: 18 additions & 15 deletions templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">x</button>
<h4>
<span><strong>Ooops !</strong> You must be logged in to access this page ! </span>
<span>
<strong>Ooops !</strong> You must be logged in to access this page !
<p><strong> Not registred yet?</strong> <a href="{{url_for('registration')}}">Join Here!</a></p>
</span>
</h4>
</div>
{% else %}
Expand Down Expand Up @@ -119,24 +122,24 @@ <h1>Administration Panel</h1>
</thead>
<tbody>
{% for c in categories %}

<tr>
<td>{{ c.id }}</td>
<td>{{ c.name }}</td>
<td>{{ c.name }}</td>
<td style="width:80px;">
<button data-toggle-dialog="#" data-toggle="modal" data-target="#updatecategory" title="Update Category" class="btn btn-small btn-warning" type="button"><i class="icon-white icon-edit"></i></button>
<button data-toggle-dialog="#" data-toggle="modal" data-target="#deletecategory" title="Delete Category" class="btn btn-danger btn-small" type="button"><i class="icon-white icon-trash"></i></button>
</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>

</section>


<div class="modal hide fade" id="delteslide" tabindex="-1" role="dialog" aria-labelledby="delteslide">
<form method="POST" action="{{ url_for('delete_slide') }}">
Expand All @@ -147,12 +150,12 @@ <h1>Administration Panel</h1>
<h4 class="modal-title" id="delteslide">Delete a Slide</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to delete :
<strong>
<p>Are you sure you want to delete :
<strong>
<span class="title-container"></span>
</strong>
</p>
<input type="hidden" name="id" />
<input type="hidden" name="id" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
Expand All @@ -175,12 +178,12 @@ <h4 class="modal-title" id="delteslide">Delete a Slide</h4>
<h4 class="modal-title" id="deletecategory">Delete a Category</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to delete :
<strong>
<p>Are you sure you want to delete :
<strong>
<span class="title-container"></span>
</strong>
</p>
<input type="hidden" name="id" />
<input type="hidden" name="id" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
Expand Down Expand Up @@ -257,7 +260,7 @@ <h4 class="modal-title" id="labelupdateslide">Update a Category</h4>
<tr>
<td><label>Name</label></td>
<td><input type="text" name="title" required /></td>
</tr>
</tr>
<input type="hidden" name="id">
</table>
</div>
Expand Down Expand Up @@ -334,7 +337,7 @@ <h4 class="modal-title" id="addcategory">Add new Category</h4>
<tr>
<td><label>Name : </label></td>
<td><input type="text" name="name" required /></td>
</tr>
</tr>
</table>
</div>
<div class="modal-footer">
Expand Down Expand Up @@ -378,7 +381,7 @@ <h4 class="modal-title" id="addcategory">Add new Category</h4>
var columns = e.closest('tr').find('td');
var id = $(columns[0]).text();
var title = $(columns[1]).text();

$('.title-container').html(title);
$('input[name=id]').val(id);
$('input[name=title]').val(title);
Expand Down
3 changes: 3 additions & 0 deletions templates/registration.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends "layout.html" %}
{% block body %}
{% endblock %}

0 comments on commit 8dbe463

Please sign in to comment.