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

Abdulazeez saheed olawale #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv
Binary file added django/SDG23/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added django/SDG23/__pycache__/settings.cpython-38.pyc
Binary file not shown.
Binary file added django/SDG23/__pycache__/solve.cpython-38.pyc
Binary file not shown.
Binary file added django/SDG23/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added django/SDG23/__pycache__/wsgi.cpython-38.pyc
Binary file not shown.
27 changes: 23 additions & 4 deletions django/SDG23/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@
#### array is empty or contains only negative integers, the function should return 0.
######################################################################################

def getMaxSum(list):
pass
def getMaxSum(array):
if not array or max(array) < 0:
return 0

max_sum = array[0]
current_sum = array[0]

for i in range(1, len(array)):
if current_sum < 0:
current_sum = array[i]
else:
current_sum += array[i]
max_sum = max(max_sum, current_sum)

return max_sum

######################################################################################
############################## Question 2: ###########################################
Expand All @@ -19,5 +29,14 @@ def getMaxSum(list):
#### only whitespaces, the function should return an empty string.
######################################################################################

def uniqueChars(str):
pass
def uniqueChars(string):
unique_letters = ""
if string.isspace() or string == "":
return ""
else:
for letter in string:
if letter not in unique_letters:
unique_letters += letter
return unique_letters
a = uniqueChars(" \t ")
print(a)
3 changes: 2 additions & 1 deletion django/SDG23/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path,include

urlpatterns = [
path('admin/', admin.site.urls),
path('api/tasks/',include('todo_api.urls')),
]
Binary file added django/db.sqlite3
Binary file not shown.
Binary file added django/todo_api/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added django/todo_api/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file added django/todo_api/__pycache__/apps.cpython-38.pyc
Binary file not shown.
Binary file added django/todo_api/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file added django/todo_api/__pycache__/tests.cpython-38.pyc
Binary file not shown.
Binary file added django/todo_api/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added django/todo_api/__pycache__/views.cpython-38.pyc
Binary file not shown.
24 changes: 24 additions & 0 deletions django/todo_api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.1 on 2023-05-20 19:46

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Task',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('task_name', models.CharField(max_length=500)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('status', models.IntegerField(choices=[(0, 'Pending'), {1, 'Completed'}], default=0)),
],
),
]
18 changes: 18 additions & 0 deletions django/todo_api/migrations/0002_alter_task_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.1 on 2023-05-20 20:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('todo_api', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='task',
name='status',
field=models.BooleanField(default=False),
),
]
18 changes: 18 additions & 0 deletions django/todo_api/migrations/0003_rename_status_task_completed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.1 on 2023-05-20 20:01

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('todo_api', '0002_alter_task_status'),
]

operations = [
migrations.RenameField(
model_name='task',
old_name='status',
new_name='completed',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.1 on 2023-05-21 05:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('todo_api', '0003_rename_status_task_completed'),
]

operations = [
migrations.RenameField(
model_name='task',
old_name='task_name',
new_name='title',
),
migrations.AddField(
model_name='task',
name='description',
field=models.TextField(default='gh ghg hghghjgjh ghj gh jghj'),
preserve_default=False,
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
13 changes: 12 additions & 1 deletion django/todo_api/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
from django.db import models



class Task(models.Model):
pass
title = models.CharField(max_length=500)
description = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
completed = models.BooleanField(default=False)

def __str__(self):
return self.task_name


7 changes: 7 additions & 0 deletions django/todo_api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .models import Task
from rest_framework import serializers

class TaskSerializer(serializers.ModelSerializer):
class Meta:
model = Task
fields = '__all__'
8 changes: 8 additions & 0 deletions django/todo_api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from . import views

urlpatterns = [
path('',views.TaskList.as_view(),name='task_list'),
path('<task_id>/',views.TaskDetail.as_view(),name='task_detail'),
path('<task_id>/completed/',views.TaskComplete.as_view(),name='task_complete'),
]
28 changes: 27 additions & 1 deletion django/todo_api/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
from django.shortcuts import render
from django.shortcuts import render,get_object_or_404,redirect
from rest_framework import generics
from .models import Task
from .serializers import TaskSerializer
from rest_framework.decorators import api_view
from rest_framework.response import Response


# Create your views here.

class TaskList(generics.ListCreateAPIView):
queryset = Task.objects.all()
serializer_class = TaskSerializer


class TaskDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Task.objects.all()
serializer_class = TaskSerializer
lookup_url_kwarg = 'task_id'


class TaskComplete(generics.UpdateAPIView):
queryset = Task.objects.all()
serializer_class = TaskSerializer
lookup_url_kwarg = 'task_id'

def perform_update(self, serializer):
serializer.completed = True
return serializer