Commits

Lukasz Balcerzak committed 353dd67

Fixes #31 - added quickstart help rather than only showing creepy 'no changesets' found for empty repositories

Comments (0)

Files changed (5)

projector/templates/projector/project/repository/quickstart.html

+{% extends "projector/project/detail.html" %}
+
+{% load i18n %}
+{% load markup %}
+{% load native %}
+{% load projector_tags %}
+{% load richtemplates_tags %}
+
+{% block col-single-extra %}
+
+<div class="richtemplates-panel">
+    <h5>{% trans "Quickstart" %}</h5>
+    <div class="richtemplates-panel-content">
+        {% with project.get_repo_url|put_username_into_url:user as clone_url %}
+        {% if project.repository.alias == "hg" %}
+            {% include "projector/project/repository/quickstart_hg.html" %}
+        {% endif %}
+        {% if project.repository.alias == "git" %}
+            {% include "projector/project/repository/quickstart_git.html" %}
+        {% endif %}
+        {% endwith %}
+    </div>
+</div>
+
+{% endblock %}
+

projector/templates/projector/project/repository/quickstart_git.html

+{% load i18n %}
+{% load native %}
+
+<h1>{% trans "Git repository quickstart" %}</h1>
+
+<h2>{% trans "New repository" %}</h2>
+
+<div class="message message-info">
+{% blocktrans %}
+<p>
+    If you want to create new repository simply follow example below.
+</p>
+{% endblocktrans %}
+</div>
+
+{% highlight_block bash cssclass="code-highlight" %}
+git init {{ project.slug }}
+cd {{ project.slug }}
+echo "This is readme" >> README
+git add README
+git commit -m "Initial commit"
+git remote add origin {{ clone_url }}
+git push origin master
+{% endhighlight_block %}
+
+<h2>{% trans "Existing repo" %}</h2>
+
+{% blocktrans %}
+<div class="message message-info">
+<p>
+    If you already have repository and you wish to push it here
+    you would need to add remote to your repo and push it back.
+</p>
+{% endblocktrans %}
+</div>
+
+{% highlight_block bash cssclass="code-highlight" %}
+cd EXISTING_REPO_PATH
+git remote add origin {{ clone_url }}
+git push origin master
+{% endhighlight_block %}
+

projector/templates/projector/project/repository/quickstart_hg.html

+{% load i18n %}
+{% load native %}
+
+<h1>{% trans "Mercurial repository quickstart" %}</h1>
+
+<h2>{% trans "New repository" %}</h2>
+
+<div class="message message-info">
+{% blocktrans %}
+<p>If you want to create new repository simply follow example below.</p>
+{% endblocktrans %}
+</div>
+
+{% highlight_block bash cssclass="code-highlight" %}
+hg init {{ project.slug }}
+cd {{ project.slug }}
+echo "This is readme" >> README
+hg add README
+hg commit -m "Initial commit"
+echo -e "[paths]\ndefault={{ clone_url }}" >> .hg/hgrc
+hg push
+{% endhighlight_block %}
+
+<h2>{% trans "Existing repo" %}</h2>
+
+<div class="message message-info">
+{% blocktrans %}
+<p>
+    If you already have repository and you wish to push it here
+    you would need to add remote to your repo and push it back.
+</p>
+{% endblocktrans %}
+</div>
+
+{% highlight_block bash cssclass="code-highlight" %}
+cd EXISTING_REPO_PATH
+echo -e "[paths]\ndefault={{ clone_url }}" >> .hg/hgrc
+hg push
+{% endhighlight_block %}
+

projector/urls.py

         view='RepositoryFileDiff',
         name='projector_project_sources_diff'),
 
+    url(r'^(?P<username>[-\w]+)/(?P<project_slug>[-\w]+)/src/quickstart/$',
+        view='RepositoryQuickstart',
+        name='projector_project_sources_quickstart'),
+
     url(r'^(?P<username>[-\w]+)/(?P<project_slug>[-\w]+)/src/raw/(?P<revision>[\w]*)/(?P<rel_repo_url>.*)$',
         view='RepositoryFileRaw',
         name='projector_project_sources_raw'),

projector/views/project_repository.py

         if not self.project.repository_id:
             messages.info(self.request, _("Project has no repository"))
             response = redirect(self.project)
-        if not self.project._get_repo_path():
+        elif not self.project._get_repo_path() or \
+                self.project.repository is None:
             msg = _("There is something wrong with project's repository")
             messages.error(self.request, msg)
             response = redirect(self.project)
-        if not self.project.repository or not self.project.repository.revisions:
+        elif not self.project.repository.revisions:
             messages.info(self.request, _("Repository has no changesets yet"))
-            response = redirect(self.project)
+            return RepositoryQuickstart(self.request, *self.args, **self.kwargs)
         return response
 
     def get_error_response(self):
         return diff_changeset(self.request, **diff_info)
 
 
+class RepositoryQuickstart(RepositoryView):
+    """
+    Shows quickstart help for the project's repository.
+
+    **View attributes**
+
+    * ``template_name``: ``'projector/project/repository/quickstart.html'``.
+    """
+
+    template_name = 'projector/project/repository/quickstart.html'
+
+    def response(self, request, username, project_slug):
+        return self.context
+