def editSpot(request, spot_key=None): spot = AutoRetry(models.Spot).get(spot_key) user = auth.get_current_user(request) if request.method == 'POST': spot_form = forms.SpotForm(request.POST) constraint_form = forms.SpotConstraintForm(request.POST) # check if spot is changed # check if new constraint to be added if spot_form.is_valid(): for field in spot_form.fields.keys(): setattr(spot,field,spot_form.cleaned_data[field]) spot.author = user AutoRetry(models.Spot).put(spot) if constraint_form.is_valid(): connectConstraintsAndSpot( saveConstraint(constraint_form.cleaned_data), spot.key() ) return HttpResponseRedirect('/traffic_log/spot/%s'%spot.key()) else: return render_to_response('traffic_log/create_edit_spot.html', context(spot=forms.SpotForm(instance=spot), spot_key=spot_key, constraints=spot.constraints, constraint_form=forms.SpotConstraintForm(), edit=True, dow_dict=constants.DOW_DICT, formaction="/traffic_log/spot/edit/%s"%spot.key() ), context_instance=RequestContext(request))
def editSpot(request, spot_key=None): spot = AutoRetry(models.Spot).get(spot_key) user = auth.get_current_user(request) if request.method == 'POST': spot_form = forms.SpotForm(request.POST) constraint_form = forms.SpotConstraintForm(request.POST) # check if spot is changed # check if new constraint to be added if spot_form.is_valid(): for field in spot_form.fields.keys(): setattr(spot, field, spot_form.cleaned_data[field]) spot.author = user AutoRetry(models.Spot).put(spot) if constraint_form.is_valid(): connectConstraintsAndSpot( saveConstraint(constraint_form.cleaned_data), spot.key()) return HttpResponseRedirect('/traffic_log/spot/%s' % spot.key()) else: return render_to_response( 'traffic_log/create_edit_spot.html', context(spot=forms.SpotForm(instance=spot), spot_key=spot_key, constraints=spot.constraints, constraint_form=forms.SpotConstraintForm(), edit=True, dow_dict=constants.DOW_DICT, formaction="/traffic_log/spot/edit/%s" % spot.key()), context_instance=RequestContext(request))
def createEditSpotCopy(request, spot_copy_key=None, spot_key=None): if spot_copy_key: spot_copy = AutoRetry(models.SpotCopy).get(spot_copy_key) spot_key = spot_copy.spot.key( ) # so that dropdown box is selected when editing formaction = reverse('traffic_log.editSpotCopy', args=(spot_copy_key, )) else: if spot_key: formaction = reverse('traffic_log.views.addCopyForSpot', args=(spot_key, )) else: formaction = reverse('traffic_log.createSpotCopy') spot_copy = None user = auth.get_current_user(request) if request.method == 'POST': spot_copy_form = forms.SpotCopyForm(request.POST, { 'author': user, 'spot_key': spot_key }, instance=spot_copy) if spot_copy_form.is_valid(): spot_copy = spot_copy_form.save() old_spot = spot_copy.spot spot_copy.author = user spot_copy.spot = AutoRetry(models.Spot).get( spot_copy_form['spot_key'].data) # Add spot copy to spot's list of shuffled spot copies. spot_copy.spot.add_spot_copy(spot_copy) AutoRetry(spot_copy).put() if old_spot: # just in case this copy was moved from one spot # to another, bust the old cache of spot copies # See Issue 124 old_spot.shuffle_spot_copies() AutoRetry(old_spot).save() return HttpResponseRedirect(reverse('traffic_log.listSpots')) else: spot_copy_form = forms.SpotCopyForm(initial={'spot_key': spot_key}, instance=spot_copy) return render_to_response('traffic_log/create_edit_spot_copy.html', context(spot_copy=spot_copy_form, formaction=formaction), context_instance=RequestContext(request))
def createEditSpotCopy(request, spot_copy_key=None, spot_key=None): if spot_copy_key: spot_copy = AutoRetry(models.SpotCopy).get(spot_copy_key) spot_key = spot_copy.spot.key() # so that dropdown box is selected when editing formaction = reverse('traffic_log.editSpotCopy', args=(spot_copy_key,)) else: if spot_key: formaction = reverse('traffic_log.views.addCopyForSpot', args=(spot_key,)) else: formaction = reverse('traffic_log.createSpotCopy') spot_copy = None user = auth.get_current_user(request) if request.method == 'POST': spot_copy_form = forms.SpotCopyForm(request.POST, { 'author':user, 'spot_key':spot_key }, instance=spot_copy) if spot_copy_form.is_valid(): spot_copy = spot_copy_form.save() old_spot = spot_copy.spot spot_copy.author = user spot_copy.spot = AutoRetry(models.Spot).get(spot_copy_form['spot_key'].data) # Add spot copy to spot's list of shuffled spot copies. spot_copy.spot.add_spot_copy(spot_copy) AutoRetry(spot_copy).put() if old_spot: # just in case this copy was moved from one spot # to another, bust the old cache of spot copies # See Issue 124 old_spot.shuffle_spot_copies() AutoRetry(old_spot).save() return HttpResponseRedirect(reverse('traffic_log.listSpots')) else: spot_copy_form = forms.SpotCopyForm(initial={'spot_key':spot_key}, instance=spot_copy) return render_to_response('traffic_log/create_edit_spot_copy.html', context(spot_copy=spot_copy_form, formaction=formaction ), context_instance=RequestContext(request))