Skip to content

Commit

Permalink
sketching out a project proxy model per http://www.coactivate.org/pro…
Browse files Browse the repository at this point in the history
  • Loading branch information
ejucovy committed Apr 3, 2013
1 parent 9f1f80f commit d40021f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
Binary file modified thing.sqlite
Binary file not shown.
40 changes: 29 additions & 11 deletions thing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,15 @@ def dispatch(self, path_info):
lives exclusively at "/" (not /index.php)?
"""

for tool in self.project_tools():
new_path = tool.match_request(path_info)
if new_path is not None:
return tool.bind_request(new_path)

# Fallback tool
try:
return ProjectTool.objects.get(project=self, app='/').bind_request(path_info)
except ProjectTool.DoesNotExist:
return None
components = path_info.strip("/").split("/")
while components:
prefix = '/'.join([''] + components + [''])
try:
return self.proxies.get(path_prefix=prefix)
except ProjectProxy.DoesNotExist:
pass
components = components.pop(-1)
return None

class ProjectFeedSource(models.Model):

Expand Down Expand Up @@ -219,7 +218,26 @@ class Meta:
title = models.CharField('title', max_length=255)
url = models.CharField('url', max_length=255)



class ProjectProxy(models.Model):

class Meta:
verbose_name = _('project proxy')
verbose_name_plural = _('project proxies')
unique_together = [('project', 'path_prefix')]

project = models.ForeignKey(Project, verbose_name=_('project'),
related_name="proxies")
path_prefix = models.CharField(_('project proxy path prefix'),
max_length=50, db_index=True)
tool_dottedname = models.CharField(_('project proxy tool dotted name'),
max_length=50)
configuration = models.TextField(_('project proxy configuration'),
null=True, blank=True)

def get_tool(self):
return resolve(self.tool_dottedname)(self)

class ProjectTool(models.Model):

class Meta:
Expand Down
7 changes: 4 additions & 3 deletions thing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,11 @@ def __init__(self, base_url, path_info):
@csrf_exempt
@project_view
def projects_project_dispatch(request, slug, path_info):
tool = request.project.dispatch(path_info)
if tool is None:
proxy = request.project.dispatch(path_info)
if proxy is None:
return HttpResponse("404") # @@todo

tool = proxy.get_tool()

return HttpResponse(json.dumps({
"base_url": tool.url,
"script_name": tool.script_name,
Expand Down

0 comments on commit d40021f

Please sign in to comment.