root / snf-astakos-app / astakos / im / management / commands / invitation-show.py @ 415c4a56
History | View | Annotate | Download (2.8 kB)
1 | ca96a346 | Giorgos Verigakis | # Copyright 2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | df48dd1b | Giorgos Verigakis | #
|
3 | df48dd1b | Giorgos Verigakis | # Redistribution and use in source and binary forms, with or
|
4 | df48dd1b | Giorgos Verigakis | # without modification, are permitted provided that the following
|
5 | df48dd1b | Giorgos Verigakis | # conditions are met:
|
6 | df48dd1b | Giorgos Verigakis | #
|
7 | df48dd1b | Giorgos Verigakis | # 1. Redistributions of source code must retain the above
|
8 | df48dd1b | Giorgos Verigakis | # copyright notice, this list of conditions and the following
|
9 | df48dd1b | Giorgos Verigakis | # disclaimer.
|
10 | df48dd1b | Giorgos Verigakis | #
|
11 | df48dd1b | Giorgos Verigakis | # 2. Redistributions in binary form must reproduce the above
|
12 | df48dd1b | Giorgos Verigakis | # copyright notice, this list of conditions and the following
|
13 | df48dd1b | Giorgos Verigakis | # disclaimer in the documentation and/or other materials
|
14 | df48dd1b | Giorgos Verigakis | # provided with the distribution.
|
15 | df48dd1b | Giorgos Verigakis | #
|
16 | df48dd1b | Giorgos Verigakis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | df48dd1b | Giorgos Verigakis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | df48dd1b | Giorgos Verigakis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | df48dd1b | Giorgos Verigakis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | df48dd1b | Giorgos Verigakis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | df48dd1b | Giorgos Verigakis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | df48dd1b | Giorgos Verigakis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | df48dd1b | Giorgos Verigakis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | df48dd1b | Giorgos Verigakis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | df48dd1b | Giorgos Verigakis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | df48dd1b | Giorgos Verigakis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | df48dd1b | Giorgos Verigakis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | df48dd1b | Giorgos Verigakis | #
|
29 | df48dd1b | Giorgos Verigakis | # The views and conclusions contained in the software and
|
30 | df48dd1b | Giorgos Verigakis | # documentation are those of the authors and should not be
|
31 | df48dd1b | Giorgos Verigakis | # interpreted as representing official policies, either expressed
|
32 | df48dd1b | Giorgos Verigakis | # or implied, of GRNET S.A.
|
33 | df48dd1b | Giorgos Verigakis | |
34 | a0699ee4 | Sofia Papagiannaki | from django.core.management.base import CommandError |
35 | df48dd1b | Giorgos Verigakis | |
36 | df48dd1b | Giorgos Verigakis | from astakos.im.models import Invitation |
37 | a0699ee4 | Sofia Papagiannaki | from synnefo.webproject.management.commands import SynnefoCommand |
38 | df48dd1b | Giorgos Verigakis | |
39 | a0699ee4 | Sofia Papagiannaki | from synnefo.webproject.management import utils |
40 | df48dd1b | Giorgos Verigakis | |
41 | df48dd1b | Giorgos Verigakis | |
42 | a0699ee4 | Sofia Papagiannaki | class Command(SynnefoCommand): |
43 | a0699ee4 | Sofia Papagiannaki | args = "<invitation ID or code>"
|
44 | d01e7b22 | Antony Chazapis | help = "Show invitation info"
|
45 | 5ce3ce4f | Sofia Papagiannaki | |
46 | df48dd1b | Giorgos Verigakis | def handle(self, *args, **options): |
47 | df48dd1b | Giorgos Verigakis | if len(args) != 1: |
48 | df48dd1b | Giorgos Verigakis | raise CommandError("Please provide an invitation id") |
49 | 5ce3ce4f | Sofia Papagiannaki | |
50 | df48dd1b | Giorgos Verigakis | try:
|
51 | df48dd1b | Giorgos Verigakis | invitation = Invitation.objects.get(id=int(args[0])) |
52 | df48dd1b | Giorgos Verigakis | except Invitation.DoesNotExist:
|
53 | a0699ee4 | Sofia Papagiannaki | try:
|
54 | a0699ee4 | Sofia Papagiannaki | invitation = Invitation.objects.get(code=args[0])
|
55 | a0699ee4 | Sofia Papagiannaki | except Invitation.DoesNotExist:
|
56 | a0699ee4 | Sofia Papagiannaki | raise CommandError("Unknown invitation id '%s'" % (args[0],)) |
57 | 5ce3ce4f | Sofia Papagiannaki | |
58 | df48dd1b | Giorgos Verigakis | kv = { |
59 | df48dd1b | Giorgos Verigakis | 'id': invitation.id,
|
60 | df48dd1b | Giorgos Verigakis | 'real name': invitation.realname,
|
61 | df48dd1b | Giorgos Verigakis | 'email': invitation.username,
|
62 | df48dd1b | Giorgos Verigakis | 'code': invitation.code,
|
63 | cb261eef | Sofia Papagiannaki | 'consumed': invitation.is_consumed,
|
64 | cb261eef | Sofia Papagiannaki | 'date created': invitation.created,
|
65 | cb261eef | Sofia Papagiannaki | 'date consumed': invitation.consumed,
|
66 | df48dd1b | Giorgos Verigakis | 'inviter real name': invitation.inviter.realname,
|
67 | df48dd1b | Giorgos Verigakis | 'invitater email': invitation.inviter.email,
|
68 | df48dd1b | Giorgos Verigakis | } |
69 | 5ce3ce4f | Sofia Papagiannaki | |
70 | a0699ee4 | Sofia Papagiannaki | utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
|
71 | a0699ee4 | Sofia Papagiannaki | options["output_format"], vertical=True) |