Adding projectrequest files

This commit is contained in:
Nathan Adams 2013-07-30 19:50:05 -05:00
parent f62d20f0d1
commit 2f981e42e5
5 changed files with 287 additions and 0 deletions

View File

@ -0,0 +1,72 @@
<?php
class IDF_Form_ProjectRequest extends Pluf_Form
{
public $user = null;
public function initFields($extra=array())
{
$choices = array();
$options = array(
'git' => __('git'),
'svn' => __('Subversion'),
'mercurial' => __('mercurial'),
'mtn' => __('monotone'),
);
foreach (Pluf::f('allowed_scm', array()) as $key => $class) {
$choices[$options[$key]] = $key;
}
$this->fields['shortname'] = new Pluf_Form_Field_Varchar(
array('required' => true,
'label' => __('Name'),
'initial' => '',
'help_text' => __('This will be the name of your repo and of your project - however - you can change the project name later.'),
));
$this->fields['repotype'] = new Pluf_Form_Field_Varchar(
array('required' => true,
'label' => __('Repository type'),
'initial' => 'git',
'widget_attrs' => array('choices' => $choices),
'widget' => 'Pluf_Form_Widget_SelectInput',
));
$this->fields['desc'] = new Pluf_Form_Field_Varchar(
array('required' => true,
'label' => __('Short description'),
'help_text' => __('A one line description of the project.'),
'initial' => '',
'widget_attrs' => array('size' => '35'),
));
$this->user = $extra['user'];
}
function save($commit=true)
{
if (!$this->isValid()) {
throw new Exception(__('Cannot save the model from an invalid form.'));
}
$checksql = new Pluf_SQL(sprintf("shortname='%s'", $this->cleaned_data['shortname']));
$requestcheck = Pluf::factory("IDF_Project")->getCount(array('filter'=>$checksql->gen()));
if ($requestcheck == 1)
return false;
try
{
$request = new IDF_ProjectRequest();
$request->shortname = $this->cleaned_data['shortname'];
$request->repotype = $this->cleaned_data['repotype'];
$request->desc = $this->cleaned_data['desc'];
$request->submitter = $this->user;
$request->create();
return true;
} catch (Exception $e)
{
return false;
}
}
}

View File

@ -0,0 +1,85 @@
<?php
/*
* This is the model for people to request a repo
* An administrator can then approve/deny the repo
*
*
*/
class IDF_ProjectRequest extends Pluf_Model
{
public $_model = __CLASS__;
function init()
{
$this->_a['table'] = 'idf_projectrequest';
$this->_a['model'] = __CLASS__;
$this->_a['cols'] = array(
// It is mandatory to have an "id" column.
'id' =>
array(
'type' => 'Pluf_DB_Field_Sequence',
'blank' => true,
),
'shortname' =>
array(
'type' => 'Pluf_DB_Field_Varchar',
'blank' => false,
'size' => 50,
'verbose' => __('shortname'),
'unique' => true,
),
'repotype' =>
array(
'type' => 'Pluf_DB_Field_Varchar',
'blank' => false,
'size' => 25,
'verbose' => __('Repository Type'),
),
'desc' =>
array(
'type' => 'Pluf_DB_Field_Varchar',
'blank' => false,
'size' => 250,
'verbose' => __('Description'),
),
'creation_dtime' =>
array(
'type' => 'Pluf_DB_Field_Datetime',
'blank' => true,
'verbose' => __('creation date'),
),
'submitter' =>
array(
'type' => 'Pluf_DB_Field_Foreignkey',
'model' => 'Pluf_User',
'blank' => false,
'verbose' => __('submitter'),
));
}
/**
* String representation of the abstract.
*/
function __toString()
{
return $this->shortname;
}
/**
* String ready for indexation.
*/
function _toIndex()
{
return '';
}
function preSave($create=false)
{
if ($this->id == '') {
$this->creation_dtime = gmdate('Y-m-d H:i:s');
}
}
}

View File

@ -0,0 +1,60 @@
{extends "idf/gadmin/base.html"}
{block request} class="active"{/block}
{block body}
{if $createdtext}
{$createdtext}
<br/>
<br/>
{/if}
{if $errors}
{foreach $errors as $error}
{$error}
{/foreach}
{/if}
<table>
<tr>
<th>
Short Name
</th>
<th>
Description
</th>
<th>
Repotype
</th>
<th>
Submitter
</th>
<th>
Date
</th>
<th>
Approve
</th>
</tr>
{foreach $requests as $req}
<tr>
<td>
{$req.shortname}
</td>
<td>
{$req.desc}
</td>
<td>
{$req.repotype}
</td>
<td>
{$req.get_submitter.login}
</td>
<td>
{$req.creation_dtime}
</td>
<td>
<a href="{url 'IDF_Views_Admin::projectRequestCreate'}{$req.id}/">Approve</a>
</td>
</tr>
{/foreach}
</table>
{/block}

View File

@ -0,0 +1,10 @@
Hello {$user},
You are receiving this email because you have requested a repository.
Your request for {$shortname|safe} was approved!
If you have any questions please feel free to email a member of the development team.
Yours faithfully,
The development team.

View File

@ -0,0 +1,60 @@
{extends "idf/base-simple.html"}
{block body}
{if $form.errors}
<div class="px-message-error">
<p>{trans 'Oops, please check the errors on the form.'}</p>
{if $form.get_top_errors}
{$form.render_top_errors|unsafe}
{/if}
</div>
{/if}
{if $success}
<div>
<p>
Thank you - your request has been received and will be approved by an admin shortly.
</p>
</div>
{/if}
{if $error}
<div class="px-message-error">
{$error}
</div>
{/if}
<form method="post" action=".">
<table class="form" summary="">
<tr>
<th><strong>{$form.f.shortname.labelTag}:</strong></th>
<td>{if $form.f.shortname.errors}{$form.f.shortname.fieldErrors}{/if}
{$form.f.shortname|unsafe}<br />
<span class="helptext">{$form.f.shortname.help_text}</span>
</td>
</tr>
<tr>
<th><strong>{$form.f.repotype.labelTag}:</strong></th>
<td>{if $form.f.repotype.errors}{$form.f.repotype.fieldErrors}{/if}
{$form.f.repotype|unsafe}<br />
<span class="helptext">{$form.f.repotype.help_text}</span>
</td>
</tr>
<tr>
<th><strong>{$form.f.desc.labelTag}:</strong></th>
<td>{if $form.f.desc.errors}{$form.f.desc.fieldErrors}{/if}
{$form.f.desc|unsafe}<br />
<span class="helptext">{$form.f.desc.help_text}</span>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Request Project" name="submit" /></td>
</tr>
</table>
</form>
{/block}
{block context}
{/block}