Skip to content

Instantly share code, notes, and snippets.

@marc-hughes
Last active April 10, 2016 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marc-hughes/a68164051a4f9e619a8c4b563ab3e4e8 to your computer and use it in GitHub Desktop.
Save marc-hughes/a68164051a4f9e619a8c4b563ab3e4e8 to your computer and use it in GitHub Desktop.
angularmodule.filter("iterationToName", function() {
return function(iterationId, iterations) {
var iteration;
iteration = _.findWhere(iterations, {id: iterationId});
if (iteration != null) {
return iteration.name;
}
return "";
};
});
// ------------------------------------------------------------------------------------------------------------------------
var BetaOptions = (function () {
function BetaOptions(localStorage) {
this.localStorage = localStorage;
if (!localStorage.betaOptions) {
localStorage.betaOptions = {
textEditor: 'tinymce',
animations: true,
dashboard: 'dashboard',
dropbox: 'enabled'
};
}
}
BetaOptions.prototype.dropBox = function () {
return this.localStorage.betaOptions.dropbox != 'disabled';
};
BetaOptions.prototype.getTextEditor = function () {
return this.localStorage.betaOptions.textEditor;
};
BetaOptions.prototype.getAnimations = function () {
return this.localStorage.betaOptions.animations;
};
BetaOptions.prototype.getDashboard = function () {
return this.localStorage.betaOptions.dashboard;
};
BetaOptions.$inject = ["$localStorage"];
return BetaOptions;
})();
var SomeController = (function () {
function SomeController() {
}
})();
// Import express with body parsers (for handling JSON)
import express = require('express');
var bodyParser = require('body-parser');
// Business logic and data structures
interface IRegistration {
salutation: string;
name: string;
age: number;
}
class Registration implements IRegistration {
public salutation: string;
public name: string;
public age: number;
constructor(registration: IRegistration) {
this.salutation = registration.salutation;
this.name = registration.name;
this.age = registration.age;
}
public isValid() {
return this.age >= 18;
}
}
// Sample repository of registrations (for demo purposes just in memory
var registrations = new Array<IRegistration>();
registrations.push(
{ salutation: "Mr.", name: "Tom Tailor", age: 20 },
{ salutation: "Mr.", name: "Max Muster", age: 19 });
// var oneRegistration:IRegistration = registrations[0];
// oneRegistration.isValid();
// Setup express
var app = express();
app.use(bodyParser());
// Uncommend this line to demo basic auth
// app.use(express.basicAuth((user, password) => user == "user2" && password == "password"));
// Implement web API
app.get("/api/registrations", (req, res) => {
// Get all registrations
res.send(registrations);
});
// Register
app.post("/api/register", (req, res) => {
var registration = new Registration(<IRegistration>req.body);
if (registration.isValid()) {
registrations.push(registration);
res.send(201);
}
else {
res.send(400);
}
});
// Listen for HTTP traffic
app.listen(process.env.PORT || 3000);
from django.db import models, IntegrityError
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from apps.account.templatetags import account_tags
import logging
logger = logging.getLogger(__name__)
class Story(models.Model):
summary = models.TextField()
local_id = models.IntegerField()
created = models.DateTimeField(_('created'), auto_now_add=True)
modified = models.DateTimeField(_('modified'), auto_now=True)
assignee = models.ManyToManyField(User,
blank=True,
verbose_name=_('assignees'),
db_table='v2_projects_story_assignee_m2m',
related_name="assigned_stories")
points = models.CharField('points', max_length=3, default="?", blank=True)
iteration = models.ForeignKey("projects.Iteration", related_name="stories")
project = models.ForeignKey("projects.Project", related_name="stories")
assignees_cache = models.CharField(max_length=512, blank=True, null=True, default=None)
def clean_fields(self, exclude=None):
super(Story, self).clean_fields(exclude)
self.status = min(10, max(1, self.status))
@property
def assignees(self):
return self.assignee.all()
@assignees.setter
def assignees(self, value):
if self.id is None:
self.save() # Need to have an ID to set assignees
old_assignees = list(self.assignee.all())
for username in value.split(","):
username = username.strip()
# First, try to find the user's full name
eui = ExtraUserInfo.objects.filter(full_name=username)
for e in eui:
user = e.user
if self.project.hasReadAccess(user):
try:
self.assignee.add(user)
except IntegrityError:
pass # occasionally we got an error here because the person was already assigned.
# This username is seen, so remove it from old_assignees
old_assignees = [a for a in old_assignees if a.username != user.username]
# Then, try to look up by username
try:
user_obj = User.objects.get(username=username)
if self.project.hasReadAccess(user_obj):
try:
self.assignee.add(user_obj)
except IntegrityError:
pass # occasionally we got an error here because the person was already assigned.
old_assignees = [a for a in old_assignees if a.username != user_obj.username]
except User.DoesNotExist:
logger.warn("Could not find user %s" % username)
# old_assignees now contains users not seen in the new list, so remove them
for assignee in old_assignees:
self.assignee.remove( assignee )
self.resetAssigneeCache()
def resetAssigneeCache(self):
r = ""
for assignee in self.assignee.all():
if len(r) > 0:
r += ", "
r += account_tags.realname(assignee)
self.assignees_cache = r
class Meta:
app_label = 'projects'
db_table = "v2_projects_story"
unique_together = (("local_id", "project"),)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment