Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
adding rocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kwinkunks committed Jun 17, 2014
1 parent 0183a5a commit 4088243
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 47 deletions.
90 changes: 47 additions & 43 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
rock.name = i['name']
rock.group = 'public'

rock.description = i['description']

rock.vp = float(i['vp'])
rock.vs = float(i['vs'])
rock.rho = float(i['rho'])
Expand Down Expand Up @@ -385,48 +387,7 @@ class AddRockHandler(ModelrPageRequest):
'''
add a rock
'''
def post(self):

user = self.verify()
if user is None:
self.redirect('/signup')

name = self.request.get('name')

rocks = Rock.all()
rocks.ancestor(user)
rocks.filter("user =", user.user_id)
rocks.filter("name =", name)
rocks = rocks.fetch(1)

# Rewrite if the rock exists
if rocks:
rock = rocks[0]
else:
rock = Rock(parent=user)
rock.user = user.user_id

# Populate the object
rock.vp = float(self.request.get('vp'))
rock.vs = float(self.request.get('vs'))
rock.rho = float(self.request.get('rho'))

rock.vp_std = float(self.request.get('vp_std'))
rock.vs_std = float(self.request.get('vs_std'))
rock.rho_std = float(self.request.get('rho_std'))

rock.name = self.request.get('name')
rock.group = self.request.get('group')

# Save in the database
rock.put()

activity = "added_rock"
ActivityLog(user_id=user.user_id,
activity=activity,
parent=ModelrRoot).put()
self.redirect('/dashboard#rocks')

pass

class RemoveRockHandler(ModelrPageRequest):

Expand Down Expand Up @@ -660,6 +621,50 @@ def get(self):
parent=ModelrRoot).put()
self.response.out.write(html)

def post(self):

user = self.verify()
if user is None:
self.redirect('/signup')

name = self.request.get('name')

rocks = Rock.all()
rocks.ancestor(user)
rocks.filter("user =", user.user_id)
rocks.filter("name =", name)
rocks = rocks.fetch(1)

# Rewrite if the rock exists
if rocks:
rock = rocks[0]
else:
rock = Rock(parent=user)
rock.user = user.user_id

# Populate the object
rock.vp = float(self.request.get('vp'))
rock.vs = float(self.request.get('vs'))
rock.rho = float(self.request.get('rho'))

rock.vp_std = float(self.request.get('vp_std'))
rock.vs_std = float(self.request.get('vs_std'))
rock.rho_std = float(self.request.get('rho_std'))

rock.description = self.request.get('description')
rock.name = self.request.get('name')
rock.group = self.request.get('group')

# Save in the database
rock.put()

activity = "added_rock"
ActivityLog(user_id=user.user_id,
activity=activity,
parent=ModelrRoot).put()
self.redirect('/dashboard#rocks')



class AboutHandler(ModelrPageRequest):
def get(self):
Expand Down Expand Up @@ -2134,7 +2139,6 @@ def post(self):

app = webapp2.WSGIApplication([('/', MainHandler),
('/dashboard', DashboardHandler),
('/add_rock', AddRockHandler),
('/edit_rock', ModifyRockHandler),
('/remove_rock', RemoveRockHandler),
('/scenario', ScenarioHandler),
Expand Down
23 changes: 19 additions & 4 deletions templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ <h2>My rocks</h2>
</thead>
<tbody>
{% for rock in rocks %}

{% set slug = rock.name | replace(' ','-') %}

<tr>
<form class="form-horizontal" name="input" action="edit_rock" method="post">
<input type="hidden" name="name" value="{{rock.name}}" />
<td><strong>{{rock.name}}</strong></td>
<td><strong>{{ rock.name }}</strong><span style="color:#bbb; font-size:100%; vertical-align:middle; left:6px; top:-2px;" class="glyphicon glyphicon-info-sign" id="rock_desc_{{ slug }}" data-container="body" data-toggle="popover" data-placement="right" data-content="{{ rock.description }}"></td>
<td>{{rock.vp}}</td>
<td>{{rock.vs}}</td>
<td>{{rock.rho}}</td>
Expand All @@ -128,10 +131,22 @@ <h2>My rocks</h2>
<td><input class="btn btn-success btn-xs" type="submit" name="action" value="edit">&nbsp;&nbsp;&nbsp;&nbsp;<input class="btn btn-danger btn-xs" type="submit" formaction="/remove_rock" method="post" value="remove" /></td>
</form>
</tr>

<script>
$('#rock_desc_{{ slug }}').popover({
trigger: 'hover click',
html: true,
placement: 'right',
container: 'body',
delay: { show: 500, hide: 1000 }
});
</script>

{% endfor %}
</tbody>
</table>


<!-- ------ Shared rocks, if any ------- -->
{% for rock_group in rock_groups %}
<div class="panel panel-default">
Expand Down Expand Up @@ -216,13 +231,13 @@ <h3 class="panel-title"><a class="accordion-toggle" data-toggle="collapse" data-
<h3 class="panel-title">Add rock</h3>
</div>
<div class="panel-body">
<form class="form-horizontal" role="form" name="input" action="add_rock" method="post">
<form class="form-horizontal" role="form" name="input" method="post">

<div class="row"> <!-- NAME -->
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-9">
<input class="form-control" type="text" name="name" value={{current_rock.name}} />
<input class="form-control" type="text" name="name" value="{{current_rock.name}}" />
</div>
</div>
</div> <!-- /row -->
Expand All @@ -231,7 +246,7 @@ <h3 class="panel-title">Add rock</h3>
<div class="form-group">
<label for="description" class="col-sm-2 control-label">Description</label>
<div class="col-sm-9">
<textarea class="form-control" name="description" value={{current_rock.description}}></textarea>
<textarea class="form-control" rows="2" name="description">{{ current_rock.description }}</textarea>
</div>
</div>
</div> <!-- /row -->
Expand Down

0 comments on commit 4088243

Please sign in to comment.