예제 #1
0
 def create(self, request):
     """
         CREATES A NEW SUGGESTION
     """
     form = SuggestionForm(request.POST)
     if form.is_valid():
         suggestion = self._create_or_update(request, form)
         return self._render(
                     request = request,
                     context = {
                                'suggestion': suggestion,
                                },
                     status = 200)
     return self._badrequest(request, {'msg': 'invalid id'})
예제 #2
0
 def update(self, request, id):
     """
         UPDATE A EXISTING SUGGESTION
     """
     try:
         suggestion = Suggestion.objects.get(pk=id, user=request.user)
     except Suggestion.DoesNotExist:
         return self._notfound(request)
     form = SuggestionForm(request.POST, instance=suggestion)
     if form.is_valid():
         suggestion = self._create_or_update(request, form)
         return self._render(
                             request = request,
                             context = {
                                        'suggestion': suggestion,
                                        },
                             status = 200)
     return self._badrequest(request, {'msg': 'invalid id'})
예제 #3
0
def api_suggestion_add(request, name, description, place):
    place_obj = None
    if type(place) == type(0):
        place_obj = Place.objects.filter(pk=place)
    if place_obj is None:
        place_obj = Place.objects.create_from_google(
                                 google_places_reference = place,
                                 user = request.user
                                 )
        
    data = {
            'name': name,
            'description': description,
            'visibility': 'public',
            }
    form = SuggestionForm(data)
    if form.is_valid():
        suggestion = form.save(user=request.user, place=place_obj)
        return Suggestion.serialize_to_json([suggestion])
    return form.errors
예제 #4
0
 def update(self, request, id=None, slug=None):
     """
         UPDATE A EXISTING SUGGESTION
     """
     try:
         if id:
             suggestion = Suggestion.objects.get(pk=id, user=request.user)
         else:
             suggestion = Suggestion.objects.get(slug=slug.lower(), user=request.user)
     except Suggestion.DoesNotExist:
         return self._notfound(request)
     form = SuggestionForm(request.POST, instance=suggestion)
     if form.is_valid():
         suggestion = self._create_or_update(request, form)
         return self._render(
                             request = request,
                             template = 'events/suggestion_detail',
                             context = {
                                        'suggestion': suggestion,
                                        },
                             status = 200)
     return self._badrequest(request, {'msg': 'invalid id'})