Skip to content

Commit

Permalink
fix #79 add formating for core and correct ui formating
Browse files Browse the repository at this point in the history
  • Loading branch information
kirubeltadesse committed Sep 3, 2023
1 parent 6170e9c commit 0390c1c
Show file tree
Hide file tree
Showing 42 changed files with 619 additions and 420 deletions.
71 changes: 36 additions & 35 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
{
"name": "Existing Docker Compose (Extend)",
"name": "Existing Docker Compose (Extend)",

"dockerComposeFile": ["docker-compose.yml"],
"dockerComposeFile": ["docker-compose.yml"],

"service": "svc",
"service": "svc",

"workspaceFolder": "/workspace",
"workspaceFolder": "/workspace",

// Set *default* container specific settings.json values on container create.
"settings": {
"_workbench.uiExtensions": ["peterjausovec.vscode-docker"],
"python.jediEnabled": false,
"python.testing.pytestEnabled": true,
"pythonTestExplorer.testFramework": "pytest",
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"python.pythonPath": "/usr/local/bin/python3",
"python.testing.pytestPath": "/usr/local/bin/pytest",
"editor.formatOnSave": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.fontFamily": "Cascadia Code, Fira Code",
"[markdown]": {
"editor.defaultFormatter": "DavidAnson.vscode-markdownlint"
// Set *default* container specific settings.json values on container create.
"settings": {
"python.formatting.provider": "black",
"_workbench.uiExtensions": ["peterjausovec.vscode-docker"],
"python.jediEnabled": false,
"python.testing.pytestEnabled": true,
"pythonTestExplorer.testFramework": "pytest",
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"python.pythonPath": "/usr/local/bin/python3",
"python.testing.pytestPath": "/usr/local/bin/pytest",
"editor.formatOnSave": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.fontFamily": "Cascadia Code, Fira Code",
"[markdown]": {
"editor.defaultFormatter": "DavidAnson.vscode-markdownlint"
},
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"grammarly.files.include": ["**/*.md", "**/*.txt"]
},
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"grammarly.files.include": ["**/*.md", "**/*.txt"]
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"github.copilot",
"eamodio.gitlens",
"shardulm94.trailing-spaces",
"esbenp.prettier-vscode",
"ms-python.python",
"gruntfuggly.todo-tree",
"cweijan.vscode-database-client2",
"littlefoxteam.vscode-python-test-adapter",
"ms-azuretools.vscode-docker"
]
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"github.copilot",
"eamodio.gitlens",
"shardulm94.trailing-spaces",
"esbenp.prettier-vscode",
"ms-python.python",
"gruntfuggly.todo-tree",
"cweijan.vscode-database-client2",
"littlefoxteam.vscode-python-test-adapter",
"ms-azuretools.vscode-docker"
]
}
40 changes: 39 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,47 @@
*.pyc
.DS_Store
__pycache__
.coverage*
*/htmlcov/*

/data
env
env/*

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Sphinx documentation
docs/_build/

### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
7 changes: 0 additions & 7 deletions .prettierignore

This file was deleted.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ To run the test you can just use the `pytest` package
pytest
```

Code formating

```bash
python -m black ...
```

---

<details>
Expand Down
4 changes: 2 additions & 2 deletions api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'
default_auto_field = "django.db.models.BigAutoField"
name = "api"
24 changes: 19 additions & 5 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,38 @@
from rest_framework import serializers
from backend.models import Event, Mainuser, Student, Mentor


class EventSerializer(serializers.ModelSerializer):
class Meta:
model = Event
fields = ('id', 'title', 'content', 'student', 'mentor', 'start_date', 'end_date', 'status')
fields = (
"id",
"title",
"content",
"student",
"mentor",
"start_date",
"end_date",
"status",
)


# the student class


class StudentSerializer(serializers.ModelSerializer):
class Meta:
model = Mainuser
fields = ('__all__')
model = Mainuser
fields = "__all__"


class MainSerializer(serializers.ModelSerializer):
class Meta:
model = Student
fields = ('__all__')
fields = "__all__"


class MentorSerializer(serializers.ModelSerializer):
class Meta:
model = Mentor
fields = ('__all__')
fields = "__all__"
44 changes: 21 additions & 23 deletions api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,37 @@
from django.contrib.auth.models import User
from django.utils import timezone

class TestEvent(APITestCase):

class TestEvent(APITestCase):
# test if the url is working
def test_view_events(self):
url = reverse('api:list')
response = self.client.get(url, format='json')
url = reverse("api:list")
response = self.client.get(url, format="json")
self.assertEqual(response.status_code, status.HTTP_200_OK)

# test if the data is correct inserted
# test if the data is correct inserted
def create_event(self):

self.test_category = Category.objects.create(name='django')
self.test_category = Category.objects.create(name="django")

self.studentUser = User.objects.create_user(
username='test_user1', password='123456789')
username="test_user1", password="123456789"
)

self.mentorUser = User.objects.create_user(
username='test_user2', password='123456789')

username="test_user2", password="123456789"
)

data = {
'category_id': 1,
'title': 'Event Title',
'content': 'Event Content',
'slug': 'event-title',
'student': self.studentUser,
'mentor': self.mentorUser,
'start_date': timezone.now(),
'end_date': timezone.now(),
'status': 'published'
"category_id": 1,
"title": "Event Title",
"content": "Event Content",
"slug": "event-title",
"student": self.studentUser,
"mentor": self.mentorUser,
"start_date": timezone.now(),
"end_date": timezone.now(),
"status": "published",
}
url = reverse('api:list')
response = self.client.post(url, data, format='json')
url = reverse("api:list")
response = self.client.post(url, data, format="json")
self.assertEqual(response.status_code, status.HTTP_201_CREATED)



11 changes: 5 additions & 6 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from django.urls import path
from django.urls import path
from .views import EventDetail, EventList, MainList

app_name = 'api'
app_name = "api"

urlpatterns = [
path('<int:pk>/', EventDetail.as_view(), name='detail'),
path('', EventList.as_view(), name='list'),
path('mainlist/', MainList.as_view(), name='detail'),

path("<int:pk>/", EventDetail.as_view(), name="detail"),
path("", EventList.as_view(), name="list"),
path("mainlist/", MainList.as_view(), name="detail"),
]
9 changes: 8 additions & 1 deletion api/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from rest_framework import generics
from backend.models import Event, Mainuser
from .serializers import EventSerializer, MentorSerializer, MainSerializer, StudentSerializer
from .serializers import (
EventSerializer,
MentorSerializer,
MainSerializer,
StudentSerializer,
)


class EventList(generics.ListCreateAPIView):
queryset = Event.eventobjects.all()
serializer_class = EventSerializer


class EventDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Event.objects.all()
serializer_class = EventSerializer


class MainList(generics.ListCreateAPIView):
queryset = Mainuser.objects.all()
serializer_class = MainSerializer
17 changes: 9 additions & 8 deletions backend/admin.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from django.contrib import admin
from . import models


@admin.register(models.Event)
class EventAdmin(admin.ModelAdmin):
list_display = ('title', 'student', 'mentor', 'start_date', 'end_date', 'status')
list_filter = ('status', 'date_posted', 'start_date', 'end_date')
search_fields = ('title', 'content')
prepopulated_fields = {'slug': ('title',)}
raw_id_fields = ('student', 'mentor')
date_hierarchy = 'start_date'
ordering = ('status', 'start_date')
list_display = ("title", "student", "mentor", "start_date", "end_date", "status")
list_filter = ("status", "date_posted", "start_date", "end_date")
search_fields = ("title", "content")
prepopulated_fields = {"slug": ("title",)}
raw_id_fields = ("student", "mentor")
date_hierarchy = "start_date"
ordering = ("status", "start_date")


admin.site.register(models.Category)
# Register your models here.

admin.site.register(models.Mainuser)

admin.site.register(models.Student)

4 changes: 2 additions & 2 deletions backend/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class BackendConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'backend'
default_auto_field = "django.db.models.BigAutoField"
name = "backend"
Loading

0 comments on commit 0390c1c

Please sign in to comment.