Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: sergiocharpineljr/ispdb
base: 5f16017563
...
head fork: sergiocharpineljr/ispdb
compare: 6d3e8a7cd2
  • 11 commits
  • 23 files changed
  • 0 commit comments
  • 2 contributors
View
256 ispdb/config/models.py
@@ -12,6 +12,8 @@
from django.contrib.auth.models import User
from django.conf import settings
from django.utils.translation import get_language_info
+from django.utils.functional import curry
+from django.utils.translation.trans_real import parse_accept_lang_header
import ispdb.audit as audit
class Domain(models.Model):
@@ -75,7 +77,7 @@ def __unicode__(self):
on_delete=models.SET_NULL)
last_update_datetime = models.DateTimeField(auto_now=True)
created_datetime = models.DateTimeField(auto_now_add=True)
- deleted_datetime = models.DateTimeField(null=True)
+ deleted_datetime = models.DateTimeField(null=True, blank=True)
CONFIG_CHOICES = [
("requested", "requested"),
("suggested", "suggested"),
@@ -84,8 +86,9 @@ def __unicode__(self):
("deleted", "deleted"),
]
status = models.CharField(max_length=20, choices = CONFIG_CHOICES)
- last_status = models.CharField(max_length=20, choices = CONFIG_CHOICES)
- email_provider_id = models.CharField(max_length=50)
+ last_status = models.CharField(max_length=20, choices = CONFIG_CHOICES,
+ blank=True)
+ email_provider_id = models.CharField(max_length=50, blank=True)
display_name = models.CharField(
max_length=100,
verbose_name="The name of this ISP",
@@ -169,6 +172,7 @@ def __unicode__(self):
flagged_as_incorrect = models.BooleanField()
flagged_by_email = models.EmailField(blank=True)
+ locked = models.BooleanField()
history = audit.AuditTrail()
@@ -187,27 +191,58 @@ class Issue(models.Model):
status = models.CharField(max_length=20, choices=STATUS_CHOICES,
default="open")
-class DocURL(models.Model):
+
+class CommonConfigURL(models.Model):
url = models.URLField(
- verbose_name="URL of the page describing these settings")
- config = models.ForeignKey(Config)
+ verbose_name="URL of the page")
+ config = models.ForeignKey(Config, related_name="%(class)s_set")
+
+ class Meta:
+ abstract = True
def __str__(self): return str(self.url)
def __unicode__(self): return self.url
-class DocURLDesc(models.Model):
+
+class CommonURLDesc(models.Model):
description = models.TextField(
max_length=100,
- verbose_name="Description of the settings page")
+ verbose_name="Description")
language = models.CharField(
max_length=10,
verbose_name="Language",
choices=settings.LANGUAGES)
- docurl = models.ForeignKey(DocURL, related_name="descriptions")
+
+ class Meta:
+ abstract = True
def __str__(self): return str(self.description)
def __unicode__(self): return self.description
+
+class DocURL(CommonConfigURL):
+ pass
+DocURL._meta.get_field('url').verbose_name = ("URL of the page describing "
+ "these settings")
+
+
+class DocURLDesc(CommonURLDesc):
+ docurl = models.ForeignKey(DocURL, related_name="descriptions")
+DocURLDesc._meta.get_field('description').verbose_name = ('Description of the '
+ 'settings page')
+
+
+class EnableURL(CommonConfigURL):
+ pass
+EnableURL._meta.get_field('url').verbose_name = ("URL of the page with enable "
+ "instructions")
+
+
+class EnableURLInst(CommonURLDesc):
+ enableurl = models.ForeignKey(EnableURL, related_name="instructions")
+EnableURLInst._meta.get_field('description').verbose_name = ('Instruction')
+
+
# Forms
def clean_port(self,field):
data = self.cleaned_data[field]
@@ -247,6 +282,18 @@ def clean(self, **kwargs):
self.errors.clear()
return cleaned_data
+ def save(self, commit=True):
+ super(DynamicModelForm, self).save(commit=False)
+ if commit:
+ # delete if exists
+ if self.cleaned_data and self.cleaned_data['DELETE']:
+ if self.instance.pk:
+ return self.instance.delete()
+ else:
+ return None
+ super(DynamicModelForm, self).save()
+ return self.instance
+
class DynamicBaseModelFormSet(BaseModelFormSet):
"""
@@ -287,17 +334,25 @@ class Meta:
fields = ['title', 'description']
-class DocURLDescForm(DynamicModelForm):
- class Meta:
- model = DocURLDesc
- exclude = ['docurl']
-
+class LanguageDescModelForm(DynamicModelForm):
+ """
+ A DynamicModelForm for classes with a language and a description fields
+ """
def __init__(self, *args, **kwargs):
- super(DocURLDescForm, self).__init__(*args, **kwargs)
- self.fields['description'].widget.attrs.update({'rows': 2, 'cols': 20})
+ http_accept_language = kwargs.pop('http_accept_language', '')
+ super(LanguageDescModelForm, self).__init__(*args, **kwargs)
+ self.fields['description'].widget.attrs.update({'rows': 1, 'cols': 20})
+ choices = []
+ # add HTTP_ACCEPTED_LANG first
+ if http_accept_language:
+ for code, q in parse_accept_lang_header(http_accept_language):
+ try:
+ li = get_language_info(code)
+ except:
+ continue
+ choices.append((code, li['name'] + ' - ' + li['name_local']))
# Redefine our choices, so we can add the translated language names and
# sort the list by language name
- choices = []
choices.append(self.fields['language'].choices[0])
langs = self.fields['language'].choices[1:]
langs.sort(key=lambda l: l[1].lower())
@@ -305,18 +360,13 @@ def __init__(self, *args, **kwargs):
li = get_language_info(code)
choices.append((code, lang + ' - ' + li['name_local']))
self.fields['language'].choices = choices
+ self.fields['language'].initial = choices[0]
- def save(self, commit=True):
- super(DocURLDescForm, self).save(commit=False)
- if commit:
- # delete if exists
- if self.cleaned_data and self.cleaned_data['DELETE']:
- if self.instance.pk:
- return self.instance.delete()
- else:
- return None
- super(DocURLDescForm, self).save()
- return self.instance
+
+class DocURLDescForm(LanguageDescModelForm):
+ class Meta:
+ model = DocURLDesc
+ exclude = ['docurl']
class BaseDocURLDescFormSet(DynamicBaseModelFormSet):
@@ -383,11 +433,17 @@ class BaseDocURLFormSet(DynamicBaseModelFormSet):
def __init__(self, *args, **kwargs):
kwargs['prefix'] = 'docurl'
+ # get request.META to add HTTP_ACCEPT_LANGUAGE on top of languages
+ # choices
+ meta = kwargs.pop('meta', {})
+ accept_lang = meta.get('HTTP_ACCEPT_LANGUAGE', '')
super(BaseDocURLFormSet, self).__init__(*args, **kwargs)
# construct description formsets
self.DocURLDescFormSet = modelformset_factory(DocURLDesc,
extra=self.extra, form=DocURLDescForm,
formset=BaseDocURLDescFormSet)
+ self.DocURLDescFormSet.form = staticmethod(curry(DocURLDescForm,
+ http_accept_language=accept_lang))
for index, form in enumerate(self.forms):
prefix = 'desc_%s' % index
data = self.data or None
@@ -437,6 +493,138 @@ def delete(self):
desc.instance.delete()
form.instance.delete()
+
+class EnableURLInstForm(LanguageDescModelForm):
+ class Meta:
+ model = EnableURLInst
+ exclude = ['enableurl']
+
+
+class BaseEnableURLInstFormSet(DynamicBaseModelFormSet):
+ model = EnableURLInst
+
+ def __init__(self, *args, **kwargs):
+ self.enableurl_delete = kwargs.pop('delete', False)
+ super(BaseEnableURLInstFormSet, self).__init__(*args, **kwargs)
+ # if enableurl is deleted, set required to false so they don't
+ # need to be filled
+ if self.enableurl_delete:
+ for form in self.forms:
+ for k, field in form.fields.iteritems():
+ field.required = False
+
+ def clean(self, **kwargs):
+ super(BaseEnableURLInstFormSet, self).clean(**kwargs)
+ if any(self.errors):
+ return
+ deleted_forms = 0
+ languages = []
+ for i in range(0, self.total_form_count()):
+ form = self.forms[i]
+ if (not form.cleaned_data) or form.cleaned_data['DELETE']:
+ deleted_forms += 1
+ continue
+ # Check for repeated languages
+ if form.cleaned_data['language'] in languages:
+ raise ValidationError("Duplicated language found.")
+ if form.cleaned_data['language'] != "Other":
+ languages.append(form.cleaned_data['language'])
+ # Check if all forms are deleted
+ if (not self.enableurl_delete) and (self.total_form_count() == 0 or
+ self.total_form_count() == deleted_forms):
+ raise ValidationError("At least one instruction should be "
+ "specified.")
+
+
+class EnableURLForm(DynamicModelForm):
+ class Meta:
+ model = EnableURL
+ fields = ['url']
+
+ def save(self, commit=True):
+ m = super(EnableURLForm, self).save(commit=False)
+ self.inst_formset.save(commit=False)
+ if commit:
+ if self.cleaned_data and self.cleaned_data['DELETE']:
+ # delete enableurl and instruction forms
+ if self.instance.pk:
+ for form in self.inst_formset:
+ if form.instance.pk:
+ form.instance.delete()
+ self.instance.delete()
+ return None
+ m = super(EnableURLForm, self).save()
+ for form in self.inst_formset:
+ form.instance.enableurl = m
+ self.inst_formset.save()
+ return m
+
+class BaseEnableURLFormSet(DynamicBaseModelFormSet):
+ model = EnableURL
+
+ def __init__(self, *args, **kwargs):
+ kwargs['prefix'] = 'enableurl'
+ # get request.META to add HTTP_ACCEPT_LANGUAGE on top of languages
+ # choices
+ meta = kwargs.pop('meta', {})
+ accept_lang = meta.get('HTTP_ACCEPT_LANGUAGE', '')
+ super(BaseEnableURLFormSet, self).__init__(*args, **kwargs)
+ # construct instructions formsets
+ self.EnableURLInstFormSet = modelformset_factory(EnableURLInst,
+ extra=self.extra, form=EnableURLInstForm,
+ formset=BaseEnableURLInstFormSet)
+ self.EnableURLInstFormSet.form = staticmethod(curry(EnableURLInstForm,
+ http_accept_language=accept_lang))
+ for index, form in enumerate(self.forms):
+ prefix = 'inst_%s' % index
+ data = self.data or None
+ delete = False
+ if self.queryset:
+ qs = EnableURLInst.objects.filter(enableurl=form.instance)
+ else:
+ qs = EnableURLInst.objects.none()
+ # if form is deleted, delete the instructions
+ if (self.data and
+ self.data.get(form.prefix+'-DELETE', '') == "True"):
+ delete = True
+ form.inst_formset = self.EnableURLInstFormSet(data=data,
+ prefix=prefix,
+ delete=delete,
+ queryset=qs)
+ # create a empty_desc_form
+ if self.forms:
+ self.empty_desc_form = self.forms[0].inst_formset.empty_form
+ else:
+ formset = self.EnableURLInstFormSet()
+ self.empty_desc_form = formset.empty_form
+
+ def clean(self, **kwargs):
+ super(BaseEnableURLFormSet, self).clean(**kwargs)
+ if any(self.errors):
+ return
+ urls = []
+ for i in range(0, self.total_form_count()):
+ form = self.forms[i]
+ if (not form.cleaned_data) or form.cleaned_data['DELETE']:
+ continue
+ # Check for repeated urls
+ if form.cleaned_data['url'] in urls:
+ raise ValidationError("Duplicated URL found.")
+ urls.append(form.cleaned_data['url'])
+
+ def is_valid(self, *args, **kwargs):
+ result = super(BaseEnableURLFormSet, self).is_valid(*args, **kwargs)
+ for form in self.forms:
+ result = result and form.inst_formset.is_valid()
+ return result
+
+ def delete(self):
+ for form in self.forms:
+ for inst in form.inst_formset:
+ inst.instance.delete()
+ form.instance.delete()
+
+
class DomainForm(DynamicModelForm):
class Meta:
fields = ('name',)
@@ -553,6 +741,7 @@ class Meta:
'outgoing_add_this_server',
'outgoing_use_global_preferred_server',
'owner',
+ 'locked',
]
incoming_type = ChoiceField(widget=RadioSelect,
choices=Config.INCOMING_TYPE_CHOICES)
@@ -560,10 +749,13 @@ class Meta:
def __init__(self, *args, **kwargs):
self.domain_formset = kwargs.pop('domain_formset', None)
self.docurl_formset = kwargs.pop('docurl_formset', None)
+ self.enableurl_formset = kwargs.pop('enableurl_formset', None)
if not self.domain_formset:
raise(Exception('Domain formset required.'))
if not self.docurl_formset:
raise(Exception('DocURL formset required.'))
+ if not self.enableurl_formset:
+ raise(Exception('EnableURL formset required.'))
super(ConfigForm, self).__init__(*args, **kwargs)
def clean_incoming_port(self):
@@ -575,7 +767,8 @@ def clean_outgoing_port(self):
def is_valid_all(self, *args, **kwargs):
return (self.is_valid(*args, **kwargs) and
self.domain_formset.is_valid(*args, **kwargs) and
- self.docurl_formset.is_valid(*args, **kwargs))
+ self.docurl_formset.is_valid(*args, **kwargs) and
+ self.enableurl_formset.is_valid(*args, **kwargs))
def save_all(self, *args, **kwargs):
super(ConfigForm, self).save(*args, **kwargs)
@@ -589,3 +782,8 @@ def save_all(self, *args, **kwargs):
for form in self.docurl_formset:
form.instance.config = self.instance
self.docurl_formset.save()
+ # Save EnableURL formset
+ self.enableurl_formset.save(commit=False)
+ for form in self.enableurl_formset:
+ form.instance.config = self.instance
+ self.enableurl_formset.save()
View
8 ispdb/config/serializers.py
@@ -69,6 +69,14 @@ def xmlOneDotOne(data):
text = unicode(text)
e.text = text
+ # EnableURL
+ for enableurl in data.enableurl_set.all():
+ enable = ET.SubElement(emailProvider, "enable")
+ enable.attrib["visiturl"] = enableurl.url
+ for inst in enableurl.instructions.all():
+ d = ET.SubElement(enable, "instruction")
+ d.attrib["lang"] = inst.language
+ d.text = unicode(inst.description)
# DocURL
for docurl in data.docurl_set.all():
doc = ET.SubElement(emailProvider, "documentation")
View
15 ispdb/config/static/css/enter_config.css
@@ -6,11 +6,6 @@
#domain_list table {
max-width: 40em;
}
-#add_domain {
- position: absolute;
- bottom: 1em;
- right: 1em;
-}
input[readonly=readonly] {
color: grey;
background-color:#F0F0F0;
@@ -33,15 +28,7 @@ input[readonly=readonly] {
}
table.tab_descs td, table.tab_descs th,
+table.tab_insts td, table.tab_insts th,
td.noborder, th.noborder {
border-bottom: 0px;
}
-
-.add_desc {
- font-size: 12px;
-}
-
-#add_docurl {
- padding-top: 10px;
- padding-bottom: 10px;
-}
View
112 ispdb/config/views.py
@@ -25,7 +25,8 @@
from ispdb.config.models import (Config, ConfigForm, Domain, DomainForm,
DomainRequest, BaseDomainFormSet, Issue, IssueForm, DocURL, DocURLDesc,
- BaseDocURLFormSet, DocURLForm, DocURLDescForm, BaseDocURLDescFormSet)
+ BaseDocURLFormSet, DocURLForm, DocURLDescForm, BaseDocURLDescFormSet,
+ EnableURL, EnableURLForm, BaseEnableURLFormSet)
from ispdb.config import serializers
from ispdb.config.configChecks import do_domain_checks
from ispdb.config.configChecks import do_config_checks
@@ -107,6 +108,10 @@ def details(request, id, error=None):
DocURLFormSet = modelformset_factory(DocURL, extra=0,
form=DocURLForm, formset=BaseDocURLFormSet)
docurl_formset = DocURLFormSet(queryset=config.docurl_set.all())
+ # Enable URLs
+ EnableURLFormSet = modelformset_factory(EnableURL, extra=0,
+ form=EnableURLForm, formset=BaseEnableURLFormSet)
+ enableurl_formset = EnableURLFormSet(queryset=config.enableurl_set.all())
return render_to_response("config/details.html", {
'config': config,
'incoming': incoming,
@@ -114,7 +119,8 @@ def details(request, id, error=None):
'other_fields': other_fields,
'error': error,
'issues': config.reported_issues.filter(status="open"),
- 'docurls': docurl_formset},
+ 'docurls': docurl_formset,
+ 'enableurls': enableurl_formset},
context_instance=RequestContext(request))
def export_xml(request, version=None, id=None, domain=None):
@@ -137,6 +143,10 @@ def edit(request, config_id):
(config.status == 'requested' or config.status == 'suggested')
and config.owner == request.user)):
return HttpResponseRedirect(reverse('ispdb_login'))
+ if config.locked:
+ error = ("This configuration is locked. Only admins can unlock "
+ "it.")
+ return details(request, config.id, error=error)
# Get initial data
if config.domains.all():
model = Domain
@@ -149,6 +159,9 @@ def edit(request, config_id):
DocURLFormSet = modelformset_factory(DocURL, extra=0,
form=DocURLForm, formset=BaseDocURLFormSet)
docurl_queryset = config.docurl_set.all()
+ EnableURLFormSet = modelformset_factory(EnableURL, extra=0,
+ form=EnableURLForm, formset=BaseEnableURLFormSet)
+ enableurl_queryset = config.enableurl_set.all()
if request.method == 'POST':
data = request.POST
@@ -156,12 +169,15 @@ def edit(request, config_id):
domain_formset = DomainFormSet(request.POST, request.FILES,
queryset=domain_queryset)
docurl_formset = DocURLFormSet(request.POST, request.FILES,
- queryset=docurl_queryset)
+ queryset=docurl_queryset, meta=request.META)
+ enableurl_formset = EnableURLFormSet(request.POST, request.FILES,
+ queryset=enableurl_queryset, meta=request.META)
config_form = ConfigForm(request.POST,
request.FILES,
instance=config,
domain_formset=domain_formset,
- docurl_formset=docurl_formset)
+ docurl_formset=docurl_formset,
+ enableurl_formset=enableurl_formset)
if config_form.is_valid_all():
config_form.save_all()
if config.status == 'suggested':
@@ -171,11 +187,15 @@ def edit(request, config_id):
return HttpResponseRedirect(reverse('ispdb_details',
args=[config.id]))
else:
- docurl_formset = DocURLFormSet(queryset=docurl_queryset)
+ docurl_formset = DocURLFormSet(queryset=docurl_queryset,
+ meta=request.META)
+ enableurl_formset = EnableURLFormSet(queryset=enableurl_queryset,
+ meta=request.META)
domain_formset = DomainFormSet(queryset=domain_queryset)
config_form = ConfigForm(instance=config,
domain_formset=domain_formset,
- docurl_formset=docurl_formset)
+ docurl_formset=docurl_formset,
+ enableurl_formset=enableurl_formset)
return render_to_response('config/enter_config.html', {
'config_form': config_form,
@@ -191,20 +211,25 @@ def add(request, domain=None):
form=DomainForm, formset=BaseDomainFormSet)
DocURLFormSet = modelformset_factory(DocURL, extra=1, form=DocURLForm,
formset=BaseDocURLFormSet)
+ EnableURLFormSet = modelformset_factory(EnableURL, extra=1,
+ form=EnableURLForm, formset=BaseEnableURLFormSet)
action = 'add'
has_errors = False
if request.method == 'POST': # If the form has been submitted...
data = request.POST
docurl_formset = DocURLFormSet(request.POST, request.FILES,
- queryset=DocURL.objects.none())
+ queryset=DocURL.objects.none(), meta=request.META)
+ enableurl_formset = EnableURLFormSet(request.POST, request.FILES,
+ queryset=EnableURL.objects.none(), meta=request.META)
domain_formset = DomainFormSet(request.POST, request.FILES,
queryset=DomainRequest.objects.none())
# did the user fill in a full form, or are they just asking for some
# domains to be registered
if data['asking_or_adding'] == 'asking':
config_form = ConfigForm(domain_formset=domain_formset,
- docurl_formset=docurl_formset)
+ docurl_formset=docurl_formset,
+ enableurl_formset=enableurl_formset)
action = 'ask'
if domain_formset.is_valid():
domain_formset.save(commit=False)
@@ -225,7 +250,8 @@ def add(request, domain=None):
request.FILES,
instance=config,
domain_formset=domain_formset,
- docurl_formset=docurl_formset)
+ docurl_formset=docurl_formset,
+ enableurl_formset=enableurl_formset)
# All validation rules pass
if config_form.is_valid_all():
config_form.save_all()
@@ -234,12 +260,15 @@ def add(request, domain=None):
else:
has_errors = True
else:
- docurl_formset = DocURLFormSet(queryset=DocURL.objects.none())
+ docurl_formset = DocURLFormSet(queryset=DocURL.objects.none(),
+ meta=request.META)
+ enableurl_formset = EnableURLFormSet(queryset=EnableURL.objects.none(),
+ meta=request.META)
domain_formset = DomainFormSet(initial=[{'name': domain}],
queryset=DomainRequest.objects.none())
config_form = ConfigForm(domain_formset=domain_formset,
- docurl_formset=docurl_formset)
-
+ docurl_formset=docurl_formset,
+ enableurl_formset=enableurl_formset)
return render_to_response('config/enter_config.html', {
'config_form': config_form,
'action': action,
@@ -265,6 +294,10 @@ def policy(request):
@permission_required("config.can_approve")
def approve(request, id):
config = get_object_or_404(Config, pk=id)
+ if config.locked:
+ error = ("This configuration is locked. Only admins can unlock "
+ "it.")
+ return details(request, config.id, error=error)
old_status = config.status
message = ''
if request.method == 'POST': # If the form has been submitted...
@@ -337,6 +370,10 @@ def delete(request, id):
(config.status == 'requested' or config.last_status == 'requested')
and config.owner == request.user)):
return HttpResponseRedirect(reverse('ispdb_login'))
+ if config.locked:
+ error = ("This configuration is locked. Only admins can unlock "
+ "it.")
+ return details(request, id, error=error)
if request.method == 'POST':
data = request.POST
if data.has_key('delete') and data['delete'] == "delete":
@@ -371,20 +408,26 @@ def report(request, id):
DocURLFormSet = modelformset_factory(DocURL, extra=0,
form=DocURLForm, formset=BaseDocURLFormSet)
docurl_queryset = config.docurl_set.all()
+ EnableURLFormSet = modelformset_factory(EnableURL, extra=0,
+ form=EnableURLForm, formset=BaseEnableURLFormSet)
+ enableurl_queryset = config.enableurl_set.all()
if request.method == 'POST':
data = request.POST
domain_formset = DomainFormSet(request.POST, request.FILES,
queryset=domain_queryset)
docurl_formset = DocURLFormSet(request.POST, request.FILES,
- queryset=docurl_queryset)
+ queryset=docurl_queryset, meta=request.META)
+ enableurl_formset = EnableURLFormSet(request.POST, request.FILES,
+ queryset=enableurl_queryset, meta=request.META)
p_config = Config(owner=request.user, status='suggested')
issue = Issue(config=config, owner=request.user)
config_form = ConfigForm(request.POST,
request.FILES,
instance=p_config,
domain_formset=domain_formset,
- docurl_formset=docurl_formset)
+ docurl_formset=docurl_formset,
+ enableurl_formset=enableurl_formset)
issue_form = IssueForm(request.POST, instance=issue)
if issue_form.is_valid():
if issue_form.cleaned_data['show_form']:
@@ -415,6 +458,21 @@ def report(request, id):
desc_form.cleaned_data['DELETE']):
continue
docurl_formset.save()
+ # Save EnableURL formset
+ enableurl_formset.save(commit=False)
+ for form in enableurl_formset:
+ form.instance.pk = None
+ if not form.cleaned_data or (
+ form.cleaned_data['DELETE']):
+ continue
+ form.instance.config = p_config
+ for inst_form in form.inst_formset:
+ inst_form.instance.pk = None
+ if not inst_form.cleaned_data or (
+ inst_form.cleaned_data['DELETE']):
+ continue
+ enableurl_formset.save()
+
# Save Issue
issue.updated_config = p_config
issue_form.save()
@@ -429,10 +487,14 @@ def report(request, id):
else:
domain_formset = DomainFormSet(queryset=domain_queryset)
- docurl_formset = DocURLFormSet(queryset=docurl_queryset)
+ docurl_formset = DocURLFormSet(queryset=docurl_queryset,
+ meta=request.META)
+ enableurl_formset = EnableURLFormSet(queryset=enableurl_queryset,
+ meta=request.META)
config_form = ConfigForm(instance=config,
domain_formset=domain_formset,
- docurl_formset=docurl_formset)
+ docurl_formset=docurl_formset,
+ enableurl_formset=enableurl_formset)
issue = Issue(config=config)
issue_form = IssueForm(instance=issue)
return render_to_response('config/enter_config.html', {
@@ -453,6 +515,7 @@ def show_issue(request, id):
added_domains = set()
error = ""
new_docurl_formset = []
+ new_enableurl_formset = []
up_conf = issue.updated_config
if up_conf:
@@ -478,6 +541,13 @@ def show_issue(request, id):
form=DocURLForm, formset=BaseDocURLFormSet)
docurl_formset = DocURLFormSet(queryset=issue.config.docurl_set.all())
new_docurl_formset = DocURLFormSet(queryset=up_conf.docurl_set.all())
+ # Enable URLs
+ EnableURLFormSet = modelformset_factory(EnableURL, extra=0,
+ form=EnableURLForm, formset=BaseEnableURLFormSet)
+ enableurl_formset = EnableURLFormSet(
+ queryset=issue.config.enableurl_set.all())
+ new_enableurl_formset = EnableURLFormSet(
+ queryset=up_conf.enableurl_set.all())
# get removed/added domains
original_domains = []
@@ -503,6 +573,9 @@ def show_issue(request, id):
elif data['action'] == 'merge':
if not issue.config.status == "approved":
error = "Can't merge into non approved configurations."
+ if issue.config.locked:
+ error = ("This configuration is locked. Only admins can unlock "
+ "it.")
elif issue.updated_config:
# check if any of the added domains are already bound to some
# approved configuration
@@ -538,6 +611,12 @@ def show_issue(request, id):
for docurl in new_docurl_formset:
docurl.instance.config = issue.config
docurl.instance.save()
+ # update enableurls
+ enableurl_formset.delete()
+ for enableurl in new_enableurl_formset:
+ enableurl.instance.config = issue.config
+ enableurl.instance.save()
+ # update issue
issue.updated_config.status = 'deleted'
issue.updated_config.save()
issue.config.save()
@@ -555,5 +634,6 @@ def show_issue(request, id):
'removed_domains': removed_domains,
'added_domains': added_domains,
'new_docurl_formset': new_docurl_formset,
+ 'new_enableurl_formset': new_enableurl_formset,
'error': error,
}, context_instance=RequestContext(request))
View
12 ispdb/fixtures/domain_testdata.json
@@ -60,7 +60,8 @@
"outgoing_hostname": "test.com",
"incoming_type": "imap",
"deleted_datetime": null,
- "last_status": ""
+ "last_status": "",
+ "locked": "False"
}
},
{
@@ -90,7 +91,8 @@
"outgoing_hostname": "Valid Domain",
"incoming_type": "imap",
"deleted_datetime": null,
- "last_status": ""
+ "last_status": "",
+ "locked": "False"
}
},
{
@@ -120,7 +122,8 @@
"outgoing_hostname": "test.com",
"incoming_type": "imap",
"last_status": "",
- "deleted_datetime": null
+ "deleted_datetime": null,
+ "locked": "False"
}
},
{
@@ -150,7 +153,8 @@
"outgoing_hostname": "test.com",
"incoming_type": "imap",
"last_status": "",
- "deleted_datetime": null
+ "deleted_datetime": null,
+ "locked": "False"
}
},
{
View
17 ispdb/fixtures/issue_testdata.json
@@ -53,5 +53,22 @@
"description": "test",
"language": "en"
}
+ },
+ {
+ "pk": 1,
+ "model": "config.enableurl",
+ "fields": {
+ "url": "http://test.com/",
+ "config": 1
+ }
+ },
+ {
+ "pk": 1,
+ "model": "config.enableurlinst",
+ "fields": {
+ "enableurl": 1,
+ "description": "test",
+ "language": "en"
+ }
}
]
View
51 ispdb/fixtures/xml_testdata.json
@@ -31,7 +31,8 @@
"last_update_datetime": "2012-05-31T21:08:11.305Z",
"incoming_username_form":"",
"outgoing_hostname":"hostname_out",
- "incoming_type":"imap"
+ "incoming_type":"imap",
+ "locked": "False"
}
},
{
@@ -63,7 +64,7 @@
"pk": 2,
"model": "config.docurldesc",
"fields": {
- "docurl": 1,
+ "docurl": 2,
"description": "test",
"language": "en"
}
@@ -72,10 +73,52 @@
"pk": 3,
"model": "config.docurldesc",
"fields": {
- "docurl": 1,
+ "docurl": 2,
+ "description": "test2",
+ "language": "fr"
+ }
+ },
+ {
+ "pk": 1,
+ "model": "config.enableurl",
+ "fields": {
+ "url": "http://test.com/",
+ "config": 1
+ }
+ },
+ {
+ "pk": 1,
+ "model": "config.enableurlinst",
+ "fields": {
+ "enableurl": 1,
+ "description": "test",
+ "language": "en"
+ }
+ },
+ {
+ "pk": 2,
+ "model": "config.enableurl",
+ "fields": {
+ "url": "http://test.com/",
+ "config": 1
+ }
+ },
+ {
+ "pk": 2,
+ "model": "config.enableurlinst",
+ "fields": {
+ "enableurl": 2,
+ "description": "test",
+ "language": "en"
+ }
+ },
+ {
+ "pk": 3,
+ "model": "config.enableurlinst",
+ "fields": {
+ "enableurl": 2,
"description": "test2",
"language": "fr"
}
}
-
]
View
37 ispdb/templates/config/details.html
@@ -248,8 +248,31 @@
</td>
</tr>
</table>
+</div>
+{% if docurls %}
+<div id="docurl">
+ <h4>Documentation</h4>
+ {% for form in docurls %}
+ {% include "config/urls/url_list.html" %}
+ {% for desc_form in form.desc_formset %}
+ {% include "config/urls/desc_list.html" %}
+ {% endfor %}
+ {% endfor %}
</div>
+{% endif %}
+
+{% if enableurls %}
+<div id="enableurl">
+ <h4>Enable Instructions</h4>
+ {% for form in enableurls %}
+ {% include "config/urls/url_list.html" %}
+ {% for desc_form in form.inst_formset %}
+ {% include "config/urls/desc_list.html" %}
+ {% endfor %}
+ {% endfor %}
+</div>
+{% endif %}
<div id="other_data">
<h4>Other Fields</h4>
@@ -260,20 +283,6 @@
</tr>
{% endfor %}
</table>
- {% for docurl in docurls %}
- <table>
- <tr>
- <td>{{ docurl.url.label}}:</td><td>{{ docurl.url.value}}</td>
- </tr>
- </table>
- {% for desc in docurl.desc_formset %}
- <table class="tab_desc">
- <tr>
- <td>{{ desc.description.label }}:</td><td>{{ desc.description.value }}</td><td> {{ desc.language|data_verbose_field }}</td>
- </tr>
- </table>
- {% endfor %}
- {% endfor %}
</div>
</td>
<td>
View
172 ispdb/templates/config/enter_config.html
@@ -19,19 +19,30 @@
$("#{{docurl.desc_formset.prefix}}").hide();
{% endif %}
{% endfor %}
+ {% for enableurl in config_form.enableurl_formset %}
+ {% if enableurl.DELETE.value == "True" %}
+ $("#{{enableurl.inst_formset.prefix}}").hide();
+ {% endif %}
+ {% endfor %}
// add functions
- function addRow(prefix, template_selector, appendto_selector) {
+ function addRow(prefix, template_selector, tab_selector) {
var template = jQuery.format($(template_selector).html());
var i = $("#id_"+prefix+"-TOTAL_FORMS").val() | 0;
- $(template(i++, prefix)).appendTo(appendto_selector);
+ $(tab_selector+' tr:last').before(template(i++, prefix));
$("#id_"+prefix+"-TOTAL_FORMS").val(i);
}
$("#add_docurl").click(function() {
var i = $("#id_{{config_form.docurl_formset.prefix}}-TOTAL_FORMS").val();
- addRow('{{config_form.docurl_formset.prefix}}', '#docurl_template tbody:first', '#configform table:first');
+ addRow('{{config_form.docurl_formset.prefix}}', '#docurl_template tbody:first', '#tab_docurl');
var desc_prefix = 'desc_'+i;
- addRow(desc_prefix, '#desc_full_template tbody:first', '#configform table:first');
+ addRow(desc_prefix, '#desc_full_template tbody:first', '#tab_docurl');
+ });
+ $("#add_enableurl").click(function() {
+ var i = $("#id_{{config_form.enableurl_formset.prefix}}-TOTAL_FORMS").val();
+ addRow('{{config_form.enableurl_formset.prefix}}', '#enableurl_template tbody:first', '#tab_enableurl');
+ var desc_prefix = 'inst_'+i;
+ addRow(desc_prefix, '#inst_full_template tbody:first', '#tab_enableurl');
});
$("#add_domain").click(function() {
addRow('{{config_form.domain_formset.prefix}}', '#domain_template tbody:first', '#domain_list table');
@@ -40,6 +51,10 @@
var prefix = $(this).attr('value');
addRow(prefix, '#desc_template tbody:first', '#'+prefix+' table.tab_descs');
});
+ $("#configform").on("click", "a.add_inst", function() {
+ var prefix = $(this).attr('value');
+ addRow(prefix, '#inst_template tbody:first', '#'+prefix+' table.tab_insts');
+ });
// delete functions
$("#domain_list").on("click", "a.delete", function(){
@@ -55,37 +70,37 @@
$(this).text("Undo");
}
});
- $("#configform").on("click", "a.delete.desc", function(){
+ $("#configform").on("click", "a.delete.url", function(){
var prefix = $(this).attr('value');
var check = $('#id_'+prefix+'-DELETE');
if (check.val() == "True"){
check.val("False");
- $('#id_'+prefix+'-description').removeAttr("disabled");
- $('#id_'+prefix+'-language').removeAttr("disabled");
+ $('#id_'+prefix+'-url').removeAttr("readonly");
+ $(this).closest('tr').next().find('div').show();
$(this).text("Remove");
} else {
check.val("True");
- $('#id_'+prefix+'-description').attr("disabled", "disabled");
- $('#id_'+prefix+'-language').attr("disabled", "disabled");
+ $('#id_'+prefix+'-url').attr("readonly", "readonly");
+ $(this).closest('tr').next().find('div').hide();
$(this).text("Undo");
}
});
- $("#configform").on("click", "a.delete.docurl", function(){
+ $("#configform").on("click", "a.delete.desc", function(){
var prefix = $(this).attr('value');
var check = $('#id_'+prefix+'-DELETE');
if (check.val() == "True"){
check.val("False");
- $('#id_'+prefix+'-url').removeAttr("readonly");
- $(this).closest('tr').next().find('div').show();
+ $('#id_'+prefix+'-description').removeAttr("disabled");
+ $('#id_'+prefix+'-language').removeAttr("disabled");
$(this).text("Remove");
} else {
check.val("True");
- $('#id_'+prefix+'-url').attr("readonly", "readonly");
- $(this).closest('tr').next().find('div').hide();
+ $('#id_'+prefix+'-description').attr("disabled", "disabled");
+ $('#id_'+prefix+'-language').attr("disabled", "disabled");
$(this).text("Undo");
}
});
-
+
function showForm() {
$("#question").hide();
$("#submit").show();
@@ -228,46 +243,48 @@
</tr>
{% endwith %}
</table>
+
<table style="display:none" id="docurl_template">
{% with config_form.docurl_formset.empty_form as form %}
- <tr>
- <th class="noborder">{{ form.url.label_tag }}:</th>
- <td class="noborder">
- {{ form.url }}
- {{ form.DELETE }}
- <a class="link delete docurl" value="{1}-{0}">Remove</a>
- </td>
- </tr>
+ {% include "config/urls/url_template_form.html" %}
{% endwith %}
</table>
+
+<table style="display:none" id="enableurl_template">
+{% with config_form.enableurl_formset.empty_form as form %}
+ {% include "config/urls/url_template_form.html" %}
+{% endwith %}
+</table>
+
<table style="display:none" id="desc_template">
{% with config_form.docurl_formset.empty_desc_form as form %}
- <tr>
- <th>{{ form.description.label_tag }}:</th>
- <td>{{ form.description }}</td>
- <td>
- {{ form.language }}
- {{ form.DELETE }}
- <a class="link delete desc" value="{1}-{0}">Remove</a>
- </td>
- </tr>
+ {% include "config/urls/desc_template_form.html" %}
{% endwith %}
</table>
+
+<table style="display:none" id="inst_template">
+{% with config_form.enableurl_formset.empty_desc_form as form %}
+ {% include "config/urls/desc_template_form.html" %}
+{% endwith %}
+</table>
+
<table style="display:none" id="desc_full_template">
{% with config_form.docurl_formset.empty_desc_form as form %}
<tr><td class="noborder"><td class="noborder"><div id="{1}"><table class="tab_descs">
<input type="hidden" name="{1}-TOTAL_FORMS" value="1" id="id_{1}-TOTAL_FORMS" /><input type="hidden" name="{1}-INITIAL_FORMS" value="0" id="{1}-INITIAL_FORMS" /><input type="hidden" name="{1}-MAX_NUM_FORMS" id="id_{1}-MAX_NUM_FORMS" />
- <tr>
- <th>{{ form.description.label_tag }}:</th>
- <td>{{ form.description }}</td>
- <td>
- {{ form.language }}
- {{ form.DELETE }}
- <a class="link delete desc" value="{1}-{0}">Remove</a>
- </td>
- </tr>
- <table><tr><td><a class="link add_desc" value="{1}">add another description</a></td></tr></table>
- </div></td></td></tr>
+ {% include "config/urls/desc_template_form.html" %}
+ <tr><td class="noborder"><a class="link add_desc" value="{1}">add another description</a></td></tr>
+ </table></div></td></td></tr>
+{% endwith %}
+</table>
+
+<table style="display:none" id="inst_full_template">
+{% with config_form.enableurl_formset.empty_desc_form as form %}
+ <tr><td class="noborder"><td class="noborder"><div id="{1}"><table class="tab_insts">
+ <input type="hidden" name="{1}-TOTAL_FORMS" value="1" id="id_{1}-TOTAL_FORMS" /><input type="hidden" name="{1}-INITIAL_FORMS" value="0" id="{1}-INITIAL_FORMS" /><input type="hidden" name="{1}-MAX_NUM_FORMS" id="id_{1}-MAX_NUM_FORMS" />
+ {% include "config/urls/desc_template_form.html" %}
+ <tr><td><a class="link add_inst" value="{1}">add another instruction</a></td></tr>
+ </table></div></td></td></tr>
{% endwith %}
</table>
@@ -318,8 +335,8 @@
{% endif %}
</tr>
{% endfor %}
+ <tr><td class="noborder"><div id="add_domain" class="hidden"><a class="link">add another domain</a></div></td></tr>
</table>
- <div id="add_domain" class="hidden"><a class="link">add another domain</a></div>
</div>
<div id="question">
@@ -333,24 +350,13 @@ <h3 id="encouragement">Great! Please fill in this form:</h3>
<h3 class="hidden" id="problem">There are missing or incorrect values in the form, please fix them:</h3>
<table>
{{ config_form }}
+ </table>
+
+ <table id="tab_docurl">
{{ config_form.docurl_formset.management_form }}
- <tr><td>{{ config_form.docurl_formset.non_form_errors }}</td></tr>
+ <tr><td class="noborder">{{ config_form.docurl_formset.non_form_errors }}</td></tr>
{% for form in config_form.docurl_formset %}
- <tr><td class="noborder">{{ form.non_field_errors }}</td></tr>
- {{ form.id }}
- <tr>
- <th class="noborder">{{ form.url.label_tag }}:</th>
- <td class="noborder">
- {{ form.url.errors }}
- {{ form.url }}
- {{ form.DELETE }}
- {% if form.DELETE.value == "True" %}
- <a class="link delete docurl" value="{{form.prefix}}">Undo</a>
- {% else %}
- <a class="link delete docurl" value="{{form.prefix}}">Remove</a>
- {% endif %}
- </td>
- </tr>
+ {% include "config/urls/url_form.html" %}
<tr><td class="noborder"><td class="noborder"><div id="{{form.desc_formset.prefix}}"><table class="tab_descs">
{{ form.desc_formset.management_form }}
<tr><td>{{ form.desc_formset.non_form_errors }}</td></tr>
@@ -358,27 +364,41 @@ <h3 class="hidden" id="problem">There are missing or incorrect values in the for
<tr><td>{{ error }}</td></tr>
{% endfor %}
{% for desc_form in form.desc_formset %}
- {{ desc_form.id }}
- <tr>
- <th>{{ desc_form.description.label_tag }}:</th>
- <td>{{ desc_form.description.errors }}{{ desc_form.description }}</td>
- <td>
- {{ desc_form.language.errors }}{{ desc_form.language }}
- {{ desc_form.DELETE }}
- {% if desc_form.DELETE.value == "True" %}
- <a class="link delete desc" value="{{desc_form.prefix}}">Undo</a>
- {% else %}
- <a class="link delete desc" value="{{desc_form.prefix}}">Remove</a>
- {% endif %}
- </td>
- </tr>
+ {% include "config/urls/desc_form.html" %}
+ {% endfor %}
+ <tr><td class="noborder"><a class="link add_desc" value="{{form.desc_formset.prefix}}">add another description</a></td></tr>
+ </table>
+ </div></td></td></tr>
+ {% endfor %}
+ <tr>
+ <td><div id="add_docurl"><a class="link">add another settings page</a></div></td>
+ <td></td>
+ </tr>
+ </table>
+
+ <table id="tab_enableurl">
+ {{ config_form.enableurl_formset.management_form }}
+ <tr><td class="noborder">{{ config_form.enableurl_formset.non_form_errors }}</td></tr>
+ {% for form in config_form.enableurl_formset %}
+ {% include "config/urls/url_form.html" %}
+ <tr><td class="noborder"><td class="noborder"><div id="{{form.inst_formset.prefix}}"><table class="tab_insts">
+ {{ form.inst_formset.management_form }}
+ <tr><td>{{ form.inst_formset.non_form_errors }}</td></tr>
+ {% for error in form.inst_formset.non_field_errors %}
+ <tr><td>{{ error }}</td></tr>
+ {% endfor %}
+ {% for desc_form in form.inst_formset %}
+ {% include "config/urls/desc_form.html" %}
{% endfor %}
+ <tr><td><a class="link add_inst" value="{{form.inst_formset.prefix}}">add another instruction</a></td></tr>
</table>
- <table><tr><td><a class="link add_desc" value="{{form.desc_formset.prefix}}">add another description</a></td></tr></table>
</div></td></td></tr>
{% endfor %}
+ <tr>
+ <td><div id="add_enableurl"><a class="link">add another enable page</a></div></td>
+ <td></td>
+ </tr>
</table>
- <div id="add_docurl"><a class="link">add another settings page</a></div>
</div>
<div id="voteforit" class="hidden">
View
29 ispdb/templates/config/show_issue.html
@@ -132,22 +132,23 @@
</div>
<div id="docurl">
- <h4>Documentation</h4>
- {% for docurl in new_docurl_formset %}
- <table>
- <tr>
- <td>{{ docurl.url.label}}:</td><td>{{ docurl.url.value}}</td>
- </tr>
- </table>
- <table class="tab_desc">
- {% for desc in docurl.desc_formset %}
- <tr>
- <td>{{ desc.description.label }}:</td><td>{{ desc.description.value }}</td><td> {{ desc.language|data_verbose_field }}</td>
- </tr>
+ <h4>Documentation (only the suggested is shown)</h4>
+ {% for form in new_docurl_formset %}
+ {% include "config/urls/url_list.html" %}
+ {% for desc_form in form.desc_formset %}
+ {% include "config/urls/desc_list.html" %}
{% endfor %}
- </table>
+ {% endfor %}
+ </div>
+
+ <div id="enableurl">
+ <h4>Enable Instructions (only the suggested is shown)</h4>
+ {% for form in new_enableurl_formset %}
+ {% include "config/urls/url_list.html" %}
+ {% for desc_form in form.inst_formset %}
+ {% include "config/urls/desc_list.html" %}
{% endfor %}
- </table>
+ {% endfor %}
</div>
</div>
View
14 ispdb/templates/config/urls/desc_form.html
@@ -0,0 +1,14 @@
+{{ desc_form.id }}
+<tr>
+ <th>{{ desc_form.description.label_tag }}:</th>
+ <td>{{ desc_form.description.errors }}{{ desc_form.description }}</td>
+ <td>
+ {{ desc_form.language.errors }}{{ desc_form.language }}
+ {{ desc_form.DELETE }}
+ {% if desc_form.DELETE.value == "True" %}
+ <a class="link delete desc" value="{{desc_form.prefix}}">Undo</a>
+ {% else %}
+ <a class="link delete desc" value="{{desc_form.prefix}}">Remove</a>
+ {% endif %}
+ </td>
+</tr>
View
6 ispdb/templates/config/urls/desc_list.html
@@ -0,0 +1,6 @@
+{% load custom_filters %}
+<table class="tab_desc">
+ <tr>
+ <td>{{ desc_form.description.label }}:</td><td>{{ desc_form.description.value }}</td><td> {{ desc_form.language|data_verbose_field }}</td>
+ </tr>
+</table>
View
9 ispdb/templates/config/urls/desc_template_form.html
@@ -0,0 +1,9 @@
+<tr>
+ <th>{{ form.description.label_tag }}:</th>
+ <td>{{ form.description }}</td>
+ <td>
+ {{ form.language }}
+ {{ form.DELETE }}
+ <a class="link delete desc" value="{1}-{0}">Remove</a>
+ </td>
+</tr>
View
15 ispdb/templates/config/urls/url_form.html
@@ -0,0 +1,15 @@
+<tr><td class="noborder">{{ form.non_field_errors }}</td></tr>
+{{ form.id }}
+<tr>
+ <th class="noborder">{{ form.url.label_tag }}:</th>
+ <td class="noborder">
+ {{ form.url.errors }}
+ {{ form.url }}
+ {{ form.DELETE }}
+ {% if form.DELETE.value == "True" %}
+ <a class="link delete url" value="{{form.prefix}}">Undo</a>
+ {% else %}
+ <a class="link delete url" value="{{form.prefix}}">Remove</a>
+ {% endif %}
+ </td>
+</tr>
View
5 ispdb/templates/config/urls/url_list.html
@@ -0,0 +1,5 @@
+<table>
+ <tr>
+ <td>{{ form.url.label}}:</td><td>{{ form.url.value}}</td>
+ </tr>
+</table>
View
8 ispdb/templates/config/urls/url_template_form.html
@@ -0,0 +1,8 @@
+<tr>
+ <th class="noborder">{{ form.url.label_tag }}:</th>
+ <td class="noborder">
+ {{ form.url }}
+ {{ form.DELETE }}
+ <a class="link delete url" value="{1}-{0}">Remove</a>
+ </td>
+</tr>
View
96 ispdb/tests/common.py
@@ -0,0 +1,96 @@
+# -*- coding: utf-8 -*-
+
+import httplib
+
+# Redirect to /add/ on success
+success_code = httplib.FOUND
+# Return with form errors if form is invalid
+fail_code = httplib.OK
+
+
+def asking_domain_form():
+ return {
+ "asking_or_adding": "asking",
+ "domain-TOTAL_FORMS": "1",
+ "domain-INITIAL_FORMS": "0",
+ "domain-0-id": "",
+ "domain-0-name": "test.com",
+ "domain-0-DELETE": "False",
+ "docurl-INITIAL_FORMS": "0",
+ "docurl-TOTAL_FORMS": "1",
+ "docurl-MAX_NUM_FORMS": "",
+ "docurl-0-id": "",
+ "docurl-0-DELETE": "False",
+ "docurl-0-url": "http://test.com/",
+ "desc_0-INITIAL_FORMS": "0",
+ "desc_0-TOTAL_FORMS": "1",
+ "desc_0-MAX_NUM_FORMS": "",
+ "desc_0-0-id": "",
+ "desc_0-0-DELETE": "False",
+ "desc_0-0-language": "en",
+ "desc_0-0-description": "test",
+ "enableurl-INITIAL_FORMS": "0",
+ "enableurl-TOTAL_FORMS": "1",
+ "enableurl-MAX_NUM_FORMS": "",
+ "enableurl-0-id": "",
+ "enableurl-0-DELETE": "False",
+ "enableurl-0-url": "http://test.com/",
+ "inst_0-INITIAL_FORMS": "0",
+ "inst_0-TOTAL_FORMS": "1",
+ "inst_0-MAX_NUM_FORMS": "",
+ "inst_0-0-id": "",
+ "inst_0-0-DELETE": "False",
+ "inst_0-0-language": "en",
+ "inst_0-0-description": "test"
+ }
+
+
+def adding_domain_form():
+ return {
+ "asking_or_adding": "adding",
+ "domain-TOTAL_FORMS": "1",
+ "domain-INITIAL_FORMS": "0",
+ "domain-MAX_NUM_FORMS": "10",
+ "domain-0-id": "",
+ "domain-0-name": "test.com",
+ "domain-0-DELETE": "False",
+ "display_name": "test",
+ "display_short_name": "test",
+ "incoming_type": "imap",
+ "incoming_hostname": "foo",
+ "incoming_port": "333",
+ "incoming_socket_type": "plain",
+ "incoming_authentication": "password-cleartext",
+ "incoming_username_form": "%25EMAILLOCALPART%25",
+ "outgoing_hostname": "bar",
+ "outgoing_port": "334",
+ "outgoing_socket_type": "STARTTLS",
+ "outgoing_username_form": "%25EMAILLOCALPART%25",
+ "outgoing_authentication": "password-cleartext",
+ "docurl-INITIAL_FORMS": "0",
+ "docurl-TOTAL_FORMS": "1",
+ "docurl-MAX_NUM_FORMS": "",
+ "docurl-0-id": "",
+ "docurl-0-DELETE": "False",
+ "docurl-0-url": "http://test.com/",
+ "desc_0-INITIAL_FORMS": "0",
+ "desc_0-TOTAL_FORMS": "1",
+ "desc_0-MAX_NUM_FORMS": "",
+ "desc_0-0-id": "",
+ "desc_0-0-DELETE": "False",
+ "desc_0-0-language": "en",
+ "desc_0-0-description": "test",
+ "enableurl-INITIAL_FORMS": "0",
+ "enableurl-TOTAL_FORMS": "1",
+ "enableurl-MAX_NUM_FORMS": "",
+ "enableurl-0-id": "",
+ "enableurl-0-DELETE": "False",
+ "enableurl-0-url": "http://test.com/",
+ "inst_0-INITIAL_FORMS": "0",
+ "inst_0-TOTAL_FORMS": "1",
+ "inst_0-MAX_NUM_FORMS": "",
+ "inst_0-0-id": "",
+ "inst_0-0-DELETE": "False",
+ "inst_0-0-language": "en",
+ "inst_0-0-description": "test"
+ }
View
97 ispdb/tests/test_add.py
@@ -1,17 +1,13 @@
# -*- coding: utf-8 -*-
-import httplib
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.forms import ValidationError
from django.utils import timezone
from nose.tools import *
from ispdb.config import models
-
-# Redirect to /add/ on success
-success_code = httplib.FOUND
-# Return with form errors if form is invalid
-fail_code = httplib.OK
+from ispdb.tests.common import adding_domain_form, asking_domain_form
+from ispdb.tests.common import success_code, fail_code
class AddTest(TestCase):
fixtures = ['login_testdata.json']
@@ -296,57 +292,46 @@ def test_add_one_deleted_desc(self):
model = models.DocURLDesc.objects.filter(description="test2")
assert_false(model)
-def asking_domain_form():
- return {"asking_or_adding":"asking",
- "domain-TOTAL_FORMS":"1",
- "domain-INITIAL_FORMS":"0",
- "domain-0-id": "",
- "domain-0-name":"test.com",
- "domain-0-DELETE":"False",
- "docurl-INITIAL_FORMS": "0",
- "docurl-TOTAL_FORMS": "1",
- "docurl-MAX_NUM_FORMS": "",
- "docurl-0-id": "",
- "desc_0-INITIAL_FORMS": "0",
- "desc_0-TOTAL_FORMS": "1",
- "desc_0-MAX_NUM_FORMS": "",
- "docurl-0-id": "",
- }
+ def test_add_one_deleted_enableurl(self):
+ self.client.login(username='test', password='test')
+ domain_form = adding_domain_form()
+ domain_form["enableurl-TOTAL_FORMS"] = "2",
+ domain_form["enableurl-0-url"] = "http://test.com"
+ domain_form["enableurl-0-DELETE"] = "False"
+ domain_form["enableurl-1-id"] = ""
+ domain_form["enableurl-1-url"] = "http://test2.com"
+ domain_form["enableurl-1-DELETE"] = "True"
+ domain_form["inst_1-INITIAL_FORMS"] = "0"
+ domain_form["inst_1-TOTAL_FORMS"] = "1"
+ domain_form["inst_1-MAX_NUM_FORMS"] = ""
+ domain_form["inst_1-0-id"] = ""
+ domain_form["inst_1-0-DELETE"] = "False"
+ domain_form["inst_1-0-language"] = "en"
+ domain_form["inst_1-0-description"] = "test2"
+ res = self.client.post(reverse("ispdb_add"), domain_form)
+ assert_equal(res.status_code, success_code)
+ model = models.EnableURL.objects.filter(url="http://test.com/")
+ assert_true(model)
+ model = models.EnableURL.objects.filter(url="http://test2.com/")
+ assert_false(model)
+ model = models.EnableURLInst.objects.filter(description="test2")
+ assert_false(model)
+
+ def test_add_one_deleted_inst(self):
+ self.client.login(username='test', password='test')
+ domain_form = adding_domain_form()
+ domain_form["inst_0-TOTAL_FORMS"] = "2",
+ domain_form["inst_0-1-id"] = ""
+ domain_form["inst_0-1-DELETE"] = "True"
+ domain_form["inst_0-1-language"] = "en"
+ domain_form["inst_0-1-description"] = "test2"
+ res = self.client.post(reverse("ispdb_add"), domain_form)
+ assert_equal(res.status_code, success_code)
+ model = models.EnableURLInst.objects.filter(description="test")
+ assert_true(model)
+ model = models.EnableURLInst.objects.filter(description="test2")
+ assert_false(model)
-def adding_domain_form():
- return {"asking_or_adding":"adding",
- "domain-TOTAL_FORMS":"1",
- "domain-INITIAL_FORMS":"0",
- "domain-MAX_NUM_FORMS": "10",
- "domain-0-id": "",
- "domain-0-name":"test.com",
- "domain-0-DELETE":"False",
- "display_name":"test",
- "display_short_name":"test",
- "incoming_type":"imap",
- "incoming_hostname":"foo",
- "incoming_port":"333",
- "incoming_socket_type":"plain",
- "incoming_authentication":"password-cleartext",
- "incoming_username_form":"%25EMAILLOCALPART%25",
- "outgoing_hostname":"bar",
- "outgoing_port":"334",
- "outgoing_socket_type":"STARTTLS",
- "outgoing_username_form":"%25EMAILLOCALPART%25",
- "outgoing_authentication":"password-cleartext",
- "docurl-INITIAL_FORMS": "0",
- "docurl-TOTAL_FORMS": "1",
- "docurl-MAX_NUM_FORMS": "",
- "docurl-0-id": "",
- "docurl-0-DELETE": "False",
- "docurl-0-url": "http://test.com/",
- "desc_0-INITIAL_FORMS": "0",
- "desc_0-TOTAL_FORMS": "1",
- "desc_0-MAX_NUM_FORMS": "",
- "desc_0-0-id": "",
- "desc_0-0-DELETE": "False",
- "desc_0-0-language": "en",
- "desc_0-0-description": "test"}
class ModelTest(TestCase):
def test_simple_domain(self):
View
15 ispdb/tests/test_approve.py
@@ -22,6 +22,21 @@ def test_unauthenticated_user(self):
goodRedirect = "/login/?next=%s" % (quote_plus("/approve/1"))
self.assertRedirects(result, goodRedirect)
+ def test_locked_config(self):
+ user_info = {"username": "test_admin", "password": "test"}
+ self.client.login(**user_info)
+ config = Config.objects.get(id=1)
+ config.locked = True
+ config.save()
+ result = self.client.post("/approve/1", {
+ "approved": True,
+ }, follow=True)
+ config = Config.objects.get(id=1)
+ # Should not have changed the config
+ assert_equal(config.status, 'requested')
+ assert_true("This configuration is locked. Only admins can unlock it."
+ in result.content)
+
def test_authenticated_user(self):
user_info = {"username": "test_admin", "password": "test"}
self.client.login(**user_info)
View
15 ispdb/tests/test_delete.py
@@ -42,6 +42,21 @@ def test_delete_no_superuser_domain(self):
goodRedirect = "/login/"
self.assertRedirects(res, goodRedirect)
+ def test_delete_locked_config(self):
+ config = models.Config.objects.get(pk=1)
+ config.locked = True
+ config.save()
+ self.client.login(username='test_admin', password='test')
+ config = models.Config.objects.get(pk=1)
+ assert_true(config.status != 'deleted')
+ res = self.client.post(reverse("ispdb_delete", args=[1]),
+ {'delete':'delete'})
+ self.client.logout()
+ config = models.Config.objects.get(pk=1)
+ assert_true(config.status != 'deleted')
+ assert_true("This configuration is locked. Only admins can unlock it."
+ in res.content)
+
def test_delete_domainrequest(self):
self.delete_domain(1)
config = models.Config.objects.get(pk=1)
View
80 ispdb/tests/test_edit.py
@@ -1,16 +1,12 @@
# -*- coding: utf-8 -*-
-import httplib
from urllib import quote_plus
from django.test import TestCase
from django.core.urlresolvers import reverse
from nose.tools import *
from ispdb.config import models
-
-# Redirect to /add/ on success
-success_code = httplib.FOUND
-# Return with form errors if form is invalid
-fail_code = httplib.OK
+from ispdb.tests.common import adding_domain_form
+from ispdb.tests.common import success_code, fail_code
class EditTest(TestCase):
fixtures = ['login_testdata.json']
@@ -46,6 +42,22 @@ def test_edit_invalid_user(self):
goodRedirect = "/login/"
self.assertRedirects(res, goodRedirect)
+ def test_edit_locked_config(self):
+ self.add_domain()
+ config = models.Config.objects.get(pk=1)
+ config.locked = True
+ config.save()
+ form = adding_domain_form()
+ form["display_name"] = "testing2"
+ self.client.login(username='test', password='test')
+ res = self.client.post(reverse("ispdb_edit",args=[1]),
+ form,
+ follow=True)
+ config = models.Config.objects.get(pk=1)
+ assert_true(config.display_name != "testing2")
+ assert_true("This configuration is locked. Only admins can unlock it."
+ in res.content)
+
def test_edit_same_user(self):
self.add_domain()
self.client.login(username='test', password='test')
@@ -60,6 +72,12 @@ def test_edit_same_user(self):
form["desc_0-INITIAL_FORMS"] = "1"
form["desc_0-0-id"] = "1"
form["desc_0-0-description"] = "test1"
+ form["enableurl-INITIAL_FORMS"] = "1"
+ form["enableurl-0-id"] = "1"
+ form["enableurl-0-url"] = "http://test1.com/"
+ form["inst_0-INITIAL_FORMS"] = "1"
+ form["inst_0-0-id"] = "1"
+ form["inst_0-0-description"] = "test1"
res = self.client.post(reverse("ispdb_edit",args=[1]),
form,
follow=True)
@@ -75,6 +93,10 @@ def test_edit_same_user(self):
assert_equal(docurl.url, 'http://test1.com/')
desc = models.DocURLDesc.objects.get(pk=1)
assert_equal(desc.description, 'test1')
+ enableurl = models.EnableURL.objects.get(pk=1)
+ assert_equal(enableurl.url, 'http://test1.com/')
+ inst = models.EnableURLInst.objects.get(pk=1)
+ assert_equal(inst.description, 'test1')
def test_edit_staff_user(self):
self.add_domain()
@@ -90,6 +112,12 @@ def test_edit_staff_user(self):
form["desc_0-INITIAL_FORMS"] = "1"
form["desc_0-0-id"] = "1"
form["desc_0-0-description"] = "test1"
+ form["enableurl-INITIAL_FORMS"] = "1"
+ form["enableurl-0-id"] = "1"
+ form["enableurl-0-url"] = "http://test1.com/"
+ form["inst_0-INITIAL_FORMS"] = "1"
+ form["inst_0-0-id"] = "1"
+ form["inst_0-0-description"] = "test1"
res = self.client.post(reverse("ispdb_edit",args=[1]),
form,
follow=True)
@@ -105,6 +133,10 @@ def test_edit_staff_user(self):
assert_equal(docurl.url, 'http://test1.com/')
desc = models.DocURLDesc.objects.get(pk=1)
assert_equal(desc.description, 'test1')
+ enableurl = models.EnableURL.objects.get(pk=1)
+ assert_equal(enableurl.url, 'http://test1.com/')
+ inst = models.EnableURLInst.objects.get(pk=1)
+ assert_equal(inst.description, 'test1')
def test_edit_duplicated_names(self):
self.add_domain()
@@ -149,39 +181,3 @@ def test_owner_edit_approved_domain(self):
follow=True)
goodRedirect = "/login/"
self.assertRedirects(res, goodRedirect)
-
-def adding_domain_form():
- return {"asking_or_adding":"adding",
- "domain-TOTAL_FORMS":"1",
- "domain-INITIAL_FORMS":"0",
- "domain-MAX_NUM_FORMS": "10",
- "domain-0-id":"",
- "domain-0-name":"test.com",
- "domain-0-DELETE":"False",
- "display_name":"test",
- "display_short_name":"test",
- "incoming_type":"imap",
- "incoming_hostname":"foo",
- "incoming_port":"333",
- "incoming_socket_type":"plain",
- "incoming_authentication":"password-cleartext",
- "incoming_username_form":"%25EMAILLOCALPART%25",
- "outgoing_hostname":"bar",
- "outgoing_port":"334",
- "outgoing_socket_type":"STARTTLS",
- "outgoing_username_form":"%25EMAILLOCALPART%25",
- "outgoing_authentication":"password-cleartext",
- "docurl-INITIAL_FORMS": "0",
- "docurl-TOTAL_FORMS": "1",
- "docurl-MAX_NUM_FORMS": "",
- "docurl-0-id": "",
- "docurl-0-DELETE": "False",
- "docurl-0-url": "http://test.com/",
- "desc_0-INITIAL_FORMS": "0",
- "desc_0-TOTAL_FORMS": "1",
- "desc_0-MAX_NUM_FORMS": "",
- "desc_0-0-id": "",
- "desc_0-0-DELETE": "False",
- "desc_0-0-language": "en",
- "desc_0-0-description": "test"}
-
View
120 ispdb/tests/test_issue.py
@@ -1,16 +1,20 @@
# -*- coding: utf-8 -*-
-import httplib
from urllib import quote_plus
from django.test import TestCase
from django.core.urlresolvers import reverse
from nose.tools import *
from ispdb.config import models
+from ispdb.tests.common import adding_domain_form
+from ispdb.tests.common import success_code, fail_code
+
+def adding_issue_form():
+ form = adding_domain_form()
+ form['show_form'] = 'False'
+ form['title'] = 'Test'
+ form['description'] = 'Test'
+ return form
-# Redirect to /add/ on success
-success_code = httplib.FOUND
-# Return with form errors if form is invalid
-fail_code = httplib.OK
class IssueTest(TestCase):
fixtures = ['login_testdata', 'issue_testdata']
@@ -20,6 +24,22 @@ def add_issue(self, updated_config=False, config_id=1):
issue = models.Issue.objects.filter(title='Test')
assert_false(issue)
form = adding_issue_form()
+ form["domain-INITIAL_FORMS"] = "1"
+ form["domain-0-id"] = "1"
+ form["domain-0-name"] = "test1.com"
+ form["display_name"] = "testing2"
+ form["docurl-INITIAL_FORMS"] = "1"
+ form["docurl-0-id"] = "1"
+ form["docurl-0-url"] = "http://test1.com/"
+ form["desc_0-INITIAL_FORMS"] = "1"
+ form["desc_0-0-id"] = "1"
+ form["desc_0-0-description"] = "test1"
+ form["enableurl-INITIAL_FORMS"] = "1"
+ form["enableurl-0-id"] = "1"
+ form["enableurl-0-url"] = "http://test1.com/"
+ form["inst_0-INITIAL_FORMS"] = "1"
+ form["inst_0-0-id"] = "1"
+ form["inst_0-0-description"] = "test1"
if updated_config:
form['show_form'] = 'True'
res = self.client.post(reverse("ispdb_report", args=[config_id]), form)
@@ -76,6 +96,21 @@ def test_merge_issue_normal_user(self):
goodRedirect = "/login/"
self.assertRedirects(res, goodRedirect)
+ def test_merge_locked_config(self):
+ self.add_issue(updated_config=True)
+ issue = models.Issue.objects.get(title='Test')
+ issue.config.locked = True
+ issue.config.save()
+ self.client.login(username='test_admin', password='test')
+ res = self.client.post(reverse("ispdb_show_issue",args=[1]),
+ {"action":"merge"},
+ follow=True)
+ issue = models.Issue.objects.get(title='Test')
+ assert_equal(issue.status, "open")
+ assert_true(issue.config.display_name != "testing2")
+ assert_true("This configuration is locked. Only admins can unlock it."
+ in res.content)
+
def test_merge_issue_superuser(self):
self.add_issue(updated_config=True)
self.client.login(username='test_admin', password='test')
@@ -84,67 +119,20 @@ def test_merge_issue_superuser(self):
follow=True)
issue = models.Issue.objects.get(title='Test')
assert_equal(issue.status, "closed")
- assert_equal(issue.config.display_name, "Test")
+ assert_equal(issue.config.display_name, "testing2")
assert_equal(1, len(issue.config.domains.all()))
- assert_equal("test2.com", issue.config.domains.all()[0].name)
- assert_equal(1, len(issue.config.docurl_set.all()))
+ assert_equal("test1.com", issue.config.domains.all()[0].name)
+ # doc url
+ assert_equal(len(issue.config.docurl_set.all()), 1)
docurl = issue.config.docurl_set.all()[0]
- assert_equal("http://test2.com/", docurl.url)
+ assert_equal(docurl.url, 'http://test1.com/')
assert_equal(len(docurl.descriptions.all()), 1)
-
-def adding_issue_form():
- return {
- "domain-TOTAL_FORMS":"2",
- "domain-INITIAL_FORMS":"1",
- "domain-MAX_NUM_FORMS": "10",
- "domain-0-id":"1",
- "domain-0-name":"test.com",
- "domain-0-DELETE":"True",
- "domain-1-id":"",
- "domain-1-name":"test2.com",
- "domain-1-DELETE":"False",
- "incoming_username_form":"%EMAILLOCALPART%",
- "outgoing_username_form":"%EMAILLOCALPART%",
- "incoming_socket_type": "plain",
- "outgoing_port": 587,
- "incoming_authentication": "password-encrypted",
- "display_name": "Test",
- "outgoing_socket_type": "plain",
- "outgoing_authentication": "password-encrypted",
- "incoming_hostname": "test.com",
- "display_short_name": "Test",
- "incoming_port": 143,
- "outgoing_hostname": "test.com",
- "incoming_type": "imap",
- "docurl-INITIAL_FORMS": "1",
- "docurl-TOTAL_FORMS": "2",
- "docurl-MAX_NUM_FORMS": "",
- "docurl-0-id": "1",
- "docurl-0-DELETE": "True",
- "docurl-0-url": "http://test.com/",
- "desc_0-INITIAL_FORMS": "1",
- "desc_0-TOTAL_FORMS": "1",
- "desc_0-MAX_NUM_FORMS": "",
- "desc_0-0-id": "1",
- "desc_0-0-DELETE": "False",
- "desc_0-0-language": "en",
- "desc_0-0-description": "test",
- "docurl-1-id": "",
- "docurl-1-DELETE": "False",
- "docurl-1-url": "http://test2.com/",
- "desc_1-INITIAL_FORMS": "0",
- "desc_1-TOTAL_FORMS": "2",
- "desc_1-MAX_NUM_FORMS": "",
- "desc_1-0-id": "",
- "desc_1-0-DELETE": "False",
- "desc_1-0-language": "fr",
- "desc_1-0-description": "test2",
- "desc_1-1-id": "",
- "desc_1-1-DELETE": "True",
- "desc_1-1-language": "en",
- "desc_1-1-description": "test3",
- "show_form":"False",
- "title":"Test",
- "description":"Test",
- "asking_or_adding":"adding",
- }
+ desc = docurl.descriptions.all()[0]
+ assert_equal(desc.description, 'test1')
+ # enable URL
+ assert_equal(len(issue.config.enableurl_set.all()), 1)
+ enableurl = issue.config.enableurl_set.all()[0]
+ assert_equal(enableurl.url, 'http://test1.com/')
+ assert_equal(len(enableurl.instructions.all()), 1)
+ inst = enableurl.instructions.all()[0]
+ assert_equal(inst.description, 'test1')
View
22 ispdb/tests/test_view.py
@@ -18,7 +18,8 @@
def make_config(value):
"Get the dictionary for a sample config."
- return {"asking_or_adding":"adding",
+ return {
+ "asking_or_adding":"adding",
"domain-TOTAL_FORMS":"1",
"domain-INITIAL_FORMS":"0",
"domain-0-id":"",
@@ -49,7 +50,22 @@ def make_config(value):
"desc_0-0-id": "",
"desc_0-0-DELETE": "False",
"desc_0-0-language": "en",
- "desc_0-0-description": "test%s" % value}
+ "desc_0-0-description": "test%s" % value,
+ "enableurl-INITIAL_FORMS": "0",
+ "enableurl-TOTAL_FORMS": "1",
+ "enableurl-MAX_NUM_FORMS": "",
+ "enableurl-0-id": "",
+ "enableurl-0-DELETE": "False",
+ "enableurl-0-url": "http://test%s.com/" % value,
+ "inst_0-INITIAL_FORMS": "0",
+ "inst_0-TOTAL_FORMS": "1",
+ "inst_0-MAX_NUM_FORMS": "",
+ "inst_0-0-id": "",
+ "inst_0-0-DELETE": "False",
+ "inst_0-0-language": "en",
+ "inst_0-0-description": "test%s" % value
+ }
+