sachin commited on
Commit
a5bf84e
·
1 Parent(s): 33969a2

init prokect

Browse files
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ venv
2
+
3
+ *.pyc
4
+ __pycache
Dockerfile ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pull official base image
2
+ FROM python:3.10-bullseye
3
+
4
+ RUN useradd -m -u 1000 user
5
+ USER user
6
+
7
+ ENV PATH="/home/user/.local/bin:$PATH"
8
+ # set work directory
9
+ WORKDIR /app
10
+
11
+ # set environment variables
12
+ ENV PYTHONDONTWRITEBYTECODE 1
13
+ ENV PYTHONUNBUFFERED 1
14
+
15
+ # install system dependencies
16
+ #RUN apt-get update && apt-get install -y netcat
17
+
18
+ # install dependencies
19
+ RUN pip install --upgrade pip
20
+ COPY --chown=user ./requirements.txt requirements.txt
21
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
22
+
23
+
24
+ # copy project
25
+
26
+ COPY --chown=user . /app
27
+
28
+ RUN python manage.py migrate
29
+
30
+ CMD ["python", "manage.py", "runserver", "0.0.0.0:7860"]
31
+
32
+ #CMD ["uvicorn", "spaces.asgi:application", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
  title: Django Spaces
3
- emoji:
4
- colorFrom: purple
5
  colorTo: pink
6
  sdk: docker
7
  pinned: false
 
1
  ---
2
  title: Django Spaces
3
+ emoji: 🏢
4
+ colorFrom: yellow
5
  colorTo: pink
6
  sdk: docker
7
  pinned: false
db.sqlite3 ADDED
Binary file (135 kB). View file
 
docs/setup.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Backend
2
+
3
+ Setup
4
+
5
+
6
+
7
+ git clone https://huggingface.co/spaces/gaganyatri/django_spaces
8
+
9
+ cd django_spaces
10
+
11
+ docker build -t slabstech/gaganyatri -f Dockerfile .
12
+
13
+ docker run slabstech/gaganyatri
14
+
15
+
16
+ - Steps to build this project
17
+ - python3.10 -m venv venv
18
+ - source venv/bin/activate
19
+ - pip install Django==5.1.1
20
+ - django-admin startproject spaces .
21
+ - python manage.py migrate
22
+ - python manage.py runserver
23
+
24
+ - python manage.py startapp space_walks
25
+ - python manage.py makemigrations
26
+ - python manage.py migrate
27
+
28
+
29
+ - pip install uvicorn
30
+ - python -m uvicorn spaces.asgi:application
31
+
32
+
33
+ - Merge for Huggingface
34
+ - git fetch --all
35
+ - git checkout main
36
+ - git merge --squash django-setup
37
+ - git commit -m "merge"
38
+ - git push origin main
39
+
40
+
41
+
42
+ - Referenc
43
+ - https://www.djangoproject.com/download/
44
+ - https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/
45
+ - https://github.com/testdrivenio/django-on-docker
46
+
47
+
manage.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """Django's command-line utility for administrative tasks."""
3
+ import os
4
+ import sys
5
+
6
+
7
+ def main():
8
+ """Run administrative tasks."""
9
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'spaces.settings')
10
+ try:
11
+ from django.core.management import execute_from_command_line
12
+ except ImportError as exc:
13
+ raise ImportError(
14
+ "Couldn't import Django. Are you sure it's installed and "
15
+ "available on your PYTHONPATH environment variable? Did you "
16
+ "forget to activate a virtual environment?"
17
+ ) from exc
18
+ execute_from_command_line(sys.argv)
19
+
20
+
21
+ if __name__ == '__main__':
22
+ main()
requirements.txt ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ asgiref==3.8.1
2
+ click==8.1.7
3
+ Django==5.1.1
4
+ django-cors-headers==4.4.0
5
+ djangorestframework==3.15.2
6
+ drf-yasg==1.21.7
7
+ h11==0.14.0
8
+ inflection==0.5.1
9
+ packaging==24.1
10
+ pytz==2024.2
11
+ PyYAML==6.0.2
12
+ sqlparse==0.5.1
13
+ typing_extensions==4.12.2
14
+ uritemplate==4.1.1
15
+ uvicorn==0.30.6
space_walks/__init__.py ADDED
File without changes
space_walks/admin.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ from django.contrib import admin
2
+ from .models import SpaceWalks
3
+
4
+ admin.site.register(SpaceWalks)
space_walks/apps.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class SpaceWalksConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'space_walks'
space_walks/migrations/0001_initial.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by Django 5.1.1 on 2024-09-18 19:26
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ initial = True
9
+
10
+ dependencies = [
11
+ ]
12
+
13
+ operations = [
14
+ migrations.CreateModel(
15
+ name='SpaceWalks',
16
+ fields=[
17
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+ ('astronaut', models.CharField(max_length=100)),
19
+ ('date', models.DateField()),
20
+ ('duration', models.DurationField()),
21
+ ('description', models.TextField()),
22
+ ],
23
+ options={
24
+ 'ordering': ['-date'],
25
+ },
26
+ ),
27
+ ]
space_walks/migrations/0002_space_walks.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by Django 5.1.1 on 2024-09-15 17:50
2
+
3
+ from django.db import migrations
4
+ from datetime import datetime, timedelta
5
+
6
+ def create_space_walks(apps, schema_editor):
7
+ SpaceWalks = apps.get_model('space_walks', 'SpaceWalks')
8
+ space_walks_data = [
9
+ {'astronaut': 'Chris Cassidy', 'date': '2018-11-02', 'duration': '06:36:00', 'description': 'Replaced a faulty battery on the Japanese Experiment Module Exposed Facility (JEM-EF).'},
10
+ {'astronaut': 'Anne McClain', 'date': '2019-03-29', 'duration': '06:31:00', 'description': 'Installed new batteries on the JEM-EF and replaced a faulty pump on the Kibo laboratory module.'},
11
+ {'astronaut': 'Christina Koch', 'date': '2019-05-30', 'duration': '06:30:00', 'description': 'Replaced a faulty pump on the JEM-EF and installed new batteries on the Kibo laboratory module.'},
12
+ {'astronaut': 'Luca Parmitano', 'date': '2019-10-18', 'duration': '06:50:00', 'description': 'Installed new batteries on the JEM-EF and replaced a faulty pump on the Kibo laboratory module.'},
13
+ {'astronaut': 'Chris Cassidy', 'date': '2020-02-21', 'duration': '06:45:00', 'description': 'Replaced a faulty pump on the JEM-EF and installed new batteries on the Kibo laboratory module.'},
14
+ {'astronaut': 'Douglas Hurley', 'date': '2020-05-30', 'duration': '06:58:00', 'description': 'Installed new batteries on the JEM-EF and replaced a faulty pump on the Kibo laboratory module.'},
15
+ {'astronaut': 'Victor Glover', 'date': '2020-10-27', 'duration': '06:32:00', 'description': 'Replaced a faulty pump on the JEM-EF and installed new batteries on the Kibo laboratory module.'},
16
+ {'astronaut': 'Shane Kimbrough', 'date': '2021-03-18', 'duration': '06:49:00', 'description': 'Installed new batteries on the JEM-EF and replaced a faulty pump on the Kibo laboratory module.'},
17
+ {'astronaut': 'Megan McArthur', 'date': '2021-09-16', 'duration': '06:38:00', 'description': 'Replaced a faulty pump on the JEM-EF and installed new batteries on the Kibo laboratory module.'},
18
+ {'astronaut': 'Akihiko Hoshide', 'date': '2022-04-28', 'duration': '06:42:00', 'description': 'Installed new batteries on the JEM-EF and replaced a faulty pump on the Kibo laboratory module.'},
19
+ ]
20
+ for data in space_walks_data:
21
+ SpaceWalks.objects.create(
22
+ astronaut=data['astronaut'],
23
+ date=datetime.strptime(data['date'], '%Y-%m-%d').date(),
24
+ duration=timedelta(hours=int(data['duration'][:2]), minutes=int(data['duration'][3:5]), seconds=int(data['duration'][6:])),
25
+ description=data['description']
26
+ )
27
+
28
+ class Migration(migrations.Migration):
29
+
30
+ dependencies = [
31
+ ('space_walks', '0001_initial'),
32
+ ]
33
+
34
+ operations = [
35
+ migrations.RunPython(create_space_walks),
36
+ ]
space_walks/migrations/__init__.py ADDED
File without changes
space_walks/models.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.db import models
2
+
3
+ class SpaceWalks(models.Model):
4
+ astronaut = models.CharField(max_length=100)
5
+ date = models.DateField()
6
+ duration = models.DurationField()
7
+ description = models.TextField()
8
+
9
+ def __str__(self):
10
+ return f"{self.astronaut} - {self.date}"
11
+
12
+ class Meta:
13
+ ordering = ['-date']
space_walks/serializers.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from rest_framework import serializers
2
+ from .models import SpaceWalks
3
+
4
+ class SpaceWalksSerializer(serializers.ModelSerializer):
5
+ class Meta:
6
+ model = SpaceWalks
7
+ fields = '__all__'
space_walks/templates/list.html ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <table>
2
+ <tr>
3
+ <th>Column 1</th>
4
+ <th>Column 2</th>
5
+ <th>Column 3</th>
6
+ </tr>
7
+ {% for item in items %}
8
+ <tr>
9
+ <td>{{ item.column1 }}</td>
10
+ <td>{{ item.column2 }}</td>
11
+ <td>{{ item.column3 }}</td>
12
+ </tr>
13
+ {% endfor %}
14
+ </table>
space_walks/tests.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.test import TestCase
2
+
3
+ # Create your tests here.
space_walks/urls.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.urls import path, include
2
+ from . import views
3
+
4
+ urlpatterns = [
5
+ path('', views.list_items, name='list_items'),
6
+ ]
7
+
8
+ from rest_framework.routers import DefaultRouter
9
+ from .views import SpaceWalksViewSet
10
+
11
+ router = DefaultRouter()
12
+ router.register(r'space_walks', SpaceWalksViewSet)
13
+
14
+ urlpatterns = [
15
+ # ... other URL patterns
16
+ path('api/', include(router.urls)),
17
+ ]
space_walks/views.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.shortcuts import render
2
+ from .models import SpaceWalks
3
+ from rest_framework import viewsets
4
+ from .models import SpaceWalks
5
+ from .serializers import SpaceWalksSerializer
6
+
7
+ def list_items(request):
8
+ items = SpaceWalks.objects.all()
9
+ return render(request, 'space_walks/list.html', {'items': items})
10
+
11
+ class SpaceWalksViewSet(viewsets.ModelViewSet):
12
+ queryset = SpaceWalks.objects.all()
13
+ serializer_class = SpaceWalksSerializer
spaces/__init__.py ADDED
File without changes
spaces/asgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ASGI config for spaces project.
3
+
4
+ It exposes the ASGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
8
+ """
9
+
10
+ import os
11
+
12
+ from django.core.asgi import get_asgi_application
13
+
14
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'spaces.settings')
15
+
16
+ application = get_asgi_application()
spaces/settings.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Django settings for spaces project.
3
+
4
+ Generated by 'django-admin startproject' using Django 5.1.1.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/5.1/topics/settings/
8
+
9
+ For the full list of settings and their values, see
10
+ https://docs.djangoproject.com/en/5.1/ref/settings/
11
+ """
12
+
13
+ from pathlib import Path
14
+
15
+ # Build paths inside the project like this: BASE_DIR / 'subdir'.
16
+ BASE_DIR = Path(__file__).resolve().parent.parent
17
+
18
+
19
+ # Quick-start development settings - unsuitable for production
20
+ # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
21
+
22
+ # SECURITY WARNING: keep the secret key used in production secret!
23
+ SECRET_KEY = 'django-insecure-$ih_-&px4p$qcr2uf02un+&3*_$fr@4a_gnik&2yb17e$kb*c_'
24
+
25
+ # SECURITY WARNING: don't run with debug turned on in production!
26
+ DEBUG = True
27
+
28
+ ALLOWED_HOSTS = ["*"]
29
+
30
+ X_FRAME_OPTIONS = 'ALLOW-FROM https://huggingface.co/'
31
+ # Application definition
32
+
33
+ INSTALLED_APPS = [
34
+ 'corsheaders',
35
+ 'django.contrib.admin',
36
+ 'django.contrib.auth',
37
+ 'django.contrib.contenttypes',
38
+ 'django.contrib.sessions',
39
+ 'django.contrib.messages',
40
+ 'django.contrib.staticfiles',
41
+ 'drf_yasg',
42
+ # 'spaces'
43
+ 'space_walks',
44
+ ]
45
+
46
+ MIDDLEWARE = [
47
+ 'corsheaders.middleware.CorsMiddleware',
48
+ 'django.middleware.common.CommonMiddleware',
49
+ 'django.middleware.security.SecurityMiddleware',
50
+ 'django.contrib.sessions.middleware.SessionMiddleware',
51
+ 'django.middleware.common.CommonMiddleware',
52
+ 'django.middleware.csrf.CsrfViewMiddleware',
53
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
54
+ 'django.contrib.messages.middleware.MessageMiddleware',
55
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
56
+ ]
57
+
58
+ CORS_ORIGIN_WHITELIST = [
59
+ 'https://gaganyatri.in',
60
+ ]
61
+
62
+ CORS_ALLOW_CREDENTIALS = True
63
+
64
+ ROOT_URLCONF = 'spaces.urls'
65
+
66
+ TEMPLATES = [
67
+ {
68
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
69
+ 'DIRS': [],
70
+ 'APP_DIRS': True,
71
+ 'OPTIONS': {
72
+ 'context_processors': [
73
+ 'django.template.context_processors.debug',
74
+ 'django.template.context_processors.request',
75
+ 'django.contrib.auth.context_processors.auth',
76
+ 'django.contrib.messages.context_processors.messages',
77
+ ],
78
+ },
79
+ },
80
+ ]
81
+
82
+ WSGI_APPLICATION = 'spaces.wsgi.application'
83
+
84
+
85
+ # Database
86
+ # https://docs.djangoproject.com/en/5.1/ref/settings/#databases
87
+
88
+ DATABASES = {
89
+ 'default': {
90
+ 'ENGINE': 'django.db.backends.sqlite3',
91
+ 'NAME': BASE_DIR / 'db.sqlite3',
92
+ }
93
+ }
94
+
95
+
96
+ # Password validation
97
+ # https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
98
+
99
+ AUTH_PASSWORD_VALIDATORS = [
100
+ {
101
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
102
+ },
103
+ {
104
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
105
+ },
106
+ {
107
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
108
+ },
109
+ {
110
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
111
+ },
112
+ ]
113
+
114
+
115
+ # Internationalization
116
+ # https://docs.djangoproject.com/en/5.1/topics/i18n/
117
+
118
+ LANGUAGE_CODE = 'en-us'
119
+
120
+ TIME_ZONE = 'UTC'
121
+
122
+ USE_I18N = True
123
+
124
+ USE_TZ = True
125
+
126
+
127
+ # Static files (CSS, JavaScript, Images)
128
+ # https://docs.djangoproject.com/en/5.1/howto/static-files/
129
+
130
+ STATIC_URL = 'static/'
131
+
132
+ # Default primary key field type
133
+ # https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
134
+
135
+ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
spaces/urls.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ URL configuration for spaces project.
3
+
4
+ The `urlpatterns` list routes URLs to views. For more information please see:
5
+ https://docs.djangoproject.com/en/5.1/topics/http/urls/
6
+ Examples:
7
+ Function views
8
+ 1. Add an import: from my_app import views
9
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
10
+ Class-based views
11
+ 1. Add an import: from other_app.views import Home
12
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13
+ Including another URLconf
14
+ 1. Import the include() function: from django.urls import include, path
15
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16
+ """
17
+ from django.contrib import admin
18
+ from rest_framework import permissions
19
+ from drf_yasg.views import get_schema_view
20
+ from drf_yasg import openapi
21
+ from django.urls import path, include
22
+
23
+ schema_view = get_schema_view(
24
+ openapi.Info(
25
+ title="Gaganyatri",
26
+ default_version='v1',
27
+ description="API for Space Operations",
28
+ terms_of_service="https://www.gaganyatri.in/",
29
+ contact=openapi.Contact(email="[email protected]"),
30
+ license=openapi.License(name="MIT License"),
31
+ ),
32
+ public=True,
33
+ permission_classes=(permissions.AllowAny,),
34
+ urlconf='spaces.urls',
35
+ )
36
+
37
+ urlpatterns = [
38
+ path('admin/', admin.site.urls),
39
+ path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
40
+ path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
41
+ path('space_walks/', include('space_walks.urls')),
42
+ ]
spaces/wsgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ WSGI config for spaces project.
3
+
4
+ It exposes the WSGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
8
+ """
9
+
10
+ import os
11
+
12
+ from django.core.wsgi import get_wsgi_application
13
+
14
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'spaces.settings')
15
+
16
+ application = get_wsgi_application()