Permalink
Browse files

Moving about.html to ./templates and being more explicit on the templ…

…ate name for the generic views. Also added new mappers like bulk export and delete.
  • Loading branch information...
1 parent 65011c2 commit e72ba2739b08b2713bccbe63d206eea5a57f7fa9 @ibolmo committed May 29, 2009
Showing with 36 additions and 17 deletions.
  1. +2 −1 .gitignore
  2. +1 −0 app.yaml
  3. +0 −7 myapp/templates/admin_created.html
  4. +4 −4 myapp/views.py
  5. 0 {myapp → }/templates/about.html
  6. +29 −5 util.py
View
@@ -1,3 +1,4 @@
*.pyc
config.py
-docs/calendar.md
+docs/calendar.md
+*.csv
View
@@ -38,6 +38,7 @@ skip_files: |
(.*\.py[co])|
(.*/RCS/.*)|
(\..*)|
+ (.*\.csv)|
(dev/.*)|
(test/.*)|
(docs/.*)|
@@ -1,7 +0,0 @@
-{% extends 'base.html' %}
-{% block title %}Admin created{% endblock %}
-
-{% block content %}
-<h2>Admin created</h2>
-<p>You've created an admin user with the username and password "admin". Let's have a look at the <a href="/admin/">admin interface</a>, now!</p>
-{% endblock %}
View
@@ -13,11 +13,11 @@
@login_required
def list_campaigns(request):
- return object_list(request, Campaign.all().filter('organizer =', request.user.key()), paginate_by = 10)
+ return object_list(request, Campaign.all().filter('organizer =', request.user.key()), paginate_by = 10, template_name = 'campaign_list.html')
@login_required
def show_campaign(request, key):
- return object_detail(request, Campaign.all().filter('organizer =', request.user), key)
+ return object_detail(request, Campaign.all().filter('organizer =', request.user), key, template_name = 'campaign_detail.html')
@login_required
def add_campaign(request):
@@ -34,11 +34,11 @@ def add_campaign(request):
@login_required
def edit_campaign(request, key):
- return update_object(request, object_id = key, form_class = CampaignForm)
+ return update_object(request, object_id = key, form_class = CampaignForm, template_name = 'campaign_form.html')
@login_required
def delete_campaign(request, key):
- return delete_object(request, Campaign, object_id = key, post_delete_redirect = reverse('myapp.views.list_campaigns'))
+ return delete_object(request, Campaign, object_id = key, post_delete_redirect = reverse('myapp.views.list_campaigns'), template_name = 'campaign_confirm_delete.html')
def clean_up_campaigns(request):
status = 200
File renamed without changes.
View
@@ -69,11 +69,11 @@ def get_replacement(value):
entity[key] = [isinstance(item, (datetime.datetime, datetime.date, datetime.time, datastore_types.Key, users.User)) and get_replacement(item) or item for item in values]
else:
entity[key] = isinstance(value, (datetime.datetime, datetime.date, datetime.time, datastore_types.Key, users.User)) and get_replacement(value) or value
-
+
class Mapper(object):
# Subclasses should replace this with a model class (eg, model.Person).
KIND = None
-
+
# Subclasses can replace this with a list of (property, value) tuples to filter by.
FILTERS = []
@@ -83,15 +83,15 @@ def map(self, entity):
Implementers should return a tuple containing two iterables (to_update, to_delete).
"""
return ([], [])
-
+
def get_query(self):
"""Returns a query over the specified kind, with any appropriate filters applied."""
q = self.KIND.all()
for prop, value in self.FILTERS:
q.filter("%s =" % prop, value)
q.order("__key__")
return q
-
+
def run(self, batch_size=100):
"""Executes the map procedure over all matching entities."""
q = self.get_query()
@@ -110,7 +110,7 @@ def run(self, batch_size=100):
q = self.get_query()
q.filter("__key__ >", entities[-1].key())
entities = q.fetch(batch_size)
-
+
class FixNamespace(Mapper):
def __init__(self, kind, filters = None):
self.KIND = kind
@@ -123,4 +123,28 @@ def map(self, entity):
entity.namespace = entity.namespace.strip('/').replace('/', '.')
return ([entity], [])
return ([], [])
+
+import csv
+
+class Export(Mapper):
+ def __init__(self, filename, kind, attrs, filters = None):
+ self.KIND = kind
+ if filters:
+ self.FILTERS = filters
+ self.ATTRS = attrs
+ self.writer = csv.writer(open(filename, 'w'))
+ self.writer.writerow(self.ATTRS)
+
+ def map(self, entity):
+ self.writer.writerow([getattr(entity, attr) for attr in self.ATTRS])
+ return ([], [])
+
+class Delete(Mapper):
+ def __init__(self, kind, filters = None):
+ self.KIND = kind
+ if filters:
+ self.FILTERS = filters
+
+ def map(self, entity):
+ return ([], [entity])

0 comments on commit e72ba27

Please sign in to comment.