Exemplo n.º 1
0
def viewer(request):
    paper_id = request.GET['id']
    result = Paper.objects.get(id=paper_id)
    cookie_data = request.COOKIES.get('id')
    if User.objects.filter(rand=cookie_data).exists():
        print "here i am"
        u = User.objects.get(rand=cookie_data)
        if View.objects.filter(user=u, pap=result).exists():
            pass
        else:
            d = View(user=u, pap=result)
            result.views += 1
            d.save()
    else:
        result.views += 1
        print result.views
    result.save()
    print "this is paper_id", paper_id
    url = result.paper_file.url
    title = result.title
    comment_list = get_paper_comments(paper_id)
    paper = {
        'url': url,
        'title': title,
        'comment_list': comment_list,
        'paper_id': paper_id,
        'views': result.views
    }
    return render(request, 'frame.html', {'paper': paper})
Exemplo n.º 2
0
def workspace_test():
	print_data('workspaces objects', br=False)

	for index in range(3):
		w = Workspace()
		w.name = 'New workspace name'
		w.description = 'Some new description'
		w.save()

	workspaces = Workspace.all()
	print_data('new objects -> model.all()', workspaces)

	w.name = 'Updated name'
	w.save()

	workspaces = Workspace.all()
	print_data('UPDATED -> model.all()', workspaces)

	workspaces = Workspace.get(id=w.id, name=w.name)
	print_data('GET -> model.get()', [workspaces])

	workspaces = Workspace.filter(name='New workspace name')
	print_data('FILTER -> model.filter()', workspaces)

	for index in range(2):
		o = Application()
		o.workspace_id = w.guid
		o.save()

	a = View()
	a.application_id = o.guid
	a.save()

	a = Resource()
	a.application_id = o.guid
	a.save()

	for index in range(3):
		o = Widget()
		o.workspace_id = w.guid
		o.save()

	for index in range(3):
		o = DataSource()
		o.workspace_id = w.guid
		o.save()

	objects = Workspace.all() + Resource.all() + Application.all() + Widget.all() + DataSource.all() + View.all()
	print_data('All objects in db', objects)

#	[w.delete() for w in Workspace.all()]
	workspaces = Workspace.all()
	print_data('cleaned', workspaces)

	workspaces = Workspace.filter(include_deleted=True)
	print_data('cleaned with deleted if exists', workspaces)

	objects = Workspace.all() + Resource.all() + Application.all() + Widget.all() + DataSource.all() + View.all()
	print_data('no objects left', objects)
Exemplo n.º 3
0
 def post(self):
     id = request.args['id']
     try:
         hacker = Hacker.get_by_id(id)
     except:
         abort(404, message = "Hacker not found")
     if hacker.next_proj.table == int(request.args['table']):
         try:
             View.create(hacker = hacker, project = hacker.next_proj)
             res = jsonify({"status" : "View recorded"})
             res.status_code = 201
             return res
         except:
             abort(409, message = "Unable to submit view")
     else:
         abort(409, message = "Submission and database mismatch")
Exemplo n.º 4
0
def viewer(request):
    paper_id = request.GET['id']
    result = Paper.objects.get(id=paper_id)
    cookie_data = request.COOKIES.get('id')
    if User.objects.filter(rand = cookie_data).exists():
        print "here i am"
        u=User.objects.get(rand=cookie_data)      
        if View.objects.filter(user=u,pap=result).exists():
            pass
        else:
            d=View(user=u,pap=result)
            result.views+=1
            d.save()
    else:
        result.views+=1
        print result.views
    result.save()
    print "this is paper_id",paper_id
    url=result.paper_file.url
    title = result.title
    comment_list = get_paper_comments(paper_id)
    paper = {'url': url, 'title': title,'comment_list': comment_list,'paper_id': paper_id,'views': result.views}
    return render(request, 'frame.html',{'paper': paper})
Exemplo n.º 5
0
 def post(self):
     id = request.args['id']
     table = request.args.get('table', None)
     try:
         hacker = Hacker.get_by_id(id)
     except:
         abort(404, message = "Hacker not found")
     hacker.updated_vote = datetime.datetime.utcnow()
     if table != None:
         try:
             hacker.own_proj = Project.get_by_id(table)
             View.create(hacker = hacker, project = hacker.own_proj)
         except:
             abort(404, message = "Project not found")
     try:
         hacker.save()
     except:
         abort(501, message = "Unable to create hacker entry")
     status = {"status": "Setup hacker to start voting"}
     if table != None:
         status["title"] = Project.get_by_id(table).name
     res = jsonify(status)
     res.status_code = 201
     return res
Exemplo n.º 6
0
    def get(self):
        self.response.headers['Content-Type'] = 'application/json'
        stream_name = self.request.get('stream_name')
        if not stream_name:
            return self.show_all_streams()
        stream = Stream.get_by_id(stream_name)
        if not stream:
            return self.error(404)

        # Increment View Count
        stream.view_count += 1
        stream.put()
        View(stream_id=stream.key).put()

        return self.response.out.write(
            json.dumps(stream.to_dict(), cls=MyEncoder))
Exemplo n.º 7
0
    def preferred_items(self, hacker):
        seen = {i.project.table for i in View.select().where(View.hacker == hacker)}
        # They haven't even seen the last one we gave them!
        if hacker.next_proj != None and hacker.next_proj.table not in seen:
            return [hacker.next_proj]
        if seen:
            items = Project.select().where(Project.active, ~Project.table.in_(seen))
        else:
            items = Project.select().where(Project.active)

        hackers = Hacker.select().where(Hacker.next_proj != None, Hacker.updated_vote != None)
        busy = {i.next_proj.table for i in hackers if ((datetime.datetime.utcnow() - i.updated_vote).total_seconds() < TIMEOUT * 60)}
        if busy:
            items = items.select().where(~Project.table.in_(busy))

        less_items = [i for i in items if len(i.views) < MIN_VIEWS]
        return less_items if less_items else [i for i in items]
Exemplo n.º 8
0
app = Application.get(guid=application_id)

if not app:
    self.action('goTo', ['/main'])

elif command in ['delete', 'update']:

    if 'view_id' not in args:
        raise Exception(u'View ID is not provided')

    for error_key, error_object in error_objects.items():
        error_object.action('setText', [''])

    view_id = args['view_id']
    app_view = View.get(guid=view_id, application_id=app.guid)

    if app_view:
        form_update = ViewUpdateForm(app_view)

        if command == 'delete':
            app_view.delete()
        else:
            form_update = ViewUpdateForm(
                app_view,
                name=args['input_title'],
                layout_xml=args['input_layout_xml'],
                logic_xml=args['input_logic_xml'],
            )
            if form_update.is_valid():
                form_update.save()
Exemplo n.º 9
0
from templates import (ACLViewTemplateCollection, ACLRoleTemplateCollection,
                       ACLRightTemplateCollection, ACLTableCollection)
from models import View, Role, Right, ACL
from collections import defaultdict

type = request.arguments.get('type', 'view')
object_id = request.arguments.get('object_id', '')
acl_table = session.get('acl_table')
acl_list = session.get('acl_list', {})

if type == 'view':
    view = View.get(guid=object_id)

    acl_views = acl_table.objects[0]
    acl_views.selected_id = view.guid
    acl_views.render()

    acl_roles = ACLRoleTemplateCollection()
    acl_roles.objects = view.roles
    view_role_acls = ACL.filter(object_id=view.guid)
    acl_roles.role_rights = defaultdict(int)
    for role_acl in view_role_acls:
        acl_roles.role_rights[role_acl.subject_id] += 1
    acl_roles.render()

    acl_table.objects = [acl_views, acl_roles]
    #role_rights

else:
    if type == 'role':
Exemplo n.º 10
0
from templates import ViewTemplateCollection
from models import View

app_id = request.arguments.get('id', '')

app_views = View.filter(application_id=app_id)

self.hpt_views.htmlcode = ViewTemplateCollection(app_views,
                                                 many=True,
                                                 add_new=True).html

self.cnt_view.dialog_create.form_create.application_id.value = app_id
Exemplo n.º 11
0
from models import View

application = View()
application.render()
Exemplo n.º 12
0
from models import View
from cgi import escape

view_id = request.arguments.get('view_id', '')
command = request.arguments.get('command', 'update')

app_view = View.get(guid=view_id)

if app_view:

	if command == 'play':
		# fill dov object with prerendered xml
		vdomxml, e2vdom = app_view.get_vdomxml()
		self.dialog_preview.dov_view.vdomxml = vdomxml
		self.dialog_preview.dov_view.vdomactions = e2vdom

		self.dialog_preview.show = '1'

	else:

		disabled = '2' if command == 'delete' else '0'

		form = self.dialog_update.form_update

		form.tab_view_detail.tab_params.input_title.value = app_view.name
		form.tab_view_detail.tab_params.input_title.mode = disabled
		form.tab_view_detail.tab_params.application_id.value = app_view.application_id
		form.tab_view_detail.tab_params.view_id.value = app_view.guid
		form.tab_view_detail.tab_params.command.value = command

		form.tab_view_detail.tab_layout.input_layout_xml.value = app_view.layout_xml or ""