diff --git a/requirements.txt b/requirements.txt index 31d5bc5..a9e33c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,17 @@ +dj-database-url==0.3.0 +dj-static==0.0.6 Django==1.8.2 django-bootstrap3==5.4.0 django-debug-toolbar==1.3.0 django-extensions==1.5.5 +django-toolbelt==0.0.1 +djangorestframework==3.1.3 fake-factory==0.5.1 +gnureadline==6.3.3 +gunicorn==19.3.0 ipython==3.1.0 psycopg2==2.6.1 +six==1.9.0 +sqlparse==0.1.15 +static3==0.6.1 Werkzeug==0.10.4 diff --git a/urlybird/.idea/.name b/urlybird/.idea/.name new file mode 100644 index 0000000..3aa37c8 --- /dev/null +++ b/urlybird/.idea/.name @@ -0,0 +1 @@ +urlybird \ No newline at end of file diff --git a/urlybird/.idea/misc.xml b/urlybird/.idea/misc.xml new file mode 100644 index 0000000..77c6986 --- /dev/null +++ b/urlybird/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/urlybird/.idea/modules.xml b/urlybird/.idea/modules.xml new file mode 100644 index 0000000..be78f5b --- /dev/null +++ b/urlybird/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/urlybird/.idea/urlybird.iml b/urlybird/.idea/urlybird.iml new file mode 100644 index 0000000..333a9fe --- /dev/null +++ b/urlybird/.idea/urlybird.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/urlybird/.idea/vcs.xml b/urlybird/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/urlybird/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/urlybird/.idea/workspace.xml b/urlybird/.idea/workspace.xml new file mode 100644 index 0000000..1668530 --- /dev/null +++ b/urlybird/.idea/workspace.xml @@ -0,0 +1,880 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + 1434647743579 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/urlybird/Procfile b/urlybird/Procfile new file mode 100644 index 0000000..da5bc49 --- /dev/null +++ b/urlybird/Procfile @@ -0,0 +1 @@ +web: gunicorn urlybird.wsgi --log-file - \ No newline at end of file diff --git a/urlybird/api/__init__.py b/urlybird/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/urlybird/api/admin.py b/urlybird/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/urlybird/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/urlybird/api/migrations/__init__.py b/urlybird/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/urlybird/api/models.py b/urlybird/api/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/urlybird/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/urlybird/api/permissions.py b/urlybird/api/permissions.py new file mode 100644 index 0000000..720fbb8 --- /dev/null +++ b/urlybird/api/permissions.py @@ -0,0 +1,25 @@ +from rest_framework import permissions + + +class IsOwnerOrReadOnly(permissions.BasePermission): + def has_object_permission(self, request, view, obj): + if request.method in permissions.SAFE_METHODS: + return True + else: + return request.user == obj.user + + +class OwnsRelatedBookmark(permissions.BasePermission): + def has_object_permission(self, request, view, obj): + return request.user == obj.bookmark.user + + +class IsUser(permissions.BasePermission): + def has_permission(self, request, view): + if request.method == "POST": + return request.user.is_anonymous() + else: + return True + + def has_object_permission(self, request, view, obj): + return request.user == obj diff --git a/urlybird/api/serializers.py b/urlybird/api/serializers.py new file mode 100644 index 0000000..a6c4692 --- /dev/null +++ b/urlybird/api/serializers.py @@ -0,0 +1,58 @@ +from rest_framework import serializers +from urly.models import Bookmark, Click +from rest_framework.fields import SerializerMethodField +from rest_framework.reverse import reverse +from django.contrib.auth.models import User +from rest_framework import serializers + + +class ClickSerializer(serializers.HyperlinkedModelSerializer): + user = serializers.PrimaryKeyRelatedField(read_only=True) + + class Meta: + model = Click + fields = ('user', 'bookmark') + + +class ClickWithBookmarkSerializer(serializers.HyperlinkedModelSerializer): + bookmark = serializers.HyperlinkedRelatedField(read_only=True, + view_name='click-detail') + + class Meta: + model = Click + fields = ('id', 'url', 'bookmark') + + +class BookmarkSerializer(serializers.HyperlinkedModelSerializer): + user = serializers.PrimaryKeyRelatedField(read_only=True) + clicks = ClickSerializer(many=True, read_only=True) + click_count = serializers.IntegerField(read_only=True) + _links = SerializerMethodField() + + def get__links(self, obj): + links = { + "clicks": reverse('click-list', kwargs=dict(bookmark_pk=obj.pk), + request=self.context.get('request'))} + return links + + class Meta: + model = Bookmark + fields = ('id', 'url', 'title', 'description', 'longurl', 'shorturl', 'user', 'clicks', 'click_count', '_links') + + +class UserSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = User + fields = ('url', 'username', 'password', 'email') + write_only_fields = ('password',) + + def create(self, validated_data): + user = User.objects.create( + username=validated_data['username'], + email=validated_data['email'] + ) + + user.set_password(validated_data['password']) + user.save() + + return user diff --git a/urlybird/api/tests.py b/urlybird/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/urlybird/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/urlybird/api/views.py b/urlybird/api/views.py new file mode 100644 index 0000000..cfa8e23 --- /dev/null +++ b/urlybird/api/views.py @@ -0,0 +1,58 @@ +from urly.models import Bookmark, Click +from api.serializers import BookmarkSerializer, ClickSerializer, ClickWithBookmarkSerializer, UserSerializer +from rest_framework import viewsets, permissions, generics, filters +from api.permissions import IsOwnerOrReadOnly, IsUser +from rest_framework.exceptions import PermissionDenied +from django.db.models import Count +from django.contrib.auth.models import User + + +class BookmarkViewSet(viewsets.ModelViewSet): + serializer_class = BookmarkSerializer + permission_classes = (permissions.IsAuthenticated, + IsOwnerOrReadOnly) + + def get_queryset(self): + return Bookmark.objects.filter(user=self.request.user).annotate( + click_count=Count('click', distinct=True)) + + def perform_create(self, serializer): + serializer.save(user=self.request.user) + + +class ClickViewSet(viewsets.ModelViewSet): + queryset = Click.objects.all() + serializer_class = ClickSerializer + permission_classes = (permissions.IsAuthenticatedOrReadOnly,) + + def perform_create(self, serializer): + serializer.save(user=self.request.user) + + +class ClickCreateView(generics.ListCreateAPIView): + permission_classes = (permissions.IsAuthenticated,) + serializer_class = ClickSerializer + + def initial(self, request, *args, **kwargs): + self.bookmark = Bookmark.objects.get(pk=kwargs['bookmark_pk']) + super().initial(request, *args, **kwargs) + + def get_queryset(self): + return self.bookmark.click_set.all() + + def perform_create(self, serializer): + if self.request.user != self.bookmark.user: + raise PermissionDenied + serializer.save(bookmark=self.bookmark) + + +class ClickDetailView(generics.RetrieveUpdateDestroyAPIView): + permission_classes = (permissions.IsAuthenticated,) + serializer_class = ClickWithBookmarkSerializer + queryset = Click.objects.all() + + +class UserViewSet(viewsets.ModelViewSet): + permission_classes = (IsUser,) + queryset = User.objects.all() + serializer_class = UserSerializer diff --git a/urlybird/manage.py b/urlybird/manage.py new file mode 100755 index 0000000..11b1039 --- /dev/null +++ b/urlybird/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "urlybird.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/urlybird/runtime.txt b/urlybird/runtime.txt new file mode 100644 index 0000000..d0d96e1 --- /dev/null +++ b/urlybird/runtime.txt @@ -0,0 +1 @@ +python-3.4.3 \ No newline at end of file diff --git a/urlybird/static/.gitkeep b/urlybird/static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/urlybird/urly/__init__.py b/urlybird/urly/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/urlybird/urly/admin.py b/urlybird/urly/admin.py new file mode 100644 index 0000000..27d84b3 --- /dev/null +++ b/urlybird/urly/admin.py @@ -0,0 +1,17 @@ +from django.contrib import admin +from .models import Bookmark, Click + +# Register your models here. +class BookmarkAdmin(admin.ModelAdmin): + fields = ['user', 'title', 'description', 'longurl', 'shorturl', 'count'] + list_display = ['title', 'longurl', 'shorturl'] + + +class ClickAdmin(admin.ModelAdmin): + class Meta: + fields = ['bookmark', 'timestamp'] + list_display = ['bookmark', 'timestamp'] + + +admin.site.register(Bookmark, BookmarkAdmin) +admin.site.register(Click, ClickAdmin) diff --git a/urlybird/urly/forms.py b/urlybird/urly/forms.py new file mode 100644 index 0000000..970c9ac --- /dev/null +++ b/urlybird/urly/forms.py @@ -0,0 +1,21 @@ +from django import forms +from django.contrib.auth.models import User +from .models import Bookmark + + +class UserForm(forms.ModelForm): + password = forms.CharField(widget=forms.PasswordInput()) + + class Meta: + model = User + fields = ('username', 'password',) + +class EditForm(forms.ModelForm): + class Meta: + model = Bookmark + fields = ('title', 'description', 'url',) + +class BookmarkForm(forms.ModelForm): + class Meta: + model = Bookmark + fields = ('url',) \ No newline at end of file diff --git a/urlybird/urly/migrations/0001_initial.py b/urlybird/urly/migrations/0001_initial.py new file mode 100644 index 0000000..8e0441e --- /dev/null +++ b/urlybird/urly/migrations/0001_initial.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Bookmark', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, verbose_name='ID', serialize=False)), + ('title', models.CharField(max_length=255)), + ('description', models.CharField(max_length=255)), + ('longurl', models.URLField()), + ('shorturl', models.CharField(max_length=8)), + ('time_created', models.DateTimeField(auto_now_add=True)), + ('user', models.ForeignKey(related_name='urly', to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.CreateModel( + name='Click', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, verbose_name='ID', serialize=False)), + ('timestamp', models.DateTimeField(auto_now_add=True)), + ('bookmark', models.ForeignKey(to='urly.Bookmark')), + ('user', models.ForeignKey(related_name='clicks', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/urlybird/urly/migrations/0002_auto_20150624_2212.py b/urlybird/urly/migrations/0002_auto_20150624_2212.py new file mode 100644 index 0000000..015ce28 --- /dev/null +++ b/urlybird/urly/migrations/0002_auto_20150624_2212.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + ('urly', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='click', + name='user', + field=models.ForeignKey(to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/urlybird/urly/migrations/__init__.py b/urlybird/urly/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/urlybird/urly/models.py b/urlybird/urly/models.py new file mode 100644 index 0000000..5096a22 --- /dev/null +++ b/urlybird/urly/models.py @@ -0,0 +1,68 @@ +from django.db import models +from django.contrib.auth.models import User +from faker import Factory +import random, string + +# Create your models here. + + +class Bookmark(models.Model): + user = models.ForeignKey(User, related_name="urly") + title = models.CharField(max_length=255) + description = models.CharField(max_length=255) + longurl = models.URLField() + shorturl = models.CharField(max_length=8) + time_created = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return self.shorturl + + +class Click(models.Model): + user = models.ForeignKey(User) + bookmark = models.ForeignKey(Bookmark) + timestamp = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return str(self.timestamp) + + +def create_user(): + for i in range(1, 31): + user = User.objects.create_user( + "user{}".format(i), + "user{}@theironyard.com".format(i), + "user{}".format(i) + ) + user.save() + + +def create_bookmarks(): + fake = Factory.create() + for user in User.objects.all(): + for _ in range(random.randint(1, 30)): + title = fake.word() + description = fake.sentence(nb_words=4) + longurl = fake.url() + shorturl = generate_shorturl() + time_created = fake.date_time_this_month() + #count = random.randrange(1, 51) + bookmark = Bookmark(user=user, title=title, description=description, longurl=longurl, shorturl=shorturl, + time_created=time_created) + bookmark.save() + + +def create_clicks(): + fake = Factory.create() + for bookmark in Bookmark.objects.all(): + for _ in range(random.randint(1, 50)): + user = random.choice(User.objects.all()) + timestamp = fake.date_time_this_month() + click = Click(user=user, bookmark=bookmark, timestamp=timestamp) + click.save() + + +def generate_shorturl(): + rand_char = string.ascii_letters + string.digits + unique_code = ''.join(random.choice(rand_char) for i in range(8)) + return unique_code diff --git a/urlybird/urly/templates/registration/login.html b/urlybird/urly/templates/registration/login.html new file mode 100644 index 0000000..3930ad7 --- /dev/null +++ b/urlybird/urly/templates/registration/login.html @@ -0,0 +1,35 @@ +{% extends "urly/base.html" %} + +{% block content %} + +{% if form.errors %} +

Your username and password didn't match. Please try again.

+{% endif %} + +{% if next %} + {% if user.is_authenticated %} +

Your account doesn't have access to this page. To proceed, + please login with an account that has access.

+ {% else %} +

Please login to see this page.

+ {% endif %} +{% endif %} + +
+{% csrf_token %} + + + + + + + + + +
{{ form.username.label_tag }}{{ form.username }}
{{ form.password.label_tag }}{{ form.password }}
+ + + +
+ +{% endblock %} \ No newline at end of file diff --git a/urlybird/urly/templates/registration/logout.html b/urlybird/urly/templates/registration/logout.html new file mode 100644 index 0000000..6a04e68 --- /dev/null +++ b/urlybird/urly/templates/registration/logout.html @@ -0,0 +1,7 @@ +{% extends "urly/base.html" %} + +{% block content %} + +

Logged out!

+ +{% endblock %} \ No newline at end of file diff --git a/urlybird/urly/templates/urly/base.html b/urlybird/urly/templates/urly/base.html new file mode 100644 index 0000000..505949b --- /dev/null +++ b/urlybird/urly/templates/urly/base.html @@ -0,0 +1,23 @@ + + + + + + + +
+

You are logged in as {{ user }}. + {% if user.is_anonymous %} + Login + {% else %} + Logout + {% endif %} +

+
+
+

URLY Bird

+
+{% block content %} +{% endblock %} + + \ No newline at end of file diff --git a/urlybird/urly/templates/urly/delete.html b/urlybird/urly/templates/urly/delete.html new file mode 100644 index 0000000..0bb0947 --- /dev/null +++ b/urlybird/urly/templates/urly/delete.html @@ -0,0 +1,13 @@ +{% extends "urly/base.html" %} + +{% block content %} +

Delete Bookmark

+

Title: {{ bookmark.title }}

+ +
+ {% csrf_token %} + + + +
+{% endblock %} diff --git a/urlybird/urly/templates/urly/edit_bookmark.html b/urlybird/urly/templates/urly/edit_bookmark.html new file mode 100644 index 0000000..0c89f28 --- /dev/null +++ b/urlybird/urly/templates/urly/edit_bookmark.html @@ -0,0 +1,13 @@ +{% extends "urly/base.html" %} + +{% block content %} +

Edit Bookmark

+

Title: {{ bookmark.title }}

+
+ {% csrf_token %} + {{ edit_form.as_p }} + + + +
+{% endblock %} \ No newline at end of file diff --git a/urlybird/urly/templates/urly/index.html b/urlybird/urly/templates/urly/index.html new file mode 100644 index 0000000..1250566 --- /dev/null +++ b/urlybird/urly/templates/urly/index.html @@ -0,0 +1,16 @@ +{% extends "urly/base.html" %} + +{% block content %} +

Bookmarks

+ + {% for bookmark in bookmarks %} +
+

+

+

+
+ {% endfor %} +{% endblock %} + \ No newline at end of file diff --git a/urlybird/urly/templates/urly/register.html b/urlybird/urly/templates/urly/register.html new file mode 100644 index 0000000..c572371 --- /dev/null +++ b/urlybird/urly/templates/urly/register.html @@ -0,0 +1,13 @@ +{% extends "urly/base.html" %} + +{% block content %} +

Register

+ +
+ {% csrf_token %} + {{ user_form.as_p }} + + + +
+{% endblock %} \ No newline at end of file diff --git a/urlybird/urly/templates/urly/shortenUrl.html b/urlybird/urly/templates/urly/shortenUrl.html new file mode 100644 index 0000000..32b6e9d --- /dev/null +++ b/urlybird/urly/templates/urly/shortenUrl.html @@ -0,0 +1,12 @@ +{% extends "urly/base.html" %} +{% load i18n %} + +{% block content %} +

{% trans 'Shorten URL' %}

+ +
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} \ No newline at end of file diff --git a/urlybird/urly/templates/urly/user.html b/urlybird/urly/templates/urly/user.html new file mode 100644 index 0000000..275e0b1 --- /dev/null +++ b/urlybird/urly/templates/urly/user.html @@ -0,0 +1,28 @@ +{% extends "urly/base.html" %} + +{% block content %} +

User: {{ bookmark.id }}

+ {% for bookmark in bookmarks %} +
+ +
+ {% endfor %} +{% endblock %} + \ No newline at end of file diff --git a/urlybird/urly/tests.py b/urlybird/urly/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/urlybird/urly/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/urlybird/urly/views.py b/urlybird/urly/views.py new file mode 100644 index 0000000..e0038a8 --- /dev/null +++ b/urlybird/urly/views.py @@ -0,0 +1,96 @@ +from django.shortcuts import render, redirect +from django.contrib.auth import authenticate, login +from .forms import UserForm, EditForm, BookmarkForm +from .models import Bookmark +from django.contrib import messages +import random +import string + + +# Create your views here. +def user_register(request): + if request.method == "GET": + user_form = UserForm() + elif request.method == "POST": + user_form = UserForm(request.POST) + if user_form.is_valid(): + user = user_form.save() + password = user.password + user.set_password(password) + user.save() + user = authenticate(username=user.username, + password=password) + login(request, user) + + return redirect('index') + return render(request, "urly/register.html", + {'user_form': user_form}) + + +def index(request): + bookmarks = Bookmark.objects.all() + return render(request, + "urly/index.html", + {"bookmarks": bookmarks}) + + +def edit_bookmark(request, bookmark_id): + bookmark = Bookmark.objects.get(pk=bookmark_id) + if request.method == "POST": + edit_form = EditForm(request.POST, instance=bookmark) + if edit_form.is_valid(): + new_bookmark = edit_form.save(commit=False) + new_bookmark.url = bookmark + new_bookmark.save() + messages.add_message(request, messages.SUCCESS, + "You have successfully changed the bookmark.") + + return redirect('edit_bookmark', request.user.id) + else: + edit_form = EditForm(instance=bookmark) + return render(request, + 'urly/edit_bookmark.html', + {'edit_form': edit_form, + 'bookmark': bookmark}) + + +def delete_bookmark(request, bookmark_id): + bookmark = Bookmark.objects.get(pk=bookmark_id) + if request.method == "POST": + messages.add_message(request, messages.SUCCESS, + "You have successfully deleted the bookmark.") + + bookmark.delete() + return redirect('index', request.user.id) + + return render(request, + 'urly/delete.html', + {'bookmark': bookmark}) + + +def redirect_to_site(request, bookmark_id): + short = Bookmark.objects.get(pk=bookmark_id) + short.count += 1 + short.save() + return redirect(short.url) + + +def shortenUrl(request): + rand_char = string.ascii_letters + string.digits + unique_code = ''.join(random.choice(rand_char) for i in range(8)) + + if request.method == "POST": + form = BookmarkForm(request.POST) + if form.is_valid(): + short = form.save(commit=False) + short.shorturl = unique_code + short.save() + + return redirect('shortenUrl', request.user.id) + + else: + form = BookmarkForm() + + return render(request, + 'urly/shortenUrl.html', + {'form': form}) diff --git a/urlybird/urlybird/__init__.py b/urlybird/urlybird/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/urlybird/urlybird/heroku_settings.py b/urlybird/urlybird/heroku_settings.py new file mode 100644 index 0000000..8759f06 --- /dev/null +++ b/urlybird/urlybird/heroku_settings.py @@ -0,0 +1,28 @@ +from .settings import * +import os + +DEBUG = False +SECRET_KEY = os.environ['SECRET_KEY'] + +BLACKLIST = ['debugtoolbar', 'django_extensions'] +INSTALLED_APPS = tuple([app for app in INSTALLED_APPS if app not in BLACKLIST]) + +# Parse database configuration from $DATABASE_URL +import dj_database_url +DATABASES['default'] = dj_database_url.config() + +# Honor the 'X-Forwarded-Proto' header for request.is_secure() +SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') + +# Allow all host headers +ALLOWED_HOSTS = ['*'] + +# Static asset configuration +import os +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +STATIC_ROOT = 'staticfiles' +STATIC_URL = '/static/' + +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, 'static'), +) diff --git a/urlybird/urlybird/settings.py b/urlybird/urlybird/settings.py new file mode 100644 index 0000000..5d515b9 --- /dev/null +++ b/urlybird/urlybird/settings.py @@ -0,0 +1,119 @@ +""" +Django settings for urlybird project. + +Generated by 'django-admin startproject' using Django 1.8.2. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.8/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '9!tnh+_^0n!8yhgl&w^p57emrs*k-_0ag696#wm^8n@g*1fy*6' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django_extensions', + 'rest_framework.authtoken', + 'rest_framework', + 'urly', +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django.middleware.security.SecurityMiddleware', +) + +ROOT_URLCONF = 'urlybird.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 = 'urlybird.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.8/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'urly', + 'USER': 'manish', + 'HOST': '127.0.0.1', + }, + 'sqlite3': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Internationalization +# https://docs.djangoproject.com/en/1.8/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/1.8/howto/static-files/ + +STATIC_URL = '/static/' + +LOGIN_REDIRECT_URL = '/index' + +REST_FRAMEWORK = { + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', + 'PAGE_SIZE': 20, +} diff --git a/urlybird/urlybird/static/.gitkeep b/urlybird/urlybird/static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/urlybird/urlybird/urls.py b/urlybird/urlybird/urls.py new file mode 100644 index 0000000..ae422f4 --- /dev/null +++ b/urlybird/urlybird/urls.py @@ -0,0 +1,34 @@ +"""urlybird URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.8/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Add an import: from blog import urls as blog_urls + 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) +""" +from django.conf.urls import include, url +from django.contrib import admin +# from urly import views as v +from rest_framework import routers +from api import views + +router = routers.DefaultRouter() +router.register(r'bookmarks', views.BookmarkViewSet, base_name="bookmark") +router.register(r'clicks', views.ClickViewSet, base_name="click") +router.register(r'users', views.UserViewSet) + +urlpatterns = [ + url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), + url(r'^', include(router.urls)), + url(r'^admin/', include(admin.site.urls)), + url('^', include('django.contrib.auth.urls')), + url(r'^bookmarks/(?P\d+)/clicks/$', views.ClickCreateView.as_view(), name="click-list"), + url(r'^clicks/(?P\d+)$', views.ClickDetailView.as_view(), name="click-detail"), +] diff --git a/urlybird/urlybird/wsgi.py b/urlybird/urlybird/wsgi.py new file mode 100644 index 0000000..b8b8e0f --- /dev/null +++ b/urlybird/urlybird/wsgi.py @@ -0,0 +1,23 @@ +""" +WSGI config for urlybird 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/1.8/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "urlybird.settings") + +#application = get_wsgi_application() + +## Heroku + +from django.core.wsgi import get_wsgi_application +from dj_static import Cling + +application = Cling(get_wsgi_application()) \ No newline at end of file