Explorar el Código

Merged DrkSephy/django-hackathon-starter into default

Eswari Pravallika Swarna hace 10 años
padre
commit
b073049383

+ 22 - 194
README.md

@@ -34,15 +34,6 @@ Then:
 
 This will download and extract all the packages listed within `bower.json`. **Under no circumstance should any front-end libraries manually be pushed up to the repository.**
 
-Two routes have currently been set up, which are located at:
-
-    # First test route
-    http://127.0.0.1:8000/hackathon/
-
-    # Second test route
-    http://127.0.0.1:8000/hackathon/test
-
-
 ## Testing
 
 This project aims to be as close to 100% tested as possible. For a good guide to testing using Python and `Mock`, `Nosetests` and `Unittests` libraries, please [read here](http://docs.python-guide.org/en/latest/writing/tests/).
@@ -51,195 +42,32 @@ To run the tests:
 
     hackthon-starter $ python manage.py test hackathon/unittests/
 
-You will see an output as shown below:
-
-    Name                                   Stmts   Miss  Cover   Missing
-    --------------------------------------------------------------------
-    hackathon/__init__.py                      0      0   100%
-    hackathon/admin.py                         3      3     0%   1-5
-    hackathon/forms.py                         9      9     0%   1-11
-    hackathon/migrations/0001_initial.py       6      0   100%
-    hackathon/migrations/__init__.py           0      0   100%
-    hackathon/models.py                        6      6     0%   1-11
-    hackathon/scripts/__init__.py              0      0   100%
-    hackathon/scripts/github.py              106     96     9%   17-34, 41-64, 69-97, 102-121, 126-132, 139-165, 169-175
-    hackathon/scripts/linkedin.py             19     19     0%   1-24
-    hackathon/scripts/samplescript.py   NoSource: No source for code: '/Users/DrkSephy/Documents/django-hackathon-starter/hackathon_starter/hackathon/scripts/samplescript.py'.
-    hackathon/scripts/steam.py                15     15     0%   3-29
-    hackathon/scripts/tumblr.py               60     60     0%   1-85
-    hackathon/tests.py                         1      0   100%
-    hackathon/urls.py                          3      3     0%   1-5
-    hackathon/views.py                        76     76     0%   1-157
-    --------------------------------------------------------------------
-    TOTAL                                    304    287     6%
-    ----------------------------------------------------------------------
-    Ran 2 tests in 0.002s
-
-    OK
-    Destroying test database for alias 'default'...
-
 ## Code evaluation
 
 In order to write clean code with a consistent style guide, we'll be using `Pylint` to maintain our code. Pylint will display a ton of messages regarding things that should be fixed. A sample output from running `pylint views.py` is shown below:
 
-    (web)λ pylint views.py
-    No config file found, using default configuration
-    ************* Module hackathon.views
-    C:  7, 0: Trailing whitespace (trailing-whitespace)
-    W: 11, 0: Found indentation with tabs instead of spaces (mixed-indentation)
-    W: 12, 0: Found indentation with tabs instead of spaces (mixed-indentation)
-    W: 15, 0: Found indentation with tabs instead of spaces (mixed-indentation)
-    C: 59, 0: Wrong continued indentation.
-                'hackathon/register.html',
-                ^     | (bad-continuation)
-    C: 60, 0: Wrong continued indentation.
-                {'user_form': user_form, 'registered': registered} )
-                ^     | (bad-continuation)
-    C: 60, 0: No space allowed before bracket
-                {'user_form': user_form, 'registered': registered} )
-                                                                   ^ (bad-whitespace)
-    C: 69, 0: Line too long (103/100) (line-too-long)
-    C:116, 0: Exactly one space required after comma
-        return render(request,'hackathon/steam.html', {"game": game })
-                             ^ (bad-whitespace)
-    C:116, 0: No space allowed before bracket
-        return render(request,'hackathon/steam.html', {"game": game })
-                                                                    ^ (bad-whitespace)
-    C:  1, 0: Missing module docstring (missing-docstring)
-    W:  7, 0: Relative import 'scripts.steam', should be 'hackathon.scripts.steam' (relative-import)
-    C: 10, 0: Missing function docstring (missing-docstring)
-    C: 14, 0: Missing function docstring (missing-docstring)
-    W: 14, 9: Unused argument 'request' (unused-argument)
-    C: 17, 0: Missing function docstring (missing-docstring)
-    C: 21, 0: Missing function docstring (missing-docstring)
-    C: 62, 0: Missing function docstring (missing-docstring)
-    C:103, 0: Missing function docstring (missing-docstring)
-    C:110, 0: Missing function docstring (missing-docstring)
-    C:113, 4: Invalid variable name "SteamUN" (invalid-name)
-    C:114, 4: Invalid variable name "steamID" (invalid-name)
-    C:118, 0: Missing function docstring (missing-docstring)
-    W:  4, 0: Unused RequestContext imported from django.template (unused-import)
-    W:  4, 0: Unused loader imported from django.template (unused-import)
-
-
-    Report
-    ======
-    53 statements analysed.
-
-    Statistics by type
-    ------------------
-
-    +---------+-------+-----------+-----------+------------+---------+
-    |type     |number |old number |difference |%documented |%badname |
-    +=========+=======+===========+===========+============+=========+
-    |module   |1      |NC         |NC         |0.00        |0.00     |
-    +---------+-------+-----------+-----------+------------+---------+
-    |class    |0      |NC         |NC         |0           |0        |
-    +---------+-------+-----------+-----------+------------+---------+
-    |method   |0      |NC         |NC         |0           |0        |
-    +---------+-------+-----------+-----------+------------+---------+
-    |function |8      |NC         |NC         |0.00        |0.00     |
-    +---------+-------+-----------+-----------+------------+---------+
-
-
-
-    External dependencies
-    ---------------------
-    ::
-
-        django
-          \-contrib
-          | \-auth (hackathon.views)
-          \-http (hackathon.views)
-          \-shortcuts (hackathon.views)
-          \-template (hackathon.views)
-            \-loader (hackathon.views)
-        hackathon
-          \-forms (hackathon.views)
-          \-scripts
-            \-steam (hackathon.views)
-
-
-
-    Raw metrics
-    -----------
-
-    +----------+-------+------+---------+-----------+
-    |type      |number |%     |previous |difference |
-    +==========+=======+======+=========+===========+
-    |code      |59     |59.00 |NC       |NC         |
-    +----------+-------+------+---------+-----------+
-    |docstring |1      |1.00  |NC       |NC         |
-    +----------+-------+------+---------+-----------+
-    |comment   |29     |29.00 |NC       |NC         |
-    +----------+-------+------+---------+-----------+
-    |empty     |11     |11.00 |NC       |NC         |
-    +----------+-------+------+---------+-----------+
-
-
-
-    Duplication
-    -----------
-
-    +-------------------------+------+---------+-----------+
-    |                         |now   |previous |difference |
-    +=========================+======+=========+===========+
-    |nb duplicated lines      |0     |NC       |NC         |
-    +-------------------------+------+---------+-----------+
-    |percent duplicated lines |0.000 |NC       |NC         |
-    +-------------------------+------+---------+-----------+
-
-
-
-    Messages by category
-    --------------------
-
-    +-----------+-------+---------+-----------+
-    |type       |number |previous |difference |
-    +===========+=======+=========+===========+
-    |convention |18     |NC       |NC         |
-    +-----------+-------+---------+-----------+
-    |refactor   |0      |NC       |NC         |
-    +-----------+-------+---------+-----------+
-    |warning    |7      |NC       |NC         |
-    +-----------+-------+---------+-----------+
-    |error      |0      |NC       |NC         |
-    +-----------+-------+---------+-----------+
-
-
-
-    Messages
-    --------
-
-    +--------------------+------------+
-    |message id          |occurrences |
-    +====================+============+
-    |missing-docstring   |9           |
-    +--------------------+------------+
-    |mixed-indentation   |3           |
-    +--------------------+------------+
-    |bad-whitespace      |3           |
-    +--------------------+------------+
-    |unused-import       |2           |
-    +--------------------+------------+
-    |invalid-name        |2           |
-    +--------------------+------------+
-    |bad-continuation    |2           |
-    +--------------------+------------+
-    |unused-argument     |1           |
-    +--------------------+------------+
-    |trailing-whitespace |1           |
-    +--------------------+------------+
-    |relative-import     |1           |
-    +--------------------+------------+
-    |line-too-long       |1           |
-    +--------------------+------------+
-
-
-
-    Global evaluation
-    -----------------
-    Your code has been rated at 5.28/10
+
+## RESTful endpoints
+
+Using the `Django REST framework, the current RESTful endpoints exist:
+
+    http://127.0.0.1:8000/hackathon/snippets/
+
+The list will appear empty at first, since the database model `Snippets` will be empty. To populate it with some sample data, run the following:
+
+    python manage.py shell
+    from hackathon.models import Snippet
+    from hackathon.serializers import SnippetSerializer
+    from rest_framework.renderers import JSONRenderer
+    from rest_framework.parsers import JSONParser
+
+    snippet = Snippet(code='foo = "bar"\n')
+    snippet.save()
+
+    snippet = Snippet(code='print "hello, world"\n')
+    snippet.save()
+
+The above will open the Django shell, and allow you to create objects and save them to the database. If you then navigate to the URL above, you will see the JSON output of the database model, `Snippet`. 
 
 ## Contributors
 

+ 3 - 1
hackathon_starter/hackathon/admin.py

@@ -1,5 +1,7 @@
 from django.contrib import admin
-from hackathon.models import UserProfile
+from hackathon.models import UserProfile, Profile
 
 # Register your models here.
 admin.site.register(UserProfile)
+admin.site.register(Profile)
+

+ 15 - 1
hackathon_starter/hackathon/models.py

@@ -8,4 +8,18 @@ class UserProfile(models.Model):
 
     # Override the __unicode__() method to return out something meaningful!
     def __unicode__(self):
-        return self.user.username
+        return self.user.username
+
+class Profile(models.Model):
+    user = models.ForeignKey(User)
+    oauth_token = models.CharField(max_length=200)
+    oauth_secret = models.CharField(max_length=200)
+
+class Snippet(models.Model):
+    created = models.DateTimeField(auto_now_add=True)
+    title = models.CharField(max_length=100, blank=True, default='')
+    code = models.TextField()
+    linenos = models.BooleanField(default=False)
+
+    class Meta:
+        ordering = ('created',)

+ 9 - 0
hackathon_starter/hackathon/serializers.py

@@ -0,0 +1,9 @@
+from django.forms import widgets
+from rest_framework import serializers
+from hackathon.models import Snippet
+
+
+class SnippetSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = Snippet
+        fields = ('id', 'title', 'code', 'linenos')

+ 1 - 1
hackathon_starter/hackathon/templates/hackathon/login.html

@@ -30,7 +30,7 @@
           <i class="fa fa-facebook"></i>
           Sign in with Facebook
         </a>          
-        <a class="btn btn-block btn-social btn-twitter">
+        <a class="btn btn-block btn-social btn-twitter" href="http://127.0.0.1:8000/hackathon/twitter_login/">
           <i class="fa fa-twitter"></i>
           Sign in with Twitter
         </a>

+ 26 - 7
hackathon_starter/hackathon/templates/hackathon/steam.html

@@ -1,12 +1,31 @@
 <!DOCTYPE html>
 <html>
 <body>
-<table>
-  <tr><th>Game ID</th><th>Game Name</th><th>Minutes Played</th></tr>
-  {% for game in game %}
-    {% comment %}  each game object is a dictionary with "appid", "name " and "playtime_forever" keys {% endcomment %}
-    <tr><td>{{ game.appid }}</td><td>{{game.name}} </td><td>{{ game.playtime_forever }}</td></tr>
-{% endfor %}
-</table>
+	{% include 'hackathon/base.html' %}
+
+	<h1 class="text-center"> Steam API </h1>
+		<div class="col-lg-12">
+	        <div class="table-responsive">
+	            <table class="table table-bordered table-hover table-striped tablesorter">
+	                <thead>
+	                <tr>
+	                <th class="header"> Game ID <i class="icon-sort"></i></th>
+	                <th class="header"> Game Name <i class="icon-sort"></i></th>
+	                <th class="header"> Minutes Played <i class="icon-sort"></i></th>
+	            </thead>
+	            <tbody>
+
+	            {% for game in game %}
+	                <tr>
+	                    <td>{{ game.appid }}</td>
+	                    <td>{{ game.name }}</td>
+	                    <td>{{ game.playtime_forever }}</td>
+	    			</tr>
+	            {% endfor %}
+
+	            </tbody>
+	            </table>
+	        </div>
+	    </div>
 </body>
 </html>

+ 2 - 1
hackathon_starter/hackathon/urls.py

@@ -12,5 +12,6 @@ urlpatterns = patterns('',
     url(r'^steam/$', views.steam, name='steam'),
     url(r'^github/$', views.github, name='github'),
     url(r'^tumblr/$', views.tumblr, name='tumblr'),
-    url(r'^linkedin/$', views.linkedin, name='linkedin')
+    url(r'^linkedin/$', views.linkedin, name='linkedin'),
+    url(r'^snippets/$', views.snippet_list, name='snippets'),
 )

+ 38 - 2
hackathon_starter/hackathon/views.py

@@ -1,13 +1,30 @@
+# Django
 from django.shortcuts import render
-from hackathon.forms import UserForm
 from django.contrib.auth import logout
 from django.template import RequestContext, loader
 from django.contrib.auth import authenticate, login
 from django.http import HttpResponse, HttpResponseRedirect
+from django.conf import settings
+from django.contrib.auth import authenticate, login, logout
+from django.contrib.auth.models import User
+from django.contrib.auth.decorators import login_required
+from django.views.decorators.csrf import csrf_exempt
+
+# Scripts
 from scripts.steam import gamesPulling, steamIDPulling 
 from scripts.github import *
 from scripts.tumblr import *
-from django.conf import settings
+
+# Python
+import oauth2 as oauth
+from rest_framework.renderers import JSONRenderer
+from rest_framework.parsers import JSONParser
+
+# Models
+from hackathon.models import Snippet
+from hackathon.serializers import SnippetSerializer
+from hackathon.forms import UserForm
+
 
 getTumblr = TumblrOauthClient(settings.TUMBLR_CONSUMER_KEY, settings.TUMBLR_CONSUMER_SECRET)
 
@@ -115,3 +132,22 @@ def linkedin(request):
     context = {'title': 'linkedin Example','userdata': userinfo}
     return render(request, 'hackathon/linkedin.html', context)
 
+class JSONResponse(HttpResponse):
+    """
+    An HttpResponse that renders its content into JSON.
+    """
+    def __init__(self, data, **kwargs):
+        content = JSONRenderer().render(data)
+        kwargs['content_type'] = 'application/json'
+        super(JSONResponse, self).__init__(content, **kwargs)
+
+@csrf_exempt
+def snippet_list(request):
+    """
+    List all code snippets, or create a new snippet.
+    """
+    if request.method == 'GET':
+        snippets = Snippet.objects.all()
+        serializer = SnippetSerializer(snippets, many=True)
+        return JSONResponse(serializer.data)
+

+ 3 - 0
hackathon_starter/hackathon_starter/settings.py

@@ -40,6 +40,7 @@ INSTALLED_APPS = (
     'bootstrapform',
     # 'django_openid',
     'django_nose',
+    'rest_framework',
 )
 
 MIDDLEWARE_CLASSES = (
@@ -106,4 +107,6 @@ GITHUB_CLIENT_ID = 'client_id=2404a1e21aebd902f6db'
 GITHUB_CLIENT_SECRET = 'client_secret=3da44769d4b7c9465fa4c812669148a163607c23'
 TUMBLR_CONSUMER_KEY = 'KrSbAc9cYLmIgVAn1D21FjRR97QWsutNMxkPDFBxo8CMWtMk4M'
 TUMBLR_CONSUMER_SECRET ='lKWMtL2Lj8zr5pY51PVqT8ugeoG0DjrdgoFewM0QTSyJ12jP8d'
+TWITTER_TOKEN = 'F05dgLAzHEOalb4K2xDQ8Umm8'
+TWITTER_SECRET = 'Yy3a74Z7gvyhxRruJsvUtUl8uK8iv6qKkVqbZSijUxK71Z1qTY'
 

+ 5 - 3
requirements.txt

@@ -1,8 +1,7 @@
-Django==1.7.6
-PyTumblr==0.0.6
 astroid==1.3.6
 beautifulsoup4==4.3.2
 coverage==4.0a5
+Django==1.7.6
 django-bootstrap-form==3.2
 django-bootstrap-forms==0.1
 django-bower==5.0.2
@@ -13,9 +12,12 @@ logilab-common==0.63.2
 mock==1.0.1
 nose==1.3.4
 oauth2==1.5.211
+oauthlib==0.7.2
 pylint==1.4.3
 python-openid==2.2.5
+PyTumblr==0.0.6
 requests==2.6.0
+requests-oauthlib==0.4.2
 simplejson==3.6.5
 six==1.9.0
-wsgiref==0.1.2
+tweepy==3.3.0