Skip to content

Commit

Permalink
Project structure, generated post , simple contact form
Browse files Browse the repository at this point in the history
  • Loading branch information
alaref-codes committed Mar 2, 2021
0 parents commit 764ff72
Show file tree
Hide file tree
Showing 32 changed files with 307 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vari.py
Binary file added db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'student_site.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
18 changes: 18 additions & 0 deletions my_posts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{"description": "زملائنا طلبة الكلية الأعزاء ✨✨\n ابشروا بما يسركم 😉 في الساعات القليلة القادمة\n #اتحادطلبةكليةالتقنيةالالكترونية",
"images": [],
"post_url": "",
"external_links": []
},

{"description": "المسابقة تنتهي الساعة 9 مساءً والاجابة تكون عن طريق رسائل الصفحة كالعادة ومرفقة بالاسم.\n يلا انطلقو😉", "images": ["https://scontent.fmji1-1.fna.fbcdn.net/v/t1.0-0/cp0/e15/q65/s261x260/154773728_2867525503518269_2606320992968188401_o.jpg?_nc_cat=103&ccb=3&_nc_sid=110474&_nc_ohc=7FpXmLPFgZkAX9yueB2&_nc_ht=scontent.fmji1-1.fna&tp=9&oh=028efc0417a61543ce010f0072c326d1&oe=60634B48"], "post_url": "",
"external_links": []},

{"description": "انتظرونا بعد اقل من ساعة✨",
"images": ["https://scontent.fmji1-1.fna.fbcdn.net/v/t1.0-0/cp0/e15/q65/s261x260/154965462_2867504443520375_5129616373530031730_n.jpg?_nc_cat=110&ccb=3&_nc_sid=110474&_nc_ohc=BXTsEsHMWS0AX-0wZ8E&_nc_ht=scontent.fmji1-1.fna&tp=9&oh=4c7c692963d2b2708170842001624551&oe=60607EFB"],
"post_url": "",
"external_links": []
},
{"description": "في ظل متابعة اتحاد الطلبة للظروف الراهنة وحرصاً منّا على ضمان حقوق الطلبة عليه فقد تقدم اتحاد طلبة كلية التقنية الالكترونية الى السيد عميد الكلية يوم أمس الثلاثاء الموافق 23/02/2021 بمذكرة احتجاج بخصوص الظروف الحالية وذلك لايجاد حل مناسب للأوضاع الحالية. وكذلك نؤكد على متابعتنا للأمر الى حين التوصل الى حل.", "images": ["https://scontent.fmji1-1.fna.fbcdn.net/v/t1.0-0/cp0/e15/q65/p261x260/154329296_2865918933678926_496372120313000755_n.jpg?_nc_cat=104&ccb=3&_nc_sid=110474&_nc_ohc=9VniwNL8mHgAX-Mh0Xr&_nc_ht=scontent.fmji1-1.fna&tp=3&oh=d3ad1774e5b7b50aeb4b570705e3904c&oe=60609A24"],
"post_url": "", "external_links": []}
]
Empty file added student_app/__init__.py
Empty file.
Binary file added student_app/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added student_app/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file added student_app/__pycache__/apps.cpython-37.pyc
Binary file not shown.
Binary file added student_app/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file added student_app/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file added student_app/__pycache__/views.cpython-37.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions student_app/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions student_app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class StudentAppConfig(AppConfig):
name = 'student_app'
Empty file.
Binary file not shown.
3 changes: 3 additions & 0 deletions student_app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
4 changes: 4 additions & 0 deletions student_app/my_posts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[{"published": "‏٢٦ فبراير‏، الساعة ‏٧:٠٤ م‏", "description": "المسابقة تنتهي الساعة 9 مساءً والاجابة تكون عن طريق رسائل الصفحة كالعادة ومرفقة بالاسم.\n يلا انطلقو😉", "images": ["https://scontent.fmji1-1.fna.fbcdn.net/v/t1.0-0/cp0/e15/q65/s261x260/154773728_2867525503518269_2606320992968188401_o.jpg?_nc_cat=103&ccb=3&_nc_sid=110474&_nc_ohc=d8eF4Aq8kTYAX8-2r3f&_nc_ht=scontent.fmji1-1.fna&tp=9&oh=a28120a582350304fff5cacb6894f645&oe=605F56C8"], "post_url": "", "external_links": [], "like_url": ""},
{"published": "‏٢٦ فبراير‏، الساعة ‏٦:٢٦ م‏", "description": "انتظرونا بعد اقل من ساعة✨", "images": ["https://scontent.fmji1-1.fna.fbcdn.net/v/t1.0-0/cp0/e15/q65/s261x260/154965462_2867504443520375_5129616373530031730_n.jpg?_nc_cat=110&ccb=3&_nc_sid=110474&_nc_ohc=T6fz1V9clBgAX9TYe7-&_nc_ht=scontent.fmji1-1.fna&tp=9&oh=ff3ed34bc181c9ed794c570ae1ba37a1&oe=60607EFB"], "post_url": "", "external_links": [], "like_url": ""},
{"published": "‏٢٤ فبراير‏، الساعة ‏٣:٢٧ م‏", "description": "في ظل متابعة اتحاد الطلبة للظروف الراهنة وحرصاً منّا على ضمان حقوق الطلبة عليه فقد تقدم اتحاد طلبة كلية التقنية الالكترونية الى السيد عميد الكلية يوم أمس الثلاثاء الموافق 23/02/2021 بمذكرة احتجاج بخصوص الظروف الحالية وذلك لايجاد حل مناسب للأوضاع الحالية. وكذلك نؤكد على متابعتنا للأمر الى حين التوصل الى حل.", "images": ["https://scontent.fmji1-1.fna.fbcdn.net/v/t1.0-0/cp0/e15/q65/p261x260/154329296_2865918933678926_496372120313000755_n.jpg?_nc_cat=104&ccb=3&_nc_sid=110474&_nc_ohc=9VniwNL8mHgAX-Mh0Xr&_nc_ht=scontent.fmji1-1.fna&tp=3&oh=d3ad1774e5b7b50aeb4b570705e3904c&oe=60609A24"], "post_url": "", "external_links": [], "like_url": ""},
]
15 changes: 15 additions & 0 deletions student_app/templates/student_app/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>contact</title>
</head>
<body>
<h1>HELLO FROM <span style="color: blue">Contact</span></h1>

<form method="post" action="{% url 'student_app:contact' %}">
{% csrf_token %}
<textarea name="message" placeholder="قم بوصف مشكلتك هنا"></textarea>
<input type="submit" >
</form>
</body>
</html>
14 changes: 14 additions & 0 deletions student_app/templates/student_app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>main</title>
</head>
<body>
<h1>HELLO FROM <span style="color: blue">INDEX</span></h1>
{% for feed in feeds %}
<h5>{{feed.description}}</h5>
{% endfor %}

<a href="{% url 'student_app:contact' %}">Contact us</a>
</body>
</html>
3 changes: 3 additions & 0 deletions student_app/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions student_app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from . import views

app_name = 'student_app'
urlpatterns = [
path('', views.index , name='index'),
path('contact/', views.contact, name='contact')
]
25 changes: 25 additions & 0 deletions student_app/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.shortcuts import render
from django.http import HttpResponse
import json
import codecs
from django.core.mail import send_mail
from django.conf import settings


def index(request):

with codecs.open('my_posts.json' , 'r' , 'utf-8') as f:
feeds = json.load(f)

context = {
'feeds':feeds,
}
return render(request, 'student_app/index.html' ,context)

def contact(request):

if request.method == 'POST':
message = request.POST['message']
send_mail('Contact Form',message,settings.EMAIL_HOST_USER,['[email protected]'],fail_silently=False,)

return render(request,'student_app/contact.html')
Empty file added student_site/__init__.py
Empty file.
Binary file added student_site/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added student_site/__pycache__/settings.cpython-37.pyc
Binary file not shown.
Binary file added student_site/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file added student_site/__pycache__/vari.cpython-37.pyc
Binary file not shown.
Binary file added student_site/__pycache__/wsgi.cpython-37.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions student_site/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for student_site project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'student_site.settings')

application = get_asgi_application()
132 changes: 132 additions & 0 deletions student_site/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
"""
Django settings for student_site project.
Generated by 'django-admin startproject' using Django 3.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
from . import vari


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = vari.secret

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = os.environ.get('EMAIL')
EMAIL_HOST_PASSWORD = os.environ.get('PASSWORD')
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'


ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'student_app.apps.StudentAppConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'student_site.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'student_site.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]




# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
22 changes: 22 additions & 0 deletions student_site/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""student_site URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include

urlpatterns = [
path('' , include('student_app.urls')),
path('admin/', admin.site.urls),
]
16 changes: 16 additions & 0 deletions student_site/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for student_site project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'student_site.settings')

application = get_wsgi_application()

0 comments on commit 764ff72

Please sign in to comment.