Harshal Vhatkar
commited on
Commit
·
fb298f6
1
Parent(s):
1d8204c
add web resource
Browse files- session_page.py +94 -1
session_page.py
CHANGED
@@ -235,6 +235,28 @@ def display_preclass_content(session, student_id, course_id):
|
|
235 |
)
|
236 |
if st.button("Mark PowerPoint as Read", key=f"pptx_{material['_id']}"):
|
237 |
create_notification("PowerPoint presentation marked as read!", "success")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
|
239 |
|
240 |
# Initialize 'messages' in session_state if it doesn't exist
|
@@ -754,7 +776,7 @@ def upload_preclass_materials(session_id, course_id):
|
|
754 |
st.subheader("Pre-class Materials Management")
|
755 |
|
756 |
# Create tabs for different functionalities
|
757 |
-
upload_tab, videos_tab, external_tab= st.tabs(["Upload Materials","Upload Video Sources","
|
758 |
|
759 |
with upload_tab:
|
760 |
# Original file upload functionality
|
@@ -778,6 +800,77 @@ def upload_preclass_materials(session_id, course_id):
|
|
778 |
# if video_resource_id:
|
779 |
# st.success("Video source uploaded successfully!")
|
780 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
781 |
with external_tab:
|
782 |
# Fetch and display external resources
|
783 |
session_data = courses_collection.find_one(
|
|
|
235 |
)
|
236 |
if st.button("Mark PowerPoint as Read", key=f"pptx_{material['_id']}"):
|
237 |
create_notification("PowerPoint presentation marked as read!", "success")
|
238 |
+
|
239 |
+
elif file_type == 'web_resource':
|
240 |
+
# Display resource details
|
241 |
+
st.markdown(f"**Type:** {material['material_type']}")
|
242 |
+
if material.get('description'):
|
243 |
+
st.markdown(f"**Description:** {material['description']}")
|
244 |
+
|
245 |
+
# Display resource link
|
246 |
+
st.markdown(f"**Resource Link:** [{material['file_name']}]({material['source_url']})")
|
247 |
+
|
248 |
+
# Add "Open in New Tab" button
|
249 |
+
if st.button("Open in New Tab", key=f"open_{material['_id']}"):
|
250 |
+
# Use JavaScript to open in new tab
|
251 |
+
st.markdown(f"""
|
252 |
+
<script>
|
253 |
+
window.open('{material['source_url']}', '_blank');
|
254 |
+
</script>
|
255 |
+
""", unsafe_allow_html=True)
|
256 |
+
|
257 |
+
# Add "Mark as Read" functionality
|
258 |
+
if st.button("Mark as Read", key=f"read_{material['_id']}"):
|
259 |
+
create_notification(f"{material['material_type']} marked as read!", "success")
|
260 |
|
261 |
|
262 |
# Initialize 'messages' in session_state if it doesn't exist
|
|
|
776 |
st.subheader("Pre-class Materials Management")
|
777 |
|
778 |
# Create tabs for different functionalities
|
779 |
+
upload_tab, videos_tab, web_resources ,external_tab= st.tabs(["Upload Materials","Upload Video Sources","Web Resources", "Resources by Perplexity"])
|
780 |
|
781 |
with upload_tab:
|
782 |
# Original file upload functionality
|
|
|
800 |
# if video_resource_id:
|
801 |
# st.success("Video source uploaded successfully!")
|
802 |
|
803 |
+
with web_resources:
|
804 |
+
st.markdown("##### Upload Web Resource Links")
|
805 |
+
st.info("""
|
806 |
+
Share online resources with your students. Supported links include:
|
807 |
+
- Google Colab notebooks
|
808 |
+
- Google Slides presentations
|
809 |
+
- Online documentation
|
810 |
+
- Educational websites
|
811 |
+
- Any web-based learning resource
|
812 |
+
""")
|
813 |
+
|
814 |
+
# Form for adding web resource
|
815 |
+
with st.form("web_resource_form"):
|
816 |
+
resource_title = st.text_input("Resource Title",
|
817 |
+
placeholder="e.g., Python Basics Notebook, Data Visualization Tutorial")
|
818 |
+
resource_url = st.text_input("Resource URL",
|
819 |
+
placeholder="https://colab.research.google.com/... or other web resource")
|
820 |
+
resource_type = st.selectbox("Resource Type",
|
821 |
+
["Jupyter Notebook", "Presentation", "Documentation", "Tutorial", "Other"])
|
822 |
+
resource_description = st.text_area("Description (Optional)",
|
823 |
+
placeholder="Brief description of the resource")
|
824 |
+
|
825 |
+
submit_resource = st.form_submit_button("Add Resource")
|
826 |
+
|
827 |
+
if submit_resource:
|
828 |
+
if not resource_title or not resource_url:
|
829 |
+
st.error("Please provide both a title and URL.")
|
830 |
+
else:
|
831 |
+
try:
|
832 |
+
# Create resource document
|
833 |
+
resource_data = {
|
834 |
+
"_id": ObjectId(),
|
835 |
+
"course_id": course_id,
|
836 |
+
"session_id": session_id,
|
837 |
+
"file_name": resource_title,
|
838 |
+
"file_type": "web_resource",
|
839 |
+
"material_type": resource_type,
|
840 |
+
"source_url": resource_url,
|
841 |
+
"description": resource_description,
|
842 |
+
"uploaded_at": datetime.utcnow()
|
843 |
+
}
|
844 |
+
|
845 |
+
# Check if resource already exists
|
846 |
+
existing_resource = resources_collection.find_one({
|
847 |
+
"session_id": session_id,
|
848 |
+
"source_url": resource_url
|
849 |
+
})
|
850 |
+
if existing_resource:
|
851 |
+
st.warning("This resource has already been added.")
|
852 |
+
else:
|
853 |
+
# Insert new resource
|
854 |
+
resources_collection.insert_one(resource_data)
|
855 |
+
resource_id = resource_data["_id"]
|
856 |
+
|
857 |
+
# Update course document
|
858 |
+
courses_collection.update_one(
|
859 |
+
{
|
860 |
+
"course_id": course_id,
|
861 |
+
"sessions.session_id": session_id
|
862 |
+
},
|
863 |
+
{
|
864 |
+
"$push": {"sessions.$.pre_class.resources": resource_id}
|
865 |
+
}
|
866 |
+
)
|
867 |
+
st.success(f"✅ Resource '{resource_title}' added successfully!")
|
868 |
+
|
869 |
+
except Exception as e:
|
870 |
+
st.error(f"Error adding resource: {str(e)}")
|
871 |
+
|
872 |
+
|
873 |
+
|
874 |
with external_tab:
|
875 |
# Fetch and display external resources
|
876 |
session_data = courses_collection.find_one(
|