Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Coding Backend #77

Merged
merged 3 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified backend/artistsmgmt/__pycache__/serializers.cpython-310.pyc
Binary file not shown.
Binary file modified backend/artistsmgmt/__pycache__/views.cpython-310.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions backend/artistsmgmt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ def create(self, validated_data):


class ArtistSerializer(serializers.ModelSerializer):
artist_name = serializers.SerializerMethodField()

class Meta:
model = Artist
fields = '__all__'
extra_kwargs = {'user': {'read_only': True}}

def get_artist_name(self, obj):
return obj.user.username if obj.user.username else ""

# Portfolio


class PortfolioSerializer(serializers.ModelSerializer):
class Meta:
model = Portfolio
Expand Down
17 changes: 8 additions & 9 deletions backend/artistsmgmt/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,19 @@ def post(self, request, format=None):
request.user.auth_token.delete()
return Response("Successfully signed out", status=status.HTTP_200_OK)

# class ArtistOnlyView(generics.RetrieveAPIView):
# permission_classes = [permissions.IsAuthenticated, IsArtist]
# serializer_class = UserSerializer

# def get_object(self):
# return self.request.user


class ArtistOnlyView(APIView):
permission_classes = [IsAuthenticated, IsArtist]
serializer_class = UserSerializer

def get(self, request, format=None):
return Response(data={"message": "You are an artist"}, status=status.HTTP_200_OK)
# Retrieve the authenticated artist
artist = Artist.objects.get(user=request.user)

# Serialize all fields and their values for the artist
serializer = ArtistSerializer(artist)

# Return serialized data
return Response(serializer.data, status=status.HTTP_200_OK)


class ArtistCreateView(generics.ListCreateAPIView):
Expand Down
Binary file modified backend/backend/__pycache__/urls.cpython-310.pyc
Binary file not shown.
16 changes: 7 additions & 9 deletions frontend/src/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import '../styles/scss/theme.scss';
import Layout from '@/layout/Layout';

export default function App({ Component, pageProps, router }) {
const isLoginPage = router.pathname === '/login';
const isSignupPage = router.pathname === '/signup';
const isShowcasePage = router.pathname === '/showcase';
const isProfilePage = router.pathname === '/profile';
const isFormPage = router.pathname === '/form';
const is404Page = router.pathname === '/404';
// const isLoginPage = router.pathname === '/login';
// const isSignupPage = router.pathname === '/signup';
// const isShowcasePage = router.pathname === '/showcase';
// const isProfilePage = router.pathname === '/profile';
// const isFormPage = router.pathname === '/form';
// const is404Page = router.pathname === '/404';

const shouldIncludeNavbarAndFooter = !(isLoginPage || isSignupPage || isShowcasePage || isProfilePage || isFormPage || is404Page);
// const shouldIncludeNavbarAndFooter = !(isLoginPage || isSignupPage || isShowcasePage || isProfilePage || isFormPage || is404Page);

useEffect(() => {
// Initialize Google Analytics
Expand All @@ -28,8 +28,6 @@ export default function App({ Component, pageProps, router }) {
}, [router.pathname]); // Track page views on route changes

return (
<Layout includeNavbar={shouldIncludeNavbarAndFooter} includeFooter={shouldIncludeNavbarAndFooter}>
<Component {...pageProps} />
</Layout>
);
}
115 changes: 67 additions & 48 deletions frontend/src/pages/events.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,101 @@
import Head from 'next/head';
import Head from "next/head";
import Layout from "../layout/Layout";

const UpcomingEventsPage = () => {
// Dummy data for upcoming events
const upcomingEvents = [
{
id: 1,
title: 'Art Exhibition: Colors of Creativity',
date: 'November 25, 2023',
location: 'Swahilipot Hub Gallery',
description: 'Join us for an inspiring art exhibition showcasing a vibrant array of creative expressions.',
image: '/featured/bahari-brush.jpg',
title: "Art Exhibition: Colors of Creativity",
date: "November 25, 2023",
location: "Swahilipot Hub Gallery",
description:
"Join us for an inspiring art exhibition showcasing a vibrant array of creative expressions.",
image: "/featured/bahari-brush.jpg",
},
{
id: 2,
title: 'Music Festival: Harmony in Diversity',
date: 'December 10, 2023',
location: 'Swahilipot Hub Amphitheater',
description: 'Experience the magic of music as diverse artists come together to create a harmonious celebration of unity.',
image: '/events/music-fest.jpg',
title: "Music Festival: Harmony in Diversity",
date: "December 10, 2023",
location: "Swahilipot Hub Amphitheater",
description:
"Experience the magic of music as diverse artists come together to create a harmonious celebration of unity.",
image: "/events/music-fest.jpg",
},
{
id: 3,
title: 'Spoken Word & Poetry: Poetic Justice',
date: '2023-12-15',
location: 'SPH Ampitheatre',
image: '/events/spokenword.jpg',
title: "Spoken Word & Poetry: Poetic Justice",
date: "2023-12-15",
location: "SPH Ampitheatre",
image: "/events/spokenword.jpg",
},
{
id: 4,
title: 'Concert in the Park: Music Fusion',
date: '2023-12-20',
location: 'City Park Amphitheater',
image: '/events/concert.jpg',
title: "Concert in the Park: Music Fusion",
date: "2023-12-20",
location: "City Park Amphitheater",
image: "/events/concert.jpg",
},
{
id: 5,
title: 'Workshop: Digital Art Masterclass',
date: '2023-12-25',
location: 'Creative Hub Studios',
image: '/events/digital.jpg',
title: "Workshop: Digital Art Masterclass",
date: "2023-12-25",
location: "Creative Hub Studios",
image: "/events/digital.jpg",
},
{
id: 6,
title: 'Comedy Night: Laugh Festival',
date: '2023-12-28',
location: 'Creative Hub Studios',
image: '/events/laughfest.jpg',
title: "Comedy Night: Laugh Festival",
date: "2023-12-28",
location: "Creative Hub Studios",
image: "/events/laughfest.jpg",
},
// Add more events as needed
];

return (
<>
<Head>
<title>Upcoming Events</title>
</Head>
<Layout>
<Head>
<title>Upcoming Events</title>
</Head>

<section className="container py-5">
<h1 className="mb-4">Upcoming Events</h1>
<section className="container py-5">
<h1 className="mb-4">Upcoming Events</h1>

<div className="row">
{upcomingEvents.map((event) => (
<div key={event.id} className="col-md-6 mb-4">
<div className="card" style={{ backgroundImage: `url(${event.image})`, backgroundSize: 'cover', height: '300px' }}>
<div className="card-body">
<h5 className="card-title" style={{ color: 'yellow' }}>{event.title}</h5>
<p className="card-text" style={{ color: 'white' }}>
<strong>Date:</strong> {event.date}<br />
<strong>Location:</strong> {event.location}
</p>
<p className="card-text" style={{ color: 'white' }}>{event.description}</p>
<button className="btn btn-light">View Event Details</button>
<div className="row">
{upcomingEvents.map((event) => (
<div key={event.id} className="col-md-6 mb-4">
<div
className="card"
style={{
backgroundImage: `url(${event.image})`,
backgroundSize: "cover",
height: "300px",
}}
>
<div className="card-body">
<h5 className="card-title" style={{ color: "yellow" }}>
{event.title}
</h5>
<p className="card-text" style={{ color: "white" }}>
<strong>Date:</strong> {event.date}
<br />
<strong>Location:</strong> {event.location}
</p>
<p className="card-text" style={{ color: "white" }}>
{event.description}
</p>
<button className="btn btn-light">
View Event Details
</button>
</div>
</div>
</div>
</div>
))}
</div>
</section>
))}
</div>
</section>
</Layout>
</>
);
};
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ const HomePage = () => {
<div>
{userData ? (
<div>
<h1>{userData.message}!</h1>
{/* Display user-specific content */}
<h1>Welcome, {userData.artist_name}!</h1>
</div>
) : (
<p>Loading...</p>
Expand Down
26 changes: 14 additions & 12 deletions frontend/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import Portfolio from "@/components/portfolio/Portfolio"
import Events from "@/components/landing/Events"
import Featured from "@/components/landing/Featured"

const { default: Hero } = require("@/components/landing/Hero")
import Portfolio from "@/components/portfolio/Portfolio";
import Events from "@/components/landing/Events";
import Featured from "@/components/landing/Featured";
import Layout from "@/layout/Layout";

const { default: Hero } = require("@/components/landing/Hero");

const Landing = () => {
return (
<>
<Hero />
<Portfolio />
<Featured />
<Events />
<Layout>
<Hero />
<Portfolio />
<Featured />
<Events />
</Layout>
</>
)
}
);
};

export default Landing
export default Landing;
9 changes: 6 additions & 3 deletions frontend/src/pages/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ const SignUpForm = () => {
}
} catch (error) {
console.error("Error during signup:", error);
setErrorMessage("Error during signup. Please try again.");
setSuccessMessage("");
if (error.response && error.response.status === 400) {
setErrorMessage("A user with that username already exists.");
} else {
setErrorMessage("Signup failed. Please try again.");
}
}
};

Expand Down Expand Up @@ -206,7 +209,7 @@ const SignUpForm = () => {

<div className="d-flex align-items-center justify-content-center pb-4">
<p className="mb-0 me-2">Already have an account?</p>
<a href="/signup" className="btn btn-outline-danger">
<a href="/login" className="btn btn-outline-danger">
Log In
</a>
</div>
Expand Down