Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #9

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions MANIFEST
@@ -0,0 +1,19 @@
# file GENERATED by distutils, do NOT edit
setup.py
supra/__init__.py
supra/admin.py
supra/sockets.py
supra/supra.py
supra/views.py
supra/auths/__init__.py
supra/auths/oauth/__init__.py
supra/auths/oauth/admin.py
supra/auths/oauth/models.py
supra/templates/supra/delete.html
supra/templates/supra/form.html
supra/templates/supra/json.html
supra/templates/supra/list.html
supra/templatetags/__init__.py
supra/templatetags/__init__.pyc
supra/templatetags/filters.py
supra/templatetags/filters.pyc
2 changes: 2 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,2 @@
recursive-include supra/templates *
recursive-include supra/templatetags *
10 changes: 10 additions & 0 deletions PKG-INFO
@@ -0,0 +1,10 @@
Metadata-Version: 1.0
Name: supra
Version: 1.0.18
Summary: It's an easy JSON services generator
Home-page: https://github.com/luismoralesp/supra
Author: Luis Miguel Morales Pajaro
Author-email: luismiguel.mopa@gmail.com
License: Creative Common
Description: UNKNOWN
Platform: UNKNOWN
78 changes: 74 additions & 4 deletions README.md
Expand Up @@ -9,6 +9,10 @@ It's an easy JSON service generator, using the native django ListView class as b
pip install supra
```

##Documentation##

http://supra.readthedocs.io/

##Use##

###SupraListView###
Expand All @@ -17,7 +21,8 @@ It's a simple paginater JSON service. It shows a searchable list of registers pa
**Fields**
- *model:* Stipulate the model which will be shown, **it is mandatory**.
- *list_display:* Stipulate the field list to show of this model.
- *search_fields:* Stipulate the searchable field list.
- *list_filter:* Stipulate the searchable field list for multiples params.
- *search_fields:* Stipulate the searchable field list form single param.

**Example**

Expand All @@ -40,6 +45,7 @@ class MyModelListView(supra.SupraListView):
model = models.MyModel
list_display = ['field1', 'field2', 'field3']
search_fields = ['field1', 'field2']
list_filter = ['field1', 'field2']
#end class
```
*urls.py*
Expand All @@ -50,13 +56,46 @@ import views
urlpatterns = [
url(r'mymodel/list/', views.MyModelListView.as_view(), name="mymodel_list"),
]

```

*Query for multiple params*
```
/?field1=1
```

*Query for single param*
```
/?search=1
```

*Result*
```json
{"num_rows": 1, "object_list": [{"field1": "value1", "field2":"value2", "field3":"value3"}]}
```

Also you can use *field__field* instead field name as *list_display* as for *search_fiels*.
for change the search param's name you can use *search_key*.

*views.py*
```python
import supra
import models

class MyModelListView(supra.SupraListView):
model = models.MyModel
search_key = 'q'
list_display = ['field1', 'field2', 'field3']
search_fields = ['field1', 'field2']
list_filter = ['field1', 'field2']
#end class
```

*Query for single param*
```
/?q=1
```

Also you can use *field__field* instead field name as *list_display* as for *search_fiels* and *list_filter*.

*views.py*
```python
Expand All @@ -81,7 +120,7 @@ Sub class Renderer let you use friendly names for you JSON keys instead *field_

*views.py*
```python
import supra
from supra import views as supra
import models

class MyModelListView(supra.SupraListView):
Expand All @@ -102,7 +141,7 @@ class MyModelListView(supra.SupraListView):
You can paginate your service jus using the *paginate_by* attribute like this:

```python
import supra
from supra import views as supra
import models
class MyModelListView(supra.SupraListView):
model = models.MyModel
Expand Down Expand Up @@ -227,4 +266,35 @@ Also you can use the *SupraConf* class for configure for all like this
supra.SupraConf.body = True
```

##SupraSession##
let us create a easy Django login.

**Example**

*views.py*
```python
class MySupraSession(supra.SupraSession):
pass
#end class
```

*urls.py*
```python
urlpatterns = [
url(r'session/', supra.SupraSession.as_view()),
]
```

now you can login sending a POST request to the 'session/' url and logout senfing a DELETE request to the same url.

Also if want to validate one soesific user type you can use the model attribute for spesify wich user can be login with this url, liki this:

*views.py*
```python
class MySupraSession(supra.SupraSession):
model = models.MyUser
#end class
```

then only the MyUser users can login with that url.
That's all for now folks.
10 changes: 10 additions & 0 deletions build/bdist.linux-x86_64/wininst/PURELIB/supra-1.0.0.egg-info
@@ -0,0 +1,10 @@
Metadata-Version: 1.0
Name: supra
Version: 1.0.0
Summary: UNKNOWN
Home-page: https://github.com/luismoralesp/supra
Author: Luis Miguel Morales Pajaro
Author-email: luismiguel.mopa@gmail.com
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
10 changes: 10 additions & 0 deletions build/bdist.linux-x86_64/wininst/PURELIB/supra-1.0.18.egg-info
@@ -0,0 +1,10 @@
Metadata-Version: 1.0
Name: supra
Version: 1.0.18
Summary: It's an easy JSON services generator
Home-page: https://github.com/luismoralesp/supra
Author: Luis Miguel Morales Pajaro
Author-email: luismiguel.mopa@gmail.com
License: Creative Common
Description: UNKNOWN
Platform: UNKNOWN
10 changes: 10 additions & 0 deletions build/bdist.linux-x86_64/wininst/PURELIB/supra-1.0.19.egg-info
@@ -0,0 +1,10 @@
Metadata-Version: 1.0
Name: supra
Version: 1.0.19
Summary: It's an easy JSON services generator
Home-page: https://github.com/luismoralesp/supra
Author: Luis Miguel Morales Pajaro
Author-email: luismiguel.mopa@gmail.com
License: Creative Common
Description: UNKNOWN
Platform: UNKNOWN
1 change: 1 addition & 0 deletions build/bdist.linux-x86_64/wininst/PURELIB/supra.py
@@ -0,0 +1 @@
import supra
Empty file.
3 changes: 3 additions & 0 deletions build/bdist.linux-x86_64/wininst/PURELIB/supra/admin.py
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
42 changes: 42 additions & 0 deletions build/bdist.linux-x86_64/wininst/PURELIB/supra/sockets.py
@@ -0,0 +1,42 @@
import tornado.ioloop
import tornado.web
import tornado.websocket

from tornado.options import define, options, parse_command_line

define("port", default=8888, help="run on the given port", type=int)

# we gonna store clients in dictionary.
clients = dict()

class WebSocketHandler(tornado.websocket.WebSocketHandler):
def open(self, *args):
self.id = self.get_argument("Id")
self.stream.set_nodelay(True)
clients[self.id] = {"id": self.id, "object": self}
#end def

def check_origin(self, origin):
return True

def on_message(self, message):
msg = "Client %s received a message : %s" % (self.id, message)
self.write_message(msg)
print msg
#end def

def on_close(self):
if self.id in clients:
del clients[self.id]
#end if
#end def
#end class

app = tornado.web.Application([
(r'/', WebSocketHandler),
])

if __name__ == '__main__':
parse_command_line()
app.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
1 change: 1 addition & 0 deletions build/bdist.linux-x86_64/wininst/PURELIB/supra/supra.py
@@ -0,0 +1 @@
import views
@@ -0,0 +1,4 @@
<form action="" method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p>
<input type="submit" value="Confirm" />
</form>
@@ -0,0 +1,8 @@
<form action="" method="post">{% csrf_token %}
{{form.as_p}}
{% for fo in inlines %}
{{ fo.as_p }}
{% empty %}
{% endfor %}
<input type="submit" value="Send message" />
</form>
@@ -0,0 +1,13 @@
{
{% if page_obj.has_previous %}
"previous": {{ page_obj.previous_page_number }},
{% endif %}
{% if page_obj.has_next %}
"next": {{ page_obj.next_page_number }},
{% endif %}
"count": "{{paginator.count}}",
"num_pages": "{{paginator.num_pages}}",
"page_range": "{{paginator.page_range}}",
"num_rows": "{{num_rows}}",
"object_list": {{object_list}}
}
@@ -0,0 +1,45 @@
{% load filters %}
<!DOCTYPE html>
<html>
<head>
<title>Supra Template List</title>
</head>
<body>
<header>
<h1>Supra Template List</h1>
</header>
<section>
<code>
{% for obj in object_list%}
<details>
<summary>{{obj|strip}}</summary>
<p>{</p>
<ul>
{%for k,v in obj.items%}
<p>
"{{k}}":
{%if v|get_type == 'unicode' %}"{% endif %}{{v}}{%if v|get_type in 'unicode' %}"{% endif %}

</p>
{% endfor %}
</ul>
<p>}</p>
</details>

{% endfor %}
</code>
</section>
<section>
<form>
{% for field in search_fields%}
<p>
<label>{{field}}</label>
<input name="{{field}}">
</p>
{% endfor %}
<button>GET</button>
</form>
</section>

</body>
</html>
Empty file.
@@ -0,0 +1,18 @@
from django import template
import json
register = template.Library()


@register.filter
def get_type(value):
return type(value).__name__
#end def

@register.filter
def strip(dic):
stri = json.dumps(dic)
if len(stri) > 53:
stri = stri[:50] + "..."
#end if
return stri
#end def