def post(self, current_url, itemurl): useraccount = models.get_current_auth_user(self) tag = self.request.get("tag") media_type = self.request.get("media_type") form = models.ItemForm(data=self.request.POST) location = models.Location.get(self.request.get("location")) created = False item = False if form.is_valid(): item = form.save(commit=False) item.useraccount = useraccount item.location = location item.tag = tag item.media_type = media_type # Handle oembed if (item.media_type == "Video") or (item.media_type == "Image"): item.url = helpers.get_oembed_links(item.text) models.kill_featured_caches() item.put() location.itemcount += 1 location.put() useraccount.itemcount +=1 useraccount.actioncount +=1 useraccount.put() created = True models.kill_location_items_cache(location) userlocation = models.log_userlocation_activity(location, useraccount, False) models.increment_counter("total_items") template_values = { 'created':created, 'itemform':form, 'media_types': helpers.get_media_types(), 'form_tags': helpers.get_form_tags(), 'locations': models.Location.all().order('name'), 'location': location, 'useraccount': useraccount, 'user_action_url': helpers.get_user_action_url(useraccount, current_url), 'ajax_item': self.request.get("item_ajax_submit") } if item: template_values['item'] = item if self.request.get("item_ajax_submit"): viewhelpers.render_template(self, "views/ajaxitem", template_values) else: viewhelpers.render_template(self, "views/item", template_values)
def post(self, current_url, id): useraccount = models.get_current_auth_user(self) location_key = self.request.get('id_location_key') location = models.Location.get(location_key) template_values = { 'useraccount': useraccount, 'location' : location, 'ajax_rating': self.request.get("rating_ajax_submit") } ratingform = models.RatingForm(self.request.POST) if ratingform.is_valid(): rating = ratingform.save(commit=False) rating.location = location rating.useraccount = useraccount rating.put() # create LocationRatings locationrating = None locationrating = models.LocationRatings.gql("WHERE location = :1", location).get() if not locationrating: locationrating = models.LocationRatings() locationrating.location = location if rating.when == "peak": locationrating.peak_count += 1 locationrating.peak_busy_sum += rating.busyness locationrating.peak_easy_sum += rating.how_easy locationrating.peak_step_sum += rating.steps if rating.when == "offpeak": locationrating.offpeak_count += 1 locationrating.offpeak_busy_sum += rating.busyness locationrating.offpeak_easy_sum += rating.how_easy locationrating.offpeak_step_sum += rating.steps if rating.when == "weekend": locationrating.weekend_count += 1 locationrating.weekend_busy_sum += rating.busyness locationrating.weekend_easy_sum += rating.how_easy locationrating.weekend_step_sum += rating.steps locationrating.put() models.increment_counter("total_ratings") models.kill_location_items_cache(location) template_values['ratingform'] = models.RatingForm() template_values['message'] = "Rating Created" template_values['locationrating'] = locationrating template_values['created'] = True else: template_values["error_message"] = "Error occurrred creating rating" template_values["ratingform"] = ratingform template_values["created"] = False if locationrating: template_values['locationrating'] = locationrating if self.request.get("rating_ajax_submit"): viewhelpers.render_template(self, "elements/ratingform", template_values) else: viewhelpers.render_template(self, "views/created", template_values)