Repository: fossasia/open-event-server

Issue:
Create a subtab in the admin content section for system images
Follow up/Related to https://github.com/fossasia/open-event-orga-server/issues/1845#issuecomment-236981065
- [x] Create a subtab "System Images" at https://open-event-dev.herokuapp.com/admin/content/
- [x] List all topics and subtopics 
  - [x] Add a standard image for each topic/subtopic
  - [x] Enable administrator to change that image -> Create an upload field for an image
- [x] Add help text about which size (width/height) is required
- [x] Add field form field for copyright and origin information next to each image as well



Discussion:
@niranjan94 can you help me with the uploading the new image?

@SaptakS Right now the implementation still shows images for topics, but subtopics are still not implemented. There should be much more different subtopics.

We discussed this 16 days ago already here: https://github.com/fossasia/open-event-orga-server/issues/1845#issuecomment-236990088

Please also add a dedicated photo for each subcategory. If subcategory is not chosen, use the photo of the main category.

![screenshot from 2016-08-02 20 04 32](https://cloud.githubusercontent.com/assets/1583873/17339498/79a69c20-58ec-11e6-9af3-5c35616f858b.png)

Ok, my last comment should have gone into this issue https://github.com/fossasia/open-event-orga-server/issues/2019#issuecomment-240758846

I deleted it and reposted it there. Thanks.

@mariobehling I have already implemented the backend for the subtopic as well. I only need to find the images dedicated for the subtopic and add them. The code is already written and as soon as the images are added and listed, it will get shown. Thus I feel that comment is not very relevant. The PR I made now should pretty much resolve the issue as to uploading custom placeholders and so on. Please check.


Resolving patch:
diff --git a/app/helpers/data_getter.py b/app/helpers/data_getter.py
--- a/app/helpers/data_getter.py
+++ b/app/helpers/data_getter.py
@@ -91,6 +91,14 @@ def get_all_events():
     def get_custom_placeholders():
         return CustomPlaceholder.query.all()
 
+    @staticmethod
+    def get_custom_placeholder_by_id(placeholder_id):
+        return CustomPlaceholder.query.filter_by(id=placeholder_id).first()
+
+    @staticmethod
+    def get_custom_placeholder_by_name(name):
+        return CustomPlaceholder.query.filter_by(name=name).first()
+
     @staticmethod
     def get_all_users_events_roles():
         """Method return all events"""
diff --git a/app/views/admin/super_admin/content.py b/app/views/admin/super_admin/content.py
--- a/app/views/admin/super_admin/content.py
+++ b/app/views/admin/super_admin/content.py
@@ -60,21 +60,33 @@ def placeholder_upload(self):
                     'placeholders/thumbnail/'+filename
                 )
                 shutil.rmtree(path='static/media/temp/')
-                print request.form['name']
-                placeholder_db = CustomPlaceholder(name=request.form['name'],
-                                                   url=placeholder,
-                                                   thumbnail=background_thumbnail_url,
-                                                   copyright=request.form['copyright'],
-                                                   origin=request.form['origin'])
-                save_to_db(placeholder_db, 'User notification saved')
+                placeholder_db = DataGetter.get_custom_placeholder_by_name(request.form['name'])
+                if placeholder_db:
+                    placeholder_db.url = placeholder
+                    placeholder_db.thumbnail = background_thumbnail_url
+                else:
+                    placeholder_db = CustomPlaceholder(name=request.form['name'],
+                                                       url=placeholder,
+                                                       thumbnail=background_thumbnail_url)
+                save_to_db(placeholder_db, 'Custom Placeholder saved')
 
-                return jsonify({'status': 'ok', 'placeholder': placeholder})
+                return jsonify({'status': 'ok', 'placeholder': placeholder, 'id': placeholder_db.id})
             else:
                 return jsonify({'status': 'no logo'})
 
     @expose('/update_placeholder', methods=('POST',))
     def placeholder_upload_details(self):
-        pass
+        if request.method == 'POST':
+            print request.form
+            copyright_info = request.form['copyright']
+            origin_info = request.form['origin']
+            placeholder_id = request.form['placeholder_id']
+            placeholder_db = DataGetter.get_custom_placeholder_by_id(placeholder_id)
+            placeholder_db.copyright = copyright_info
+            placeholder_db.origin = origin_info
+            save_to_db(placeholder_db, 'Custom Placeholder updated')
+            return jsonify({'status': 'ok'})
+        return jsonify({'status': 'error'})
 
     @expose('/pages/create', methods=['POST'])
     def create_view(self):


Test patch: