Author: gregoryjnewman
Date: Sat Oct  4 05:52:35 2008
New Revision: 1004

Modified:
    trunk/apps/core_apps/photos/forms.py
    trunk/apps/core_apps/photos/urls.py
    trunk/apps/core_apps/photos/views.py
    trunk/projects/complete_project/templates/photos/photo_right_panel.html

Log:
adding edit form for photos

Modified: trunk/apps/core_apps/photos/forms.py
==============================================================================
--- trunk/apps/core_apps/photos/forms.py        (original)
+++ trunk/apps/core_apps/photos/forms.py        Sat Oct  4 05:52:35 2008
@@ -12,4 +12,14 @@

      def __init__(self, user=None, *args, **kwargs):
          self.user = user
-        super(PhotoUploadForm, self).__init__(*args, **kwargs)
\ No newline at end of file
+        super(PhotoUploadForm, self).__init__(*args, **kwargs)
+
+class PhotoEditForm(forms.ModelForm):
+
+    class Meta:
+        model = Photos
+        exclude =  
('member','photoset','title_slug','effect','crop_from','image')
+
+    def __init__(self, user=None, *args, **kwargs):
+        self.user = user
+        super(PhotoEditForm, self).__init__(*args, **kwargs)
\ No newline at end of file

Modified: trunk/apps/core_apps/photos/urls.py
==============================================================================
--- trunk/apps/core_apps/photos/urls.py (original)
+++ trunk/apps/core_apps/photos/urls.py Sat Oct  4 05:52:35 2008
@@ -17,4 +17,6 @@
      url(r'^member/(?P<username>[\w]+)/$', 'photos.views.memberphotos',  
name='photos_member'),
      #destory photo
      url(r'^destroy/(\d+)/$', 'photos.views.destroy', name='photo_destroy'),
+    #edit photo
+    url(r'^edit/(\d+)/$', 'photos.views.edit', name='photo_edit'),
  )

Modified: trunk/apps/core_apps/photos/views.py
==============================================================================
--- trunk/apps/core_apps/photos/views.py        (original)
+++ trunk/apps/core_apps/photos/views.py        Sat Oct  4 05:52:35 2008
@@ -165,6 +165,33 @@
      return render_to_response("photos/memberphotos.html", {"photos":  
photos}, context_instance=RequestContext(request))

  @login_required
+def edit(request, id):
+    photo = get_object_or_404(Photos, id=id)
+
+    if request.method == "POST":
+        if photo.member != request.user:
+            request.user.message_set.create(message="You can't edit photos  
that aren't yours")
+            return HttpResponseRedirect(reverse('details',  
args=(photo.id,)))
+        if request.POST["action"] == "update":
+            photo_form = PhotoEditForm(request.user, request.POST,  
instance=photo)
+            if photo_form.is_valid():
+                photoobj = photo_form.save(commit=False)
+                photoobj.save()
+                request.user.message_set.create(message=_("Successfully  
updated photo '%s'") % photo.title)
+
+                return HttpResponseRedirect(reverse('details',  
args=(photo.id,)))
+        else:
+            photo_form = PhotoEditForm(instance=photo)
+
+    else:
+        photo_form = PhotoEditForm(instance=photo)
+
+    return render_to_response("photos/edit.html", {
+        "photo_form": photo_form,
+        "photo": photo,
+    }, context_instance=RequestContext(request))
+
[EMAIL PROTECTED]
  def destroy(request, id):
      photo = Photos.objects.get(pk=id)
      user = request.user

Modified:  
trunk/projects/complete_project/templates/photos/photo_right_panel.html
==============================================================================
--- trunk/projects/complete_project/templates/photos/photo_right_panel.html     
 
(original)
+++ trunk/projects/complete_project/templates/photos/photo_right_panel.html     
 
Sat Oct  4 05:52:35 2008
@@ -39,6 +39,9 @@
              <label>Delete Photo</label> <input type="image"  
src="/site_media/delete.png" border="0" title="{% trans "Delete Photo" %}"  
/>
                          <input type="hidden" name="action" value="delete"/>
          </form>
+
+        <a href="{% url photo_edit photo.id %}">Edit Photo</a>
+
      {% endif %}

  </div>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to