This repository has been archived by the owner on Dec 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0254036
Showing
1,384 changed files
with
124,024 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Text backup files | ||
*.bak | ||
|
||
# Database | ||
*.sqlite3 | ||
|
||
# See the name for you IDE | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn mysite.wsgi --log-file - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# JackShen World | ||
The new version of my old project [ _dj-sample_](https://github.com/JackShen1/dj-samples). | ||
|
||
Here are some of my old and new projects on Django, as well as web design + web animation using HTML + CSS + JS. | ||
|
||
Now I'm using the Heroku server. You can check out my work here: https://jackshen.herokuapp.com. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.contrib import admin | ||
from ads.models import Ad | ||
|
||
# Register your models here. | ||
admin.site.register(Ad) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AdsConfig(AppConfig): | ||
name = 'ads' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django import forms | ||
from ads.models import Ad | ||
from django.core.files.uploadedfile import InMemoryUploadedFile | ||
from ads.humanize import naturalsize | ||
|
||
|
||
# Create the form class. | ||
class CreateForm(forms.ModelForm): | ||
max_upload_limit = 2 * 1024 * 1024 | ||
max_upload_limit_text = naturalsize(max_upload_limit) | ||
|
||
picture = forms.FileField(required=False, label='File to Upload <= ' + max_upload_limit_text) | ||
upload_field_name = 'picture' | ||
|
||
class Meta: | ||
model = Ad | ||
fields = ['title', 'price', 'text', 'picture'] # Picture is manual | ||
|
||
# Validate the size of the picture | ||
def clean(self): | ||
cleaned_data = super().clean() | ||
ad = cleaned_data.get('picture') | ||
if ad is None: return | ||
if len(ad) > self.max_upload_limit: | ||
self.add_error('picture', "File must be < " + self.max_upload_limit_text + " bytes") | ||
|
||
# Convert uploaded File object to a picture | ||
def save(self, commit=True): | ||
instance = super(CreateForm, self).save(commit=False) | ||
|
||
# We only need to adjust picture if it is a freshly uploaded file | ||
f = instance.picture # Make a copy | ||
if isinstance(f, InMemoryUploadedFile): # Extract data from the form to the model | ||
bytearr = f.read() | ||
instance.content_type = f.content_type | ||
instance.picture = bytearr # Overwrite with the actual image data | ||
|
||
if commit: | ||
instance.save() | ||
|
||
return instance | ||
|
||
|
||
class CommentForm(forms.Form): | ||
comment = forms.CharField(required=True, max_length=500, min_length=3, strip=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def naturalsize(count): | ||
fcount = float(count) | ||
k = 1024 | ||
m = k * k | ||
g = m * k | ||
if fcount < k: return str(count) + 'B' | ||
if k <= fcount < m: | ||
return str(int(fcount / (k / 10.0)) / 10.0) + 'KB' | ||
if m <= fcount < g: | ||
return str(int(fcount / (m / 10.0)) / 10.0) + 'MB' | ||
return str(int(fcount / (g / 10.0)) / 10.0) + 'GB' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 3.1 on 2020-08-26 18:35 | ||
|
||
from django.conf import settings | ||
import django.core.validators | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Ad', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=200, validators=[django.core.validators.MinLengthValidator(2, 'Title must be greater than 2 characters')])), | ||
('price', models.DecimalField(decimal_places=2, max_digits=7, null=True)), | ||
('text', models.TextField()), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 3.1 on 2020-08-30 12:25 | ||
|
||
from django.conf import settings | ||
import django.core.validators | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('ads', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='ad', | ||
name='content_type', | ||
field=models.CharField(help_text='The MIMEType of the file', max_length=256, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='ad', | ||
name='picture', | ||
field=models.BinaryField(editable=True, null=True), | ||
), | ||
migrations.CreateModel( | ||
name='Comment', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('text', models.TextField(validators=[django.core.validators.MinLengthValidator(3, 'Comment must be greater than 3 characters')])), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('ad', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ads.ad')), | ||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='ad', | ||
name='comments', | ||
field=models.ManyToManyField(related_name='comments_owned', through='ads.Comment', to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 3.1 on 2020-08-31 14:52 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('ads', '0002_auto_20200830_1525'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Fav', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('ad', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ads.ad')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'unique_together': {('ad', 'user')}, | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='ad', | ||
name='favorites', | ||
field=models.ManyToManyField(related_name='favorite_ads', through='ads.Fav', to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from django.db import models | ||
from django.core.validators import MinLengthValidator | ||
from django.contrib.auth.models import User | ||
from django.conf import settings | ||
|
||
|
||
class Ad(models.Model): | ||
title = models.CharField( | ||
max_length=200, | ||
validators=[MinLengthValidator(2, "Title must be greater than 2 characters")] | ||
) | ||
price = models.DecimalField(max_digits=7, decimal_places=2, null=True) | ||
text = models.TextField() | ||
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) | ||
comments = models.ManyToManyField(settings.AUTH_USER_MODEL, | ||
through='Comment', related_name='comments_owned') | ||
|
||
# Picture | ||
picture = models.BinaryField(null=True, editable=True) | ||
content_type = models.CharField(max_length=256, null=True, help_text='The MIMEType of the file') | ||
|
||
# Favorites | ||
favorites = models.ManyToManyField(settings.AUTH_USER_MODEL, through='Fav', related_name='favorite_ads') | ||
|
||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
# Shows up in the admin list | ||
def __str__(self): | ||
return self.title | ||
|
||
|
||
class Comment(models.Model): | ||
text = models.TextField( | ||
validators=[MinLengthValidator(3, "Comment must be greater than 3 characters")] | ||
) | ||
|
||
ad = models.ForeignKey(Ad, on_delete=models.CASCADE) | ||
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) | ||
|
||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
# Shows up in the admin list | ||
def __str__(self): | ||
if len(self.text) < 15: return self.text | ||
return self.text[:11] + ' ...' | ||
|
||
|
||
class Fav(models.Model): | ||
ad = models.ForeignKey(Ad, on_delete=models.CASCADE) | ||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) | ||
|
||
# https://docs.djangoproject.com/en/3.0/ref/models/options/#unique-together | ||
class Meta: | ||
unique_together = ('ad', 'user') | ||
|
||
def __str__(self) : | ||
return '%s likes %s'%(self.user.username, self.ad.title[:10]) |
Oops, something went wrong.