forked from sio2project/oioioi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I67c968af97ffded24e2eb6f7f31a86b0ed90b8a4
- Loading branch information
Marek Sommer
authored and
Gerrit Code Review
committed
Jun 23, 2015
1 parent
05d9182
commit 214f9da
Showing
17 changed files
with
483 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def get_tag_colors(tag): | ||
"""This function decides how to color a certain tag. | ||
For a given tag name (as a string), | ||
it returns a tuple of strings (background color, text color). | ||
For example, get_tag_colors('swag') may return ('#bac010', '#1e48c0'). | ||
It computes the background color basing on the tag name's hash. | ||
The text color is matched to the background color so that | ||
it will look as nice as it is possible on this background. | ||
""" | ||
color = hash(tag) % (256 * 256 * 256) | ||
colors = [((color // 256**i) % 256) for i in (0, 1, 2)] | ||
if sum(colors) > 128 * 3: | ||
textcolors = (0, 0, 0) | ||
else: | ||
textcolors = (255, 255, 255) | ||
return ('#' + ''.join('%02x' % i for i in colors), | ||
'#' + ''.join('%02x' % i for i in textcolors)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[ | ||
{ | ||
"pk": 1, | ||
"model": "problems.tag", | ||
"fields": { | ||
"name": "mrowkowiec" | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "problems.tag", | ||
"fields": { | ||
"name": "mrowka" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "problems.tagthrough", | ||
"fields": { | ||
"problem": 1, | ||
"tag": 1 | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
import re | ||
import django.core.validators | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('problems', '0004_problem_main_problem_instance'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Tag', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('name', models.CharField(unique=True, max_length=20, verbose_name='name', validators=[django.core.validators.MinLengthValidator(3), django.core.validators.MaxLengthValidator(20), django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+$'), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')])), | ||
], | ||
options={ | ||
'verbose_name': 'tag', | ||
'verbose_name_plural': 'tags', | ||
}, | ||
bases=(models.Model,), | ||
), | ||
migrations.CreateModel( | ||
name='TagThrough', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('problem', models.ForeignKey(to='problems.Problem')), | ||
('tag', models.ForeignKey(to='problems.Tag')), | ||
], | ||
options={ | ||
}, | ||
bases=(models.Model,), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='tagthrough', | ||
unique_together=set([('problem', 'tag')]), | ||
), | ||
migrations.AddField( | ||
model_name='tag', | ||
name='problems', | ||
field=models.ManyToManyField(to='problems.Problem', through='problems.TagThrough'), | ||
preserve_default=True, | ||
), | ||
migrations.CreateModel( | ||
name='MainProblemInstance', | ||
fields=[ | ||
], | ||
options={ | ||
'proxy': True, | ||
}, | ||
bases=('contests.probleminstance',), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
function init_tag_addition(id, hints_url) { | ||
$(function(){ | ||
var input = $('#' + id); | ||
var hints = $('#' + id + '-hints'); | ||
|
||
/* Prevent multiple-initialization */ | ||
if(input.data("init")) | ||
return; | ||
input.data("init", true); | ||
|
||
var changeInput = function() { | ||
var make_hint = function(tag, query) { | ||
var index = tag.indexOf(query); | ||
var pre = tag.substr(0, index); | ||
var mid = tag.substr(index, query.length); | ||
var suf = tag.substr(index + query.length); | ||
|
||
var label = $("<strong></strong>"); | ||
label.html(pre + "<u>" + mid + "</u>" + suf); | ||
label.click(function() { input.val(tag); changeInput(); }); | ||
label.css('cursor', 'pointer'); | ||
return label; | ||
}; | ||
|
||
var html_escape = function(str) { | ||
return String(str) | ||
.replace(/&/g, '&') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>'); | ||
}; | ||
|
||
var query = input.val(); | ||
|
||
if(query.length >= 2) { | ||
$.getJSON(hints_url, {substr: query}, | ||
function(items) { | ||
var exists = false; | ||
var hint_chain = $('<span></span>'); | ||
var count = 0; | ||
for(var i = 0; i < items.length; i++) { | ||
if(items[i] == query) | ||
exists = true; | ||
else { | ||
if(count !== 0) | ||
hint_chain.append(", "); | ||
else | ||
hint_chain.append(gettext("Try: ")); | ||
hint_chain.append(make_hint(items[i], query)); | ||
count++; | ||
} | ||
} | ||
if(!exists) { | ||
hints.html(gettext( | ||
"Tag '%(query)s' doesn't exist." + | ||
" It will be added if you save the problem.") | ||
.fmt({query: html_escape(query)}) + " "); | ||
} else { | ||
hints.html(gettext("Tag exists.") + " "); | ||
} | ||
hints.append(hint_chain); | ||
}); | ||
} else { | ||
hints.html(gettext("Type tag name.")); | ||
} | ||
}; | ||
|
||
input.keyup(changeInput); | ||
input.change(changeInput); | ||
|
||
changeInput(); | ||
}); | ||
} | ||
|
||
function init_tag_selection(id) { | ||
$(function(){ | ||
var input = $('#' + id); | ||
var form = $('#' + id + '-form'); | ||
input.typeahead({ | ||
source: function(query, process) { | ||
$.getJSON(input.data("hintsUrl"), {substr: query}, process); | ||
}, | ||
minLength: 2, | ||
updater: function(item) { | ||
input.val(item); | ||
form.submit(); | ||
return item; | ||
}, | ||
}); | ||
}); | ||
} |
Oops, something went wrong.